mercredi 27 mai 2015

How to handle multiple intent actions in android notification alarm

my query is that i am trying to redirect the notification intent different depending on the conditions ,Am working on the alarm system where i need to redirect the notification intent to some activity say A if the user clicks it during the alarm playing and on completion the notification should be redirected to some other activity if still available there. here is my code

   private void DisplayNotification(String AlarmName, Context context) {
    // Context context = context.getApplicationContext();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Intent mIntent;
    SharedPreferences alarmindicator = context.getSharedPreferences(
            "notifyintent", context.MODE_PRIVATE);
    int code;
    SharedPreferences.Editor editor = alarmindicator.edit();
    if (alarmindicator.getBoolean("notifyintentPlaying", true)) {
        mIntent = new Intent(context, AlarmAlertActivity.class);
        Toast.makeText(context, "inalmact", 0).show();
        code = 1;
    }

    else {
        editor.putBoolean("notifyintentPlaying", true);
        editor.commit();
        mIntent = new Intent(context, MainActivity.class);
        // AlarmAlertActivity.this.finish();
        code = 2;
        Toast.makeText(context, "in main act", 0).show();

    }

    Bundle bundle = new Bundle();

    bundle.putString("test", "test");
    mIntent.putExtras(bundle);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, code,
            mIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    Resources res = context.getResources();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            context);

    builder.setContentIntent(pendingIntent)
            .setSmallIcon(R.drawable.notifyiconlarg)
            .setLargeIcon(
                    BitmapFactory.decodeResource(res,
                            R.drawable.notifyiconlarg))
            // .setTicker(res.getString(R.string.notification_title))
            .setTicker(AlarmName).setAutoCancel(true)
            .setContentTitle(AlarmName)
            .setContentText("Time to offer " + AlarmName + " Prayers");

    notificationManager = (NotificationManager) context
            .getSystemService(context.NOTIFICATION_SERVICE);

    notificationManager.notify(123, builder.build());
}

Aucun commentaire:

Enregistrer un commentaire