Android(安卓)PendingIntent Notification
16lz
2021-01-26
首先,我感觉在实现中PendingIntent感觉就是Intent的包装。
它的三个实例化方法:
getActivity(Context, int, Intent, int)
getService(Context, int, Intent, int)
getBroadcast(Context, int, Intent, int)
感觉是保存当前的Activity的Context,然后在外部启动Intent动作。类似于代码Context.startActivity(*, *);
常和Notification和Alarm一起使用。
代码例子:
public class BannerActivity extends Activity {private Button b;private NotificationManager mNotificationManager;private Intent intent;private PendingIntent mPendingIntent;private Notification mNotification; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); b = (Button)this.findViewById(R.id.b); intent = new Intent(BannerActivity.this, Activity01.class); mPendingIntent = PendingIntent.getActivity(BannerActivity.this, 0, intent, Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); mNotification = new Notification(); b.setOnClickListener(new Button.OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubmNotification.icon = R.drawable.ic_launcher;mNotification.tickerText = "通知!"; //通知在通知栏出现的时候的标题mNotification.defaults = Notification.DEFAULT_SOUND; // 第二个参数是打开通知栏后的标题, 第三个参数是通知内容mNotification.setLatestEventInfo(BannerActivity.this, "通知?", "通知内容!", mPendingIntent);mNotificationManager.notify(0, mNotification);}}); }}
更多相关文章
- Android(安卓)点击View Rotate旋转带视图动画
- android 多通知 参数问题, PendingIntent:有用的requestCode参数
- Android插入USB设备,自动弹出提示运行apk
- android 中关于SimpleAdapter构造参数的问题
- Android应用之PopupWindow显示位置详解
- android 中关于SimpleAdapter构造参数的问题。
- 记录Activity的onCreate()方法的参数PersistableBundle
- [Android] JNI 中传递字符串参数(String)的安全处理方式
- 使用 SQLiteDatabase 操作 SQLite 数据库