Opening activity after clicking push notification android

前端 未结 2 1411
[愿得一人]
[愿得一人] 2020-12-30 15:57

I am a huge noob to Android programming so sorry if this is a simple task. I pretty much followed the Vogella push notification tutorial for push notifications (http://www.v

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 16:12

    if you want to open a website on notification click try this:

        public void createNotification(Context context, String payload) {
            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notification = new Notification(R.drawable.ic_launcher,
                    "Message received", System.currentTimeMillis());
            // Hide the notification after its selected
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
    
            //adding LED lights to notification
            notification.defaults |= Notification.DEFAULT_LIGHTS;
    
            Intent intent = new Intent("android.intent.action.VIEW", 
             Uri.parse("http://my.example.com/"));
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                    intent, 0);
            notification.setLatestEventInfo(context, "Message",
                    "New message received", pendingIntent);
            notificationManager.notify(0, notification);
    
        }
    

提交回复
热议问题