zoukankan      html  css  js  c++  java
  • android中的开机自启动

     

    android中的开机自启动

    android中的开机自启动可分为两步:

    1.写一个BroadcastReceiver:

    Java代码  收藏代码
    1. public class BootReceiver extends BroadcastReceiver {  
    2.     private static final String TAG = "BootReceiver";  
    3.   
    4.     @Override  
    5.     public void onReceive(Context context, Intent intent) {  
    6.         Log.i(TAG, "开机自动启动");      
    7.         // AutoOpenActivity为程序的主Activity  
    8.         // 也可以是运行在后台的Service  
    9.         Intent auto = new Intent(context, AutoOpenActivity.class);      
    10.         auto.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);      
    11.         context.startActivity(auto);      
    12.     }  
    13. }  

    2.在Manifest.xml中注册BroadcastReceiver和添加权限: 

    Xml代码  收藏代码
    1. <receiver android:name=".BootReceiver" >  
    2.           <intent-filter >  
    3.                 <action android:name="android.intent.action.BOOT_COMPLETED" />  
    4.   
    5.                 <category android:name="android.intent.category.HOME" />  
    6.            </intent-filter>  
    7. </receiver>  
    Xml代码  收藏代码
    1. <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />  
  • 相关阅读:
    python入门
    Django 知识点回顾
    Django----ORM 对表单的操作
    Django----ORM 对表单的操作2
    html
    线程ThreadPoolExecutor与进程ProcessPoolExecutor
    CMDB基于配置文件加载插件的范例
    瀑布流方式三(方式二的升级版)
    学校系统快速js代码
    小知识:Python函数传递变长
  • 原文地址:https://www.cnblogs.com/geniusxjq/p/4079404.html
Copyright © 2011-2022 走看看