我想在提醒通知中添加一个操作按钮,这样,只要用户点击此类通知,就会将用户带到布局文件中。
我知道如何添加操作按钮,但是如何在此代码中的通知中添加操作按钮..
需要帮助..在此先感谢..
代码在这里......
public void onReceive(Context context, Intent intent)
{
MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.alert);
mPlayer.start();
mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = intent.getStringExtra("Name");
CharSequence message = intent.getStringExtra("Description");
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
notification = new Notification(R.drawable.alert, "Notification", System.currentTimeMillis());
notification.setLatestEventInfo(context, from, message, contentIntent);
mNotificationManager.notify(Integer.parseInt(intent.getExtras().get("NotifyCount").toString()), notification);
Toast.makeText(context, "New Notification Received", Toast.LENGTH_LONG).show();
}
答案 0 :(得分:1)
public void onReceive(Context context, Intent intent)
{
MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.alert);
mPlayer.start();
mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = intent.getStringExtra("Name");
CharSequence message = intent.getStringExtra("Description");
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
notification = new Notification(R.drawable.alert, "Notification", System.currentTimeMillis());
notification.addAction(R.mipmap.yes, "Acion_Name", contentIntent);
mNotificationManager.notify(Integer.parseInt(intent.getExtras().get("NotifyCount").toString()), notification);
Toast.makeText(context, "New Notification Received", Toast.LENGTH_LONG).show();
}
所以你只需要添加.addAction 这行代码,您可以在其中调用您的待处理意图:
notification.addAction(R.mipmap.yes, "Acion_Name", contentIntent);