2

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

Code:

public class GCMIntentService extends GCMBaseIntentService {

    public GCMIntentService() {
        super("GCMIntentService");
    }

    @Override
    protected void onMessage(Context context, Intent intent) {
        Intent dialogIntent = new Intent(this, MyActivity.class);
        dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(dialogIntent);    
    }
}

This is what I have so far. But I cannot figure out what MyActivity.class is.

Let's say I want to start the app and that's it. I do not want to add another activity to the AndroidManifest.xml.

Can't I simply use MainActivity.class for Cordova?

What exactly is MyActivity.class?

Dinkheller
  • 4,631
  • 5
  • 39
  • 67

3 Answers3

5

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);
Leo Lin
  • 681
  • 5
  • 8
  • 1
    in redmi device app did not open. I checked it by keeping it in background and after kill app. If app is open than it's working proper. – Neal Jan 06 '20 at 05:32
1

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

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
-1

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);

       }