как установить android значок уведомления так же, как значок приложения и изменить направление при нажатии на уведомление - PullRequest
0 голосов
/ 17 марта 2020

как установить android значок уведомления так же, как и значок приложения?

я пытался использовать .setSmallicon(R.mipmap.ic_launcher)

и как изменить свое намерение уведомления, когда я нажимаю на него, я уже используя эту строку

Intent intent = new Intent(this, Form_User_Notif.class);

, но она всегда указывает на мою основную деятельность вместо Form_User_Notif.class

int NOTIFICATION_ID = 234;
        NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            .......
            notificationManager.createNotificationChannel(mChannel);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setLargeIcon(BitmapFactory.decodeResource(this.getResources(),
                            R.mipmap.ic_launcher))
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(message) )
                    .setContentText(message);


            Intent resultIntent = new Intent(this, Form_User_Notif.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(Form_User_Notif.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
            builder.setContentIntent(resultPendingIntent);
            notificationManager.notify(NOTIFICATION_ID, builder.build());
        } else {
            //On click of notification it redirect to this Activity
            Intent intent = new Intent(this, Form_User_Notif.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

            Uri soundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setLargeIcon(BitmapFactory.decodeResource(this.getResources(),
                            R.mipmap.ic_launcher))
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                    .setContentText(message)
                    .setAutoCancel(true)
                    .setSound(soundUri)
                    .setContentIntent(pendingIntent);


            notificationManager.notify(0, notificationBuilder.build());

        }
...