日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

PendingIntent传值接收时为null

發(fā)布時間:2023/12/18 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PendingIntent传值接收时为null 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
時間:2016-4-20 11:01:20
描述:使用Notifaction時,使用到PendingIntent中使用intent傳值的問題,接收Activity接收時獲取到的內容為null。
解決:? ??flags有四個取值:? ??int FLAG_CANCEL_CURRENT:如果該PendingIntent已經存在,則在生成新的之前取消當前的。? ??int FLAG_NO_CREATE:如果該PendingIntent不存在,直接返回null而不是創(chuàng)建一個PendingIntent。? ??int FLAG_ONE_SHOT:該PendingIntent只能用一次,在send()方法執(zhí)行后,自動取消。? ??int FLAG_UPDATE_CURRENT:如果該PendingIntent已經存在,則用新傳入的Intent更新當前的數(shù)據(jù)。? ??我們需要把最后一個參數(shù)改為PendingIntent.FLAG_UPDATE_CURRENT,這樣在啟動的Activity里就可以用接收Intent傳送數(shù)據(jù)? ?的方法正常接收。
發(fā)送方code:
  • Intent intent = new Intent(context, XXActivity.class);
  • intent.putExtra("recFile", recName);
  • PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  • NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  • Notification.Builder builder = new Notification.Builder(context);
  • builder.setTicker("新的通知");
  • builder.setSmallIcon(R.drawable.ic_launcher);
  • builder.setContentTitle("收到新的通知");
  • builder.setContentText("您有一條新的通知");
  • builder.setContentIntent(pendingIntent);
  • Notification notification = builder.build();
  • notification.flags = Notification.FLAG_AUTO_CANCEL;
  • manager.notify(NOTIFACTION_FLAG_CODE, notification);

  • 接收方code:
  • String recFileName = getIntent().getStringExtra("recFile");
  • if (recFileName != null) {
  • //處理邏輯...
  • }



  • 來自為知筆記(Wiz)

    轉載于:https://www.cnblogs.com/yuzhongzheng/p/5412585.html

    總結

    以上是生活随笔為你收集整理的PendingIntent传值接收时为null的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。