How to automatically Open the app without user action on receiving a push on Android

后端 未结 3 1819
轻奢々
轻奢々 2021-01-15 16:42

I am trying to open an app when a push notification is received.

Code:

public class GCMIntentService extends GCMBaseIntentService {

    public GCMIn         


        
相关标签:
3条回答
  • 2021-01-15 17:18

    public void getnotification(View view) {

           NotificationManager notificationmgr =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
           Intent intent = new Intent(this,resultpage.class);
           PendingIntent p = PendingIntent.getService(this,(int) System.currentTimeMillis(),intent,0);
    
    
           Notification n = null;
           if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
               n = new Builder(this)
                                    .setSmallIcon(R.mipmap.ic_launcher)
                                   .setContentTitle("Hello android user here")
                                   .setContentText("welcome to notification serrvice")
                                   .setContentIntent(p)
                                   .build();
    
               notificationmgr.notify(0,n);
    
           }
    
    0 讨论(0)
  • 2021-01-15 17:29

    PackageManager.getLaunchIntentForPackage can help you find the entry activity.

        Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
        launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(launchIntent);
    
    0 讨论(0)
  • 2021-01-15 17:29

    Its the class that implements the activity you wish to launch. LoginActivity, MainActivity, whatever it was you named it.

    0 讨论(0)
提交回复
热议问题