Android Wear Intent.putExtra用于具有contentAction的多个页面

卡斯帕迪

我正在通过可穿戴式应用发送包含多个页面的通知。对于每个datamapItem,都有一个单独的页面,其中包含contentAction。内容操作将调用一个新的活动,并从datamapitem中提交一个“ id”。此“ id”应显示在新的活动中

创建通知的ListenerService:

for (int i=dataMapItem.getDataMap().size()-1; i>=0; i--) {

                ...

                Intent detailIntent =  new Intent(this, DetailActivity.class);
                detailIntent.putExtra(DetailActivity.EXTRA_ID, id);
                PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
                        detailIntent, PendingIntent.FLAG_UPDATE_CURRENT);

                Notification.Action action = new Notification.Action(R.drawable.btn_blue_small, "open", pendingIntent);

                actions.add(action);

                if(i!=0) {
                    Notification notificationPage = new Notification.Builder(this)
                            .setContentTitle(title)
                            .setContentText(text)
                            .extend(new Notification.WearableExtender()
                                            .setBackground(colorBitmap)
                                            .setContentAction(i)
                            )
                            .build();

                    pages.add(notificationPage);

                } else {
                    Notification.Builder notificationBuilder = new Notification.Builder(this)
                            .setSmallIcon(R.drawable.ic_launcher)
                            .setContentTitle(title)
                            .setContentText(text)
                            .extend(new Notification.WearableExtender()
                                            .addActions(actions)
                                            .addPages(pages)
                                            .setContentAction(i)
                                            .setBackground(colorBitmap)
                                            .setHintHideIcon(true)
                            );

                    Notification notification = notificationBuilder.build();
                    notification.defaults |= Notification.DEFAULT_VIBRATE;

                    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                            .notify(NOTIFICATION_ID, notification);
                }

            }

SecondActivity应该显示通过intent.putextra()提交的数据

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);

    mTextid = (TextView) findViewById(R.id.txtid);

    Intent intent = getIntent();
    if(intent != null) {
        id = intent.getStringExtra(EXTRA_ID);

    ...
}

所以这是我的问题:由于我的putExtra的Key是静态的,因此在每次循环运行中,该值都会被覆盖。并且secondactiviy中的Displayed id始终为0,或者是最后一次遍历的值。

我希望我将其描述为可以理解的;)有人对此问题有解决方案吗?谢谢

卡斯帕迪

由我自己解决。Itw只是一个愚蠢的错误。如果有人在乎,那只是挂起意图中的错误参数。

它应该是:

PendingIntent pendingIntent = PendingIntent.getActivity(this, index,
                detailIntent, PendingIntent.FLAG_UPDATE_CURRENT);

代替:

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
                    detailIntent, PendingIntent.FLAG_UPDATE_CURRENT);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Android Wear onPeerConnected未通过新的Wear Intent调用

来自分类Dev

Android Wear onPeerConnected未通过新的Wear Intent调用

来自分类Dev

如何防止Android Wear活动具有多个实例?

来自分类Dev

Android Intent putExtra与静态调用?

来自分类Dev

语音识别-带有模板(Android Wear)

来自分类Dev

在具有Android Studio的App中设置Android Wear权限

来自分类Dev

具有多个页面的Android Wear Smartwatch通知-小图标仅显示在第一页上吗?

来自分类Dev

具有多个页面的Android Wear Smartwatch通知-小图标仅显示在第一页上吗?

来自分类Dev

具有传感器数据的Android Wear表盘

来自分类Dev

具有传感器数据的Android Wear表盘

来自分类Dev

Android Wear-在没有WearableListenerService的情况下从Wear接收消息?

来自分类Dev

Android Wear设置活动

来自分类Dev

Android Wear Google Analytics

来自分类Dev

Android Wear示例应用

来自分类Dev

Android Wear风格

来自分类Dev

WebView对Android Wear的支持

来自分类Dev

屏幕记录Android Wear

来自分类Dev

Android Wear防止睡眠

来自分类Dev

Android Wear图片置顶

来自分类Dev

WearableRecyclerView Android Wear OS

来自分类Dev

Android Wear错误

来自分类Dev

Android Wear中的通知

来自分类Dev

适用于Android Wear的Moto 360模拟器

来自分类Dev

适用于Android Wear应用的OAuth流程

来自分类Dev

适用于Android Wear的Moto 360模拟器

来自分类Dev

检测Android Wear屏幕是否有下巴(又名flat胎)

来自分类Dev

在Android Wear中使用现有数据库

来自分类Dev

Android Wear HorizontalScrollView没有结束标记

来自分类Dev

Android Wear-带有功能的路径