问题描述
我创建了一个Android Wear的应用程序,它支持我的掌上电脑的应用程序。
显示通知和相关行动Android Wear应用之上执行。
I have created a android wear app which support my handheld application.The android wear app showing notifications and related actions top perform.
我创建的Android Wear通知,并增加了两个行动的暂停,恢复和终止
I have created android wear notifications and added two actions for pause,resume and stop
我需要更换,通过动态的简历行动暂停的动作,这意味着如果用户preSS暂停行动需要更改恢复行动。
I need to replace the pause action by resume action dynamically, that means if user press pause action need to change to resume action.
我的code是
Intent pauseIntent = new Intent(getApplicationContext(), PauseActivity.class);
PendingIntent pausePendingIntent = PendingIntent.getActivity(getApplicationContext(),
0, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent stopIntent = new Intent(getApplicationContext(), StopActivity.class);
PendingIntent stopPendingIntent = PendingIntent.getActivity(getApplicationContext(),
0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification =
new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.icon)
.setContentTitle("Swipe up to view")
.setDeleteIntent(deletePendingIntent)
.extend(new WearableExtender()
.setDisplayIntent(displayPendingIntent))
.addAction(R.drawable.pause_btn, "Pause", pausePendingIntent)
.addAction(R.drawable.stop_btn, "Stop", stopPendingIntent)
.build();
我的要求是当用户点击暂停按钮,我需要通过Resume图标改变这种状况。
My requirement is When user clicks on the pause button i need to change that by Resume Icon.
提前感谢所有...
我的屏幕看起来像
Advance thanks for all...My screen looks like
推荐答案
您需要在用户点击的行动,以刷新它只是张贴新的通知。结果
最老的通知将被更新,所以当发布一个新的改变暂停图标恢复图标+做同样的标签。
Solution
You need to just post new notification when user clicks that action in order to refresh it.
The old notification will be updated so while posting a new one change the "pause" icon to "resume" icon + do the same with labels.
定义你的意图那样:
Intent pauseIntent = new Intent(MediaPlayerActionsReceiver.ACTION_PAUSE, null, context, MediaPlayerActionsReceiver.class);
PendingIntent pausePendingIntent = PendingIntent.getBroadcast(context, 0, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent resumeIntent = new Intent(MediaPlayerActionsReceiver.ACTION_RESUME, null, context, MediaPlayerActionsReceiver.class);
PendingIntent resumePendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, resumeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent stopIntent = new Intent(MediaPlayerActionsReceiver.ACTION_STOP, null, context, MediaPlayerActionsReceiver.class);
PendingIntent stopPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
他们都将交付给同一组件( MediaPlayerActionsReceiver
),但与不同的操作声明。
They all will be delivered to the same component (MediaPlayerActionsReceiver
), but with different action declared.
然后创建MediaPlayerActionsReceiver类:
Then create your MediaPlayerActionsReceiver class:
public class MediaPlayerActionsReceiver extends BroadcastReceiver {
public final static String ACTION_PAUSE = "com.example.package.receiver.action_pause";
public final static String ACTION_RESUME = "com.example.package.receiver.action_resume";
public final static String ACTION_STOP = "com.example.package.receiver.action_stop";
@Override
public void onReceive(Context context, Intent intent) {
if(intent==null)
return;
final String action = intent.getAction();
if(ACTION_PAUSE.equals(action)) {
// handle pause action and refresh notification
} else if(ACTION_RESUME.equals(action)) {
// handle resume action and refresh notification
} else if(ACTION_STOP.equals(action)) {
// handle stop action and refresh notification
}
}
}
最后一步就是声明你的接收机 AndroidManifest
:
<receiver android:name="com.example.package.receiver.MediaPlayerActionsReceiver" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="com.example.package.receiver.action_pause" />
<action android:name="com.example.package.receiver.action_resume" />
<action android:name="com.example.package.receiver.action_stop" />
</intent-filter>
</receiver>
这篇关于如何变化的行动在Android Wear的动态图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!