Android App自动启动相关的一搜一大把,刚开始我也是从网上搜了下,不过貌似有些时候有些坑。还有就是在Flyme OS一直不能实现,后来发现是安全中心拦截了,只有白名单上面的App才能开启自启动。实现开机自启动主要是通过BroadcastReceiver接收ACTION_BOOT_COMPLETED的广播来实现的,首先新建一个BroadcastReceiver类:1、启动Activity
 Intent bootIntent = new Intent(context, MainActivity.class); bootIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(bootIntent);
2、启动Service
Intent bootIntent = new Intent(context, UploadImageService.class);//为了避免被强制停止后接收不到广播bootIntent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);context.startService(bootIntent);
3、启动整个应用
//包名为要唤醒的应用包名Intent bootIntent = context.getPackageManager().getLaunchIntentForPackage(包名);context.startActivity(bootIntent);
然后要在AndroidManifest里面注册BroadcastReceiver:
<receiver  android:name=".receiver.BootReceiver" android:enabled="true" android:exported="true">            <intent-filter>                <action android:name="android.intent.action.BOOT_COMPLETED"/>                <category android:name="android.intent.category.DEFAULT"/>            </intent-filter></receiver>
最后添加开机启动的权限:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

更多相关文章

  1. create custom launcher icon 细节介绍
  2. android task与back stack 开发文档翻译 - 2
  3. 【白话】App从启动到页面显示出来发生了什么
  4. Android(安卓)X86 Android-x86入门之--让你的Android-x86竖屏起
  5. 安卓项目常规设置清单
  6. Android系统手机几种运行模式解析
  7. android系统启动及wifi框架分析
  8. Android启动Activity之后阻止EditText自动获得焦点
  9. android有序广播和无序广播的区别

随机推荐

  1. 悲剧的Nokia,悲剧的meego,悲剧的N9,悲剧的我
  2. Android(安卓)NFC MifareClassic详解
  3. android 的Layout_weight属性
  4. Android(安卓)Studio 常用功能介绍
  5. Android中资源文件中的字符串数组string-
  6. android赚钱 植入有米广告方法
  7. android drawable 应用
  8. Android解决使用findViewById时需要对返
  9. CharSequence的getText()与String的getSt
  10. android uiautomator写一个崩溃的监听