android - 如何在 Android 上接收推送时自动打开应用程序而无需用户操作

标签 android android-intent cordova-plugins launching-application

我正在尝试在收到推送通知时打开应用程序。

代码:

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

这就是我到目前为止所拥有的。 但我无法弄清楚 MyActivity.class 是什么。

假设我想启动该应用程序,仅此而已。我不想向 AndroidManifest.xml 添加另一个 Activity 。

我不能简单地使用 Cordova 的 MainActivity.class 吗?

MyActivity.class 到底是什么?

最佳答案

PackageManager.getLaunchIntentForPackage可以帮助您找到条目 Activity 。

    Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(launchIntent);

关于android - 如何在 Android 上接收推送时自动打开应用程序而无需用户操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30089963/

相关文章:

android - 如何将 Jar 文件添加到 Android 的 Cordova 插件而不将其编译到 APK 中

cordova - 基于Android SDK为Ionic创建Cordova插件

android - XML 资源文件未在 Android 中复制

java - 如何在 Android 中为文件创建隐式 Intent

Android - ListView - 按需调用 getView()

android - 从另一个 Activity 调用 startActivityForResult

java - 后台服务中的 sensorManager.registerListener

android - 从卫报开放平台获取作者姓名

android - 如何向 Google Play 支付上传应用程序的费用

java - Android Intent 中 SecondActivity.class 的正确含义?