How to bring Android existing activity to front via notification

后端 未结 4 2051
醉酒成梦
醉酒成梦 2020-12-06 10:46

I have one Android application, when it runs a service, I want to show the notification on the status bar. Then the user could navigate to other application by pressing HO

4条回答
  •  无人及你
    2020-12-06 11:32

    Another way to launch your package intent.

    private void NotificationwithLaucherSelfPackage(Context context , int notification_id){
            Notification noti = new Notification.Builder(context)
                    .setContentTitle("Your Title")
                    .setContentText("Your Text")
                    .setSmallIcon(R.drawable.abc_ic_menu_share_mtrl_alpha)
                    .setContentIntent(PendingIntent.getActivity( context ,notification_id , getLauncherIntent(context) , PendingIntent.FLAG_UPDATE_CURRENT))
                    .build();
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
        }
    
    private Intent getLauncherIntent(Context context){
            return context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
        }
    

提交回复
热议问题