//Create intent
notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
note = new Notification(android.R.drawable.btn_star_big_on, contentText, System.currentTimeMillis() );
Intent notificationIntent = new Intent();
notificationIntent.putExtra("aff_id",aff_id);
notificationIntent.setAction("com.mindfsck.PossAff.aff");
notificationIntent = notificationIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
contentIntent = PendingIntent.getActivity(ctx, aff_id, notificationIntent, 0);
note.setLatestEventInfo(ctx, title, aff_id + contentText, contentIntent);
notificationManager.notify(aff_id,note);
//Pickup intent
package com.mindfsck.PossAff;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.app.PendingIntent;
public class PosAffIntentReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.mindfsck.PossAff.aff")) {
System.out.println("Picked up broadcast with aff");
context.startActivity(new Intent(context, com.mindfsck.PossAff.MainActivity.class));
}else if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")){
}
System.out.println("Picked up broadcast");
}
}
//Manifest
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true">
<activity android:name=".MainActivity"
android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".PosAffIntentReceiver">
<intent-filter>
<!--<action android:name="com.mindfsck.PossAff.intent.action.aff"></action> -->
<action android:name="com.mindfsck.PossAff.aff"></action>
</intent-filter>
</receiver>
<receiver android:name=".NotificationAlarm">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
</application>
单击通知时,我在Debug监视器中看到以下内容
03-04 11:00:24.652:INFO / ActivityManager(1296):开始活动:意图{act = com.mindfsck.PossAff.aff flg = 0x200000(有额外内容)}
但它永远不会被拿起
答案 0 :(得分:0)
在清单中的intent过滤器中缺少DEFAULT类别? (假设我明白你的意思是“永远不会被拾起”)。
答案 1 :(得分:0)
我改变了: contentIntent = PendingIntent.getActivity(ctx,aff_id,notificationIntent,0);
要 contentIntent = PendingIntent。 getBroadcast (ctx,aff_id,notificationIntent,0);