android 开机自动启动某个APP运行界面
2016-09-27 11:32
441 查看
项目文件目录:
只需如下两个步骤即可:
步骤一: 添加广播:
package com.broadcast;
import com.example.signaturedemo1.MainActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//MainActivity就是开机显示的界面
Intent mBootIntent = new Intent(context, MainActivity.class);
//下面这句话必须加上才能开机自动运行app的界面
mBootIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mBootIntent);
}
}
步骤二: AndroidManifest.xml中加入权限和配置相关信息
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
在<application>代码块中加入以下代码:(注意广播的android:name的值要写你对应广播的位置,本文的BootBroadcastReceiver.class在项目目录com.broadcast下,所以设置为:android:name="com.broadcast.BootBroadcastReceiver")
<!--开机广播接受者-->
<receiver android:name="com.broadcast.BootBroadcastReceiver">
<intent-filter>
<!--注册开机广播地址-->
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
既可以打开APP主界面了,附上MainActivity主代码:
package com.example.signaturedemo1;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);<span style="font-family: 'Microsoft YaHei'; white-space: pre-wrap;">} </span><span style="font-family: 'Microsoft YaHei'; white-space: pre-wrap;">}</span>
只需如下两个步骤即可:
步骤一: 添加广播:
package com.broadcast;
import com.example.signaturedemo1.MainActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//MainActivity就是开机显示的界面
Intent mBootIntent = new Intent(context, MainActivity.class);
//下面这句话必须加上才能开机自动运行app的界面
mBootIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mBootIntent);
}
}
步骤二: AndroidManifest.xml中加入权限和配置相关信息
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
在<application>代码块中加入以下代码:(注意广播的android:name的值要写你对应广播的位置,本文的BootBroadcastReceiver.class在项目目录com.broadcast下,所以设置为:android:name="com.broadcast.BootBroadcastReceiver")
<!--开机广播接受者-->
<receiver android:name="com.broadcast.BootBroadcastReceiver">
<intent-filter>
<!--注册开机广播地址-->
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
既可以打开APP主界面了,附上MainActivity主代码:
package com.example.signaturedemo1;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);<span style="font-family: 'Microsoft YaHei'; white-space: pre-wrap;">} </span><span style="font-family: 'Microsoft YaHei'; white-space: pre-wrap;">}</span>
相关文章推荐
- 如何在android手机上实现app开机自动运行启动(可以打开应用界面)。
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- Android设备开机后自动启动APP解决方法:(学习篇)
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- Android开机自动运行APP——BroadcastReceiver
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- Android 开机启动, service 自动运行。
- android如何实现开机自动启动Service或app(转)