开始一个活动在Android手机开机 [英] Start an Activity on Phone Boot in Android
本文介绍了开始一个活动在Android手机开机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要自动启动我的应用程序在手机启动时。 我声明在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);
}
这篇关于开始一个活动在Android手机开机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文