Am trying to getting pending intent. Its returning intent fine when i click notification. But it not returning any thing when i open my app through launcher icon its not returning the pending intent. I searched many links but am not get anything.
creating pending intent from service
Intent in = new Intent(this, MainActivity.class);
in.setAction(action);
in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
in.putExtras(bundle);
PendingIntent pendIntent = PendingIntent.getActivity(this, 0, in,0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle("Wiphone")
.setContentText(callStatus)
.setSmallIcon(R.drawable.ic_wifi)
.setWhen(System.currentTimeMillis())
.setAutoCancel(false)
.setOngoing(true)
.setPriority(Notification.FLAG_FOREGROUND_SERVICE)
.setContentIntent(pendIntent);
Notification notification = builder.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
startForeground(10, notification);
getting pending intent in activity when user launch app through launcher
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent alarmIntent = new Intent();
alarmIntent.setAction(action);
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, alarmIntent,
PendingIntent.FLAG_NO_CREATE);
if (pendingIntent != null) {
Log.d(TAG, "has pending intent");
}
else {
Log.d(TAG, "no pending intent");
}
}