Java broadcastreceiver意图启动活动其他应用程序通知
我创建了2个应用程序(appA,appB),我从appA向appB发送消息,在appB a中捕获此消息并创建通知,但我想在我点击通知打开我的appA并查看我的消息 阿帕 appB AndroidManifest appBJava broadcastreceiver意图启动活动其他应用程序通知,java,android,Java,Android,我创建了2个应用程序(appA,appB),我从appA向appB发送消息,在appB a中捕获此消息并创建通知,但我想在我点击通知打开我的appA并查看我的消息 阿帕 appB AndroidManifest appB <receiver android:name=".MyReceiver" android:enabled="true" android:exported="true"> <intent-filt
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.example.abc.send_messege.custom_action" />
</intent-filter>
</receiver>
好的,您可以试试这个
我们知道您正在创建Pending帐篷,请将新意图传递给(appA)
然后将其传递给pengincontent.setContentIntent(intent)
我还没有介绍过这个,但我认为你可以intent.putExtra(key,message)
在接收活动时通过()
谢谢,但为什么我可以在appB中使用来自appA的旧意图,并且需要创建新意图?我尝试在appA中添加ComponentName并发送appB,但它不起作用…您是否收到任何类型的错误?您可以使用
Intent.setFlag(FLAG\u DEBUG\u LOG\u RESOLUTION)
获取有关Intent RESOLUTION的额外日志信息否,但如果我尝试使用旧Intent(appA)broadcastreceiver,则无法在appB中获取消息
public class MyReceiver extends BroadcastReceiver {
private final static AtomicInteger c = new AtomicInteger(3);
public MyReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
String text = intent.getStringExtra("com.example.abc.send_messege.broadcast.Message");
//Intent intent1 = new Intent(context, Main2Activity.class);
PendingIntent pIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), intent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(android.R.drawable.alert_dark_frame)
.setContentTitle("My notification")
.setContentText(text)
.setContentIntent(pIntent)
.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(getID(), mBuilder.build());
}
public static int getID() {
return c.incrementAndGet();
}}
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.example.abc.send_messege.custom_action" />
</intent-filter>
</receiver>
Intent intent = new Intent();
//com.colisa.broadcast is the package of another app
//com.colisa.broadcast.MainActivity is the actity to be launched
intent.setComponent(
new ComponentName("com.colisa.broadcast","com.colisa.broadcast.MainActivity"));
if (null != getIntent().getExtras().getString(key)){
// whatever
}