* send()方法是用,调用PendingIntent.send()会启动包装的Intent(如启动service,activity) * cancel()方法是为了解除PendingIntent和被包装的Intent之间的关联,此时如果再调用send()方法,则会抛出CanceledException异常 ——— pendingIntent简单理解 2011-04-09 18:28:41| 分类:天天向上|举报|字号订阅 pendingIntent字面...
PendingIntent中除了不含任何参数的send()方法之外,还有其他 send 方法的版本,包括这个可以接受Intent作为参数的版本: funPendingIntent.send(context:Context!,code:Int,intent:Intent?) 这里的Intent参数并不会替换PendingIntent所封装的Intent,而是通过PendingIntent在创建时所封装的Intent来填充参数。 我们来看下面的例子。
⚠️ Android 6 (API 23) 之前的系统中,PendingIntent都是可变类型。 🆕FLAG_MUTABLE: 表示由 PendingIntent.send() 传入的 intent 内容可以被应用合并到 PendingIntent 中的 Intent。 ⚠️ 对于任何可变类型的 PendingIntent,始终设置其中所封装的Intent的ComponentName。如果未采取该操作的话可能会造成安全隐患。
0,sentInt,0);Intent delivInt=newIntent(SmsNotificationSending.DELIVERED);delivInt.putExtra("SMS_ID...
{sendNotification(context);}privatevoidsendNotification(Contextcontext){NotificationManagernotificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);StringchannelId="water_reminder_channel";if(android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.O){Notification...
intFLAG_ONE_SHOT:该PendingIntent只能用一次,在send()方法执行后,自动取消。 intFLAG_UPDATE_CURRENT:如果该PendingIntent已经存在,则用新传入的Intent更新当前的数据。 我们需要把最后一个参数改为PendingIntent.FLAG_UPDATE_CURRENT,这样在启动的Activity里就可以用接收Intent传送数据的方法正常接收。
pending.send(); } catch (CanceledException e) { // TODO Auto-generated catch block e.printStackTrace(); } 这么做只是演示,pengdingIntent有他自己的用途。 PendingIntent的使用 * Flags的类型: FLAG_ONE_SHOT:得到的pi只能使用一次,第二次使用该pi时报错 ...
send(); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); fail("CanceledException!"); } // test receiver activity.runOnUiThread(new Runnable() { @Override public void run() { activity.fullUpdateReceiver.onReceive(activity, new Intent(SuntimesActivity.SUNTIMES_APP_UPDATE_FULL)...
FLAG_ONE_SHOT:该PendingIntent只作用一次。在该PendingIntent对象通过send()方法触发过后,PendingIntent将自动调用cancel()进行销毁,那么如果你再调用send()方法的话,系统将会返回一个SendIntentException。 FLAG_UPDATE_CURRENT:如果系统中有一个和你描述的PendingIntent对等的PendingInent,那么系统将使用该PendingIntent对象,但...
例如,我们在发送系统通知消息时,会通过 PendingIntent 构造一个系统通知Notification,并调用NotificationManagerCompat.notify(…)发送通知,此时并不会直接执行 PendingIntent。而是当系统显示通知,并且用户点击通知时,才会由系统通知这个系统应用间接执行PendingIntent#send(),而不是通过当前应用执行。