AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="where.com.whereareyou">    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />    <uses-sdk        android:minSdkVersion="7"        android:sharedUserId="android.uid.system" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@android:style/Theme.Holo.NoActionBar">        <activity            android:name="where.com.whereareyou.MainActivity"            android:label="@string/app_name">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <receiver android:name="where.com.whereareyou.BootBroadcastReceiver">            <intent-filter>                <action android:name="android.intent.action.BOOT_COMPLETED" />                <action android:name="android.media.AUDIO_BECOMING_NOISY" />            </intent-filter>        </receiver>        <service android:name=".MyService"/>    </application></manifest>

MyService
package where.com.whereareyou;import android.app.Service;import android.content.Intent;import android.os.IBinder;import android.util.Log;/** * Created by Administrator on 2015-10-4. */public class MyService extends Service {    public final static String TAG = "MyService";    @Override    public int onStartCommand(Intent intent, int flags, int startId) {        Log.e(TAG,"onStartCommand");        return START_NOT_STICKY;    }    @Override    public void onDestroy() {        super.onDestroy();        Log.e(TAG,"onDestroy");    }    @Override    public IBinder onBind(Intent intent) {        return null;    }}

BootBroadcastReceiver
package where.com.whereareyou;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.util.Log;/** * Created by Administrator on 2015-10-4. */public class BootBroadcastReceiver extends BroadcastReceiver {    static final String TAG = "BootBroadcastReceiver";    @Override    public void onReceive(Context context, Intent intent) {        Log.e(TAG, "BootBroadcastReceiver onReceive");        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) ||  android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) {            Log.e(TAG, "action=" + intent.getAction());            Intent ootStartIntent = new Intent(context, MyService.class);            context.startService(ootStartIntent);        }    }}


如代码所示,Intent.ACTION_BOOT_COMPLETED表示boot启动完毕后,系统会发送一个广播过来,理论上确实可以接收到,大部分手机估计也都是可以的,但是就是有那么些手机rom被改得不可思议,非要加上个android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY才可以在开机的时候让系统执行Intent.ACTION_BOOT_COMPLETED广播的发送,根据LOG可以看出,以OPPO1107为例,系统是先发送了ACTION_AUDIO_BECOMING_NOISY后发送了ACTION_BOOT_COMPLETED,仅以此博,做个纪念

已有 0 人发表留言,猛击->> 这里<<-参与讨论


ITeye推荐
  • —软件人才免语言低担保 赴美带薪读研!—



更多相关文章

  1. android 3G pppd 调试记录
  2. android 可滑动的DatePicker和点击的DatePicker
  3. Android系统中自带的图标&一些预定义样式&参考颜色值
  4. Android(安卓)面试题总结之Android(安卓)基础(三)
  5. Android短信的发送和广播接收者实现短信的监听
  6. 【Android】Android(安卓)apk默认安装位置设置
  7. Android(安卓)Lint & Checkstyle
  8. Android(安卓)应用间跳转
  9. android 3G pppd 调试记录。

随机推荐

  1. Android创建自定义键盘
  2. zxing项目源码解读(2.3.0版本,Android部分)
  3. Android Service小实践
  4. Android使用Intent实现页面跳转
  5. Java和Javascript互调的例子 ---------(An
  6. 如何让Android屏幕只能上下翻转
  7. Android:控件GridView的使用实例
  8. android获取gps坐标
  9. android studio3.5.2打包,解决建议使用 "k
  10. [Android Pro] Android fastboot刷机和获