如何在启动时启动/启动应用程序 Android [英] How to start/ launch application at boot time Android
问题描述
我想在平板电脑启动时启动我的应用,以便用户在启动平板电脑时首先看到的是我应用的主要活动.
我已阅读有关 LauncherActivity 的内容,但我不明白如何使用它.
任何人都可以帮我提供建议、链接或教程吗?
LauncherActivity 是最好的方法还是有其他选择?
I would like to launch my app when my tablet starts, so that the main activity of my app is the first thing that the user see when they start the tablet.
I've read about LauncherActivity but I don't understand how to use it.
Can anyone help me with suggestions, links or tutorials for this?
Is LauncherActivity the best way or are there alternatives?
推荐答案
这几行代码可能对你有帮助...
These lines of code may be helpful for you...
第一步:在AndroidManifest.xml中设置权限
Step 1: Set the permission in AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
第 2 步:在接收器中添加这个意图过滤器
Step 2: Add this intent filter in receiver
<receiver android:name=".BootReceiver">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
第 3 步:现在您可以从 Receiver 类的 onReceive
方法开始应用程序的第一个活动
Step 3: Now you can start your application's first activity from onReceive
method of Receiver class
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent myIntent = new Intent(context, MainActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
}
这篇关于如何在启动时启动/启动应用程序 Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!