【问题标题】:Adding an action button to android notification向android通知添加操作按钮
【发布时间】:2014-06-24 10:27:19
【问题描述】:

我想在提醒通知中添加一个操作按钮,因此,每当用户单击此类通知时,它都会将用户带到布局文件。..

我知道一般如何添加操作按钮,但是如何在此代码中的通知上添加操作按钮..

需要帮助..提前谢谢..

代码在这里..

   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();
        }

【问题讨论】:

  • 也就是说,你需要通知栏中的按钮?
  • 是的,我需要在通知中添加一个按钮
  • 吉雅,我想你需要在那里创建自定义按钮
  • 你有什么不是@Sparrow的吗?
  • 吉亚,你有没有收到我的消息??

标签: android android-intent notifications android-actionbar alert


【解决方案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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    • 2014-03-22
    相关资源
    最近更新 更多