我试图建立一个Android应用程序,这个应用程序的关键功能之一是它能够在手机启动时自动启动一个活动,我看到我的手机上的一些应用已经做到这一点,任何帮助都会很棒所以我可以通过sdk更好地研究这一点,谢谢!
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>
Add permission:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.