【问题标题】:Is it possible to add onclick listeners to remoteviews in android是否可以将 onclick 侦听器添加到 android 中的远程视图
【发布时间】:2012-08-30 08:21:34
【问题描述】:

我已经创建了如下所示的通知方法:

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification notification;

        notification = new Notification(R.drawable.messageicon, "You have a new message",
                System.currentTimeMillis());
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification);
        view.setImageViewResource(R.id.image, R.drawable.ic_launcher);
        view.setTextViewText(R.id.title, "New Message");
        view.setTextViewText(R.id.text, message);
        notification.contentView = view;
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent activity = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        notification.contentIntent = activity;
        notificationManager.notify(0, notification);

我想在状态栏上添加一个按钮,单击该按钮应显示一个弹出窗口。 任何帮助将不胜感激。

【问题讨论】:

标签: android notifications buttonclick remoteview


【解决方案1】:

不能直接做,但是可以使用RemoteViews.setOnClickPendingIntent(int viewId, PendingIntent pendingIntent)。

如果您想在所有按钮的 onClick 事件上调用相同的 Activity,请确保添加具有不同字符串的 Intent.setAction(String action),以便系统不会将所有意图合并到所有按钮中。

然后将您的活动主题为对话框,您将有一个弹出窗口。

【讨论】:

  • 感谢您的解释,主要是关于 Intent.setAction(String action) 的部分帮助了我!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多