I have written one receiver when sim state is changed it is working fine ,and my device is dual sim card it is working for single sim,but it is not executing for 2nd sim,and when 1st sim is on ready state then i am sending one notification to the user,but notification is coming two times why it is coming two times i want to execute only once here is my receiver code
case TelephonyManager.SIM_STATE_READY:
generateNotification(context, "*** Sim State Ready ***");
Log.i("SimStateListener", "Sim State ready");
and notification code is
private void generateNotification(Context context, String address) {
Intent notifyIntent = new Intent(context,
RegisterActivity.class);
notifyIntent.putExtra("address", address);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(address).setContentIntent(pendingIntent)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND).setWhen(when);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
builder.setAutoCancel(true);
notificationManager.notify((int) when, builder.build());
i am getting notification two times why it is coming two times?
Here I am checking wether sim is removed or not.If sim is removed set flag as a true and when sim is in ready state then I am checking flag is true or not.If true then I am generating notification else I am not generating any notification.