【问题标题】:Notification addAction creates button with no behavior通知 addAction 创建没有行为的按钮
【发布时间】:2014-11-08 13:50:11
【问题描述】:

我正在尝试在我的 android 通知中添加一个按钮。 我使用addAction 方法来添加一个意图打开主要活动(与单击整个通知相同)但带有额外数据包的意图。 这是我到目前为止所做的:

notificationManager = (NotificationManager)this.getSystemService(NOTIFICATION_SERVICE);

//regular intent to view main activity
PendingIntent contentIntent = PendingIntent.getActivity(this,Constants.MAIN_ACTIVITY,
                              new Intent(this, MainActivity.class), 0);

//intent for viewing transaction dialog, within main activity using PURCHASE_DIALOG request code
Bundle bundle = new Bundle();
bundle.putParcelableArrayList(Constants.LIST, (java.util.ArrayList<? extends android.os.Parcelable>) list);
PendingIntent purchaseIntent = PendingIntent.getActivity(
                               this, Constants.PURCHASE_DIALOG,
                               new Intent(this, MainActivity.class), 0, bundle);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_launcher)
                        .setContentTitle(Constants.NOTIFICATION_TOPIC)
                        .setStyle(new NotificationCompat.BigTextStyle()
                        .bigText(watchResponse.toString()))
                        .setAutoCancel(true)
                        .addAction(R.drawable.ic_launcher, "Buy", purchaseIntent)
                        .setContentText(message);

mBuilder.setContentIntent(contentIntent);
notificationManager.notify(NOTIFICATION_ID, mBuilder.build());

我只是希望我在MainActivity 类中的onResume 在单击额外操作后会被调用,并且我将能够通过getIntent() 获得捆绑包,但是当我单击它时没有任何反应。单击按钮,但活动保持打开状态,我的应用程序活动不会启动。

【问题讨论】:

    标签: android android-intent android-notifications


    【解决方案1】:

    我遇到了一个非常相似的问题,但解决方案却截然不同。如果您在 manifest.xml 文件中声明了&lt;service android:enabled="false"&gt;&lt;/service&gt;,则也不会触发待处理的意图。

    android:enabled="false"替换为android:enabled="true"

    这可能不是问题的直接问题。但是,如果您在 android studio 中使用默认模板创建服务,它会自动将这些属性添加到服务中。

    如果这不起作用,您可以在此处找到类似的问题: Android Notification Action is not fired (PendingIntent)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-10
      • 1970-01-01
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多