惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
U
Unit 42
H
Help Net Security
博客园_首页
雷峰网
雷峰网
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - 【当耐特】
Recent Announcements
Recent Announcements
Recorded Future
Recorded Future
aimingoo的专栏
aimingoo的专栏
爱范儿
爱范儿
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Cloudflare Blog
S
Security @ Cisco Blogs
M
MIT News - Artificial intelligence
Cyberwarzone
Cyberwarzone
Cisco Talos Blog
Cisco Talos Blog
Spread Privacy
Spread Privacy
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
K
Kaspersky official blog
MyScale Blog
MyScale Blog
阮一峰的网络日志
阮一峰的网络日志
C
CERT Recently Published Vulnerability Notes
V
Vulnerabilities – Threatpost
WordPress大学
WordPress大学
C
Cisco Blogs
G
Google Developers Blog
N
News and Events Feed by Topic
P
Palo Alto Networks Blog
Apple Machine Learning Research
Apple Machine Learning Research
Schneier on Security
Schneier on Security
博客园 - 聂微东
Security Latest
Security Latest
Security Archives - TechRepublic
Security Archives - TechRepublic
O
OpenAI News
云风的 BLOG
云风的 BLOG
IT之家
IT之家
PCI Perspectives
PCI Perspectives
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
小众软件
小众软件
Scott Helme
Scott Helme
大猫的无限游戏
大猫的无限游戏
L
LINUX DO - 最新话题
Microsoft Azure Blog
Microsoft Azure Blog
Simon Willison's Weblog
Simon Willison's Weblog
N
News and Events Feed by Topic
F
Fortinet All Blogs
The Last Watchdog
The Last Watchdog

博客园 - xin36933

浅析android OCR文字识别 Android中使用代码截图的各种方法总结 Android通过tcpdump抓包 SqlServer表死锁的解决方法 数据库 的事务日志已满。若要查明无法重用日志中的空间的原因,请参阅 sys.databases 中的 log_reuse_wait_desc 列。 修改Android工程版本 android利用剪切板来实现数据的传递 ANDROID开发之SQLite详解 浅析SQLite数据库开发常用管理工具 android DDMS 连接真机(己ROOT),用file explore看不到data/data文件夹的解决办法 Android手机获取手机唯一识别号(转) android 程序时时获取logcat信息 Android adb shell启动应用程序的方法 android打电话、发短信实现 Android全局变量的定义与使用 安卓4.0/4.1/4.2手机怎么打开USB调试模式 Android中的DDMS进行调试 Runtime.getRuntime().exec执行阻塞问题解决 GC_EXTERNAL_ALLOC freed 与 GC_EXPLICIT freed 是什么?
Android 开机自动启动服务
xin36933 · 2014-06-19 · via 博客园 - xin36933

在前面的文章中提到了remote service 的创建过程,现在我们要让它开机自动启动

1.在前面代码的基础上添加 RemoteServiceBootReceiver.java ,实现一个intent的receiver

  1. package com.fly;  
  2. import android.content.BroadcastReceiver;  
  3. import android.content.Context;  
  4. import android.content.Intent;  
  5. import android.util.Log;  
  6. public class RemoteServiceBootReceiver extends BroadcastReceiver {  
  7.     private static final String TAG = "U0fly RemoteServiceBootReceiver";  
  8.     static final String ACTION = "android.intent.action.BOOT_COMPLETED";  
  9.     @Override  
  10.     public void onReceive(Context arg0, Intent arg1) {  
  11.         Log.d(TAG, "Boot completed");  
  12.         
  13.         if (arg1.getAction().equals(ACTION)) {  
  14.             
  15.             Intent myintent = new Intent(arg0, RemoteService.class);  
  16.             myintent.setAction("com.fly.RemoteService");  
  17.             arg0.startService(myintent);  
  18.         }  
  19.     }  
  20. }  

2.在AndroidManifast.xml中添加权限,并注册一个receiver

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.fly" android:versionCode="1" android:versionName="1.0">  
  4.     <application android:icon="@drawable/icon" android:label="@string/app_name">  
  5.         <activity android:name=".RemoteServiceActivity"  
  6.             android:label="@string/app_name">  
  7.             <intent-filter>  
  8.                 <action android:name="android.intent.action.MAIN" />  
  9.                 <category android:name="android.intent.category.LAUNCHER" />  
  10.             </intent-filter>  
  11.         </activity>  
  12.         <service android:name="RemoteService">  
  13.             <intent-fliter>  
  14.                 <action android:name="com.fly.RemoteService" />  
  15.             </intent-fliter>  
  16.         </service>  
  17.       
  18.         <receiver android:name=".RemoteServiceBootReceiver">  
  19.             <intent-filter>  
  20.                 <action android:name="android.intent.action.BOOT_COMPLETED" />  
  21.             </intent-filter>  
  22.         </receiver>  
  23.           
  24.     </application>  
  25.       
  26.     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>   
  27.     <uses-sdk android:minSdkVersion="7" />  
  28. </manifest>