//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>
我看到在调试监视下列当我点击通知任何人都可以看到为什么这个意图不被拾起?
11月3日至4日:00:24.652:INFO/ActivityManager(1296):启动活动:意向{ACT = com.mindfsck.PossAff FLG的.aff = 0x200000(有演员)}
但它从来没有被拾起
对不起,没有修复它。 – 2011-03-04 00:22:51
我的意思是在PosAffIntentReceiver中的onReceive永远不会被调用 – 2011-03-04 00:23:45