是否有可能推出一个Android应用程序的活动手机启动时? [英] Is it possible to launch an android application activity when the phone starts?
本文介绍了是否有可能推出一个Android应用程序的活动手机启动时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
林试图建立一个Android应用程序和关键功能之一,这个应用是因为它能够自动启动一个活动的时候,手机开始,我看到我的手机上的一些应用程序,已经做到这一点,任何帮助,将是巨大的,这样我就可以ATLEAST研究通过SDK好这一点,谢谢!
Im attempting to build an android application and one of the key features to this application is for it to be able to launch an activity automatically when the phone starts, I see some apps on my phone that already do this, any help would be great so that I can atleast research this a little better through the sdk, thanks!
推荐答案
您需要实现BroadcastReceiver的是这样的:
You need to implement BroadCastreceiver like this:
public class PhoneStateReceiver extends BroadcastReceiver{
@Override
public void onReceive(final Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent launch = new Intent(context, AcitivityToLaunch.class);
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(launch);
}
}
}
在你的清单中补充一点:
In your manifest add this:
<receiver android:name=".receiver.PhoneStateReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
添加权限:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
这篇关于是否有可能推出一个Android应用程序的活动手机启动时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文