我正在尝试构建一个 android 应用程序,这个应用程序的一个关键特性是它能够在手机启动时自动启动一个 Activity ,我看到我手机上的一些应用程序已经这样做了,任何帮助都会太棒了,这样我至少可以通过 sdk 更好地研究这个,谢谢!
最佳答案
您需要像这样实现 BroadCastreceiver:
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);
}
}
}
在您的 list 中添加:
<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" />
关于java - 手机启动时是否可以启动android应用程序 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7397065/