灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:1814回复:0

android中APK开机自动运行

楼主#
更多 发布于:2012-09-06 13:56


1.要做的就是监听系统发出的broadcast

public class FlorenceText extends BroadcastReceiver{
        public void onReceive(Context context, Intent intent) {
                if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
                        start(context);
                }
       }
}

2.在AndroidMenifest.xml里还要将receiver加上, 并写明程序的入口就是FlorenceTest
    <application
        Android:icon="@drawable/ic_launcher"
        Android:label="@string/app_name" >
        <receiver Android:name=".main.FlorenceTest"
                Android:exported="true"
                Android:process=":remote">
            <intent-filter >
                        <action Android:name="Android.intent.action.BOOT_COMPLETED" />
                        <category Android:name="Android.intent.category.HOME"/>
            </intent-filter>
        </receiver>
  </application>

这样,程序就可以在开机时自动运行了


喜欢0 评分0
游客

返回顶部