由网友(心力交瘁)分享简介:我要自动启动我的应用程序在手机启动时。我声明在manifest文件一个BroadcastReceiver。I want to start my application automatically when the phone boots.I declared a BroadcastReceiver in the...
我要自动启动我的应用程序在手机启动时。 我声明在manifest文件一个BroadcastReceiver。
I want to start my application automatically when the phone boots. I declared a BroadcastReceiver in the manifest file.
<receiver android:name=".Autostart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
我犯了一个java文件的接收器。
I made a java file for the receiver.
Autostart.java
Autostart.java
public class Autostart extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent pushIntent = new Intent(context, MushTouchActivity.class);
pushIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(pushIntent);
}
}
}
不过,该应用程序时,将我的手机上的未启动。谁能告诉我,我在这里失踪了什么?
But, the application does not launch when I switch my phone on. Can anyone tell me what I am missing here ?
推荐答案
试试你的,如果这样的语句:
try your if statement like this:
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent i = new Intent(context, MushTouchActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
相关推荐
最新文章