本文介绍了如何自动打开应用程序,而无需用户在收到Android推送请求的情况下进行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在收到推送通知时打开一个应用程序.
I am trying to open an app when a push notification is received.
代码:
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.
This is what I have so far.But I cannot figure out what MyActivity.class is.
假设我要启动该应用程序,仅此而已.我不想在AndroidManifest.xml中添加其他活动.
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.
我不能简单地将MainActivity.class用于Cordova吗?
Can't I simply use MainActivity.class for Cordova?
MyActivity.class到底是什么?
What exactly is MyActivity.class?
推荐答案
PackageManager.getLaunchIntentForPackage 可以帮助您找到输入活动.
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);
这篇关于如何自动打开应用程序,而无需用户在收到Android推送请求的情况下进行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!