I create 2 app (appA, appB) , from appA i send message to appB, in appB a catch this message and create notification , but i want on i click notification open my appA and see my message.
appA
public class MainActivity extends Activity {
TextView text;
Button send;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView) findViewById(R.id.editText);
send = (Button) findViewById(R.id.button);
View.OnClickListener Onlistbtn = new View.OnClickListener() {
@Override
public void onClick(View view) {
intent = new Intent(view.getContext(),Main2Activity.class);
intent.putExtra("com.example.abc.send_messege.broadcast.Message",text.getText().toString());
intent.setAction("com.example.abc.send_messege.custom_action");
sendBroadcast(intent);
}
};
send.setOnClickListener(Onlistbtn);
}}
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();
}}
AndroidManifest appB
<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>