Hello all in my application i need to generate notification.

for that i have done

 private void generateNotification(String message) {
            mNotificationManager = (NotificationManager) this
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                    this)
                    /* .setSmallIcon(R.drawable.ic_launcher) */
                    .setSmallIcon(R.drawable.app_icon)
                    .setContentTitle(getResources().getString(R.string.app_name))
                    .setStyle(
                            new NotificationCompat.BigTextStyle().bigText(message))
                    .setTicker(message).setContentText(message).setAutoCancel(true);

            // Play default notification sound
            mBuilder.setDefaults(Notification.DEFAULT_SOUND
                    | Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_LIGHTS);

            /*
             * PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new
             * Intent(this, RecentChatList.class), 0);
             */
            /*
             * PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new
             * Intent(this, DashboardActivity.class), 0);
             */
            PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                    new Intent(this, DashboardActivity.class), 0);
            mBuilder.setContentIntent(contentIntent);
            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
        }

and in to DashboardActivity

if (Global.getOPEN_WHICH_FRAGMENT_ON_NOTIFICATION().contains(
                "SINGLE MESSAGE")) {
            Global.setOPEN_WHICH_FRAGMENT_ON_NOTIFICATION("");
            FragmentManager fragmentManager1;
            // on first time display view for first item
            Fragment fragment1 = null;
            fragment1 = new ChatFragment();
            if (fragment1 != null) {
                fragmentManager1 = getFragmentManager();
                fragmentManager1.beginTransaction()
                        .replace(R.id.frmLayout, fragment1).commit();

                txtHeaderTitle.setText("Chat");
            }
        }
        else
        {
            Global.setOPEN_WHICH_FRAGMENT_ON_NOTIFICATION("");
            FragmentManager fragmentManager1;
            // on first time display view for first item
            Fragment fragment1 = null;
            fragment1 = new MyGroupsFragment();
            if (fragment1 != null) {
                fragmentManager1 = getFragmentManager();
                fragmentManager1.beginTransaction()
                        .replace(R.id.frmLayout, fragment1).commit();

                txtHeaderTitle.setText("Group Chat");
            }
        }

This works properly, Mean when single chat notification arrives it opens proper fragment(chatfragment) But when group notification it again opens chat fragment not opens group fragment what i missed in this code

Thanks in advance

Pragna

Related posts

Recent Viewed