我正在尝试在Android中创建PendingIntent。这是代码
mNotificationIntent = new Intent(getApplicationContent(), MyAlarm.class);
mContentIntent = PendingIntent.getActivity(getApplicationContext(),
0, mNotificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
我收到以下错误:
Must be one or more of: PendingIntent.FLAG_ONE_shot,PendingIntent.FLAG_NO_CREATE,
PendingIntent.FLAG_UPDATE_CURRENT,
Intent.FILL_IN_ACTION, Intent.FILL_IN_DATA, Intent.FILL_IN_CATEGORIES…..)
为什么会显示此错误?怎么解决这个?请帮忙。谢谢。
答案 0 :(得分:16)
当方法调用期望Intent.FLAG_ACTIVITY_NEW_TASK
标志时,您正在传递PendingIntent
。如果您想将Intent.FLAG_ACTIVITY_NEW_TASK
添加到Intent
,则需要按照以下方式执行此操作:
mNotificationIntent = new Intent(getApplicationContent(), MyAlarm.class);
mNotificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContentIntent = PendingIntent.getActivity(getApplicationContext(),
0, mNotificationIntent, 0);