代码
AndroidManifest.xml 中
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".BroadcastReceiverDemo"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.google.android_BroadcastReceiver_020" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".TestBroadcast">
<intent-filter>
<action android:name="com.google.android_BroadcastReceiver_01" />
</intent-filter>
</receiver>BroadcastReceiverDemo中要发送一个广播
private final String actionBroadcast="com.google.android_BroadcastReceiver_01";
Intent intent=new Intent(actionBroadcast);
sendBroadcast(intent);TestBroadcast 继承了 BroadcastReceiver
private final String ACTION_STR="com.google.android_BroadcastReceiver_02";
public void onReceive(Context context, Intent intent) {
this.context=context;
show();
}
private void show(){
notificationManager=(NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
Intent i=new Intent(ACTION_STR);
PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, i, 0);
Notification notification=new Notification(R.drawable.icon,"TestBroadcast听到广播后发出信息",System.currentTimeMillis());
notification.setLatestEventInfo(context, "内容title", "内容", pendingIntent);
notificationManager.notify(0, notification);
}我主要想问的问题是 ACTION_STR这个ACTION和<action android:name="com.google.android_BroadcastReceiver_020" />
这个根本不会匹配,消息为什么还会提示
也就是说 我不是很明白PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, i, 0);这个中的i参数。也就是意向起到了什么作用
AndroidManifest.xml 中
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".BroadcastReceiverDemo"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.google.android_BroadcastReceiver_020" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".TestBroadcast">
<intent-filter>
<action android:name="com.google.android_BroadcastReceiver_01" />
</intent-filter>
</receiver>BroadcastReceiverDemo中要发送一个广播
private final String actionBroadcast="com.google.android_BroadcastReceiver_01";
Intent intent=new Intent(actionBroadcast);
sendBroadcast(intent);TestBroadcast 继承了 BroadcastReceiver
private final String ACTION_STR="com.google.android_BroadcastReceiver_02";
public void onReceive(Context context, Intent intent) {
this.context=context;
show();
}
private void show(){
notificationManager=(NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
Intent i=new Intent(ACTION_STR);
PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, i, 0);
Notification notification=new Notification(R.drawable.icon,"TestBroadcast听到广播后发出信息",System.currentTimeMillis());
notification.setLatestEventInfo(context, "内容title", "内容", pendingIntent);
notificationManager.notify(0, notification);
}我主要想问的问题是 ACTION_STR这个ACTION和<action android:name="com.google.android_BroadcastReceiver_020" />
这个根本不会匹配,消息为什么还会提示
也就是说 我不是很明白PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, i, 0);这个中的i参数。也就是意向起到了什么作用
解决方案 »
- tortoisesvn工具无法下载codegoogle的开源代码,怎么办?
- popupwindows 下拉菜单问题
- 安卓横竖屏切换抖动
- android手机的使用
- OPhone与Android之间的关系?
- Google Maps API V3 和 V2有什么区别?
- android消息推送怎么做?
- Button设置背景图片和文字的小问题
- 谁能跟我讲讲SQLiteDatabase中query()跟rawquery()的区别,百度查不到
- Flag android.useDeprecatedNdk is no longer supported
- 关于android 内核版本选择的问题++++
- 程序太多的问题
根本不会匹配,消息为什么还会提示
也就是说 我不是很明白PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, i, 0);这个中的i参数。也就是意向起到了什么作用
最多也就是你点击通知时,找不到ACTION_STR所指的activity而已。
TestBroadcast 继承了 BroadcastReceiver
private final String ACTION_STR="com.google.android_BroadcastReceiver_02";
public void onReceive(Context context, Intent intent) {
this.context=context;
if (intent.getAction().equals("com.google.android_BroadcastReceiver_01")) { // 只关心你要接收的广播
show();
}
}
Intent i=new Intent(ACTION_STR);
PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, i, 0);好想没什么作用
PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, i, 0);ACTION_STR这个不是一个ACTION动作啊,要跳转的那个页面不用匹配这个吗