Android开发之使用BroadcastReceiver实现开机自动启动(源代码分享)
2014-04-30 23:22
597 查看
From:/article/1337154.html
上一节已经介绍过BroadcastReceiver实现实时监听电量的功能,这节就来介绍一下如果实现开机自动启动的功能,这个比监听电量还简单不少
(1)在清单文件注册权限
[java] view
plaincopy
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
(2)实现 BroadcastReceiver接口
[java] view
plaincopy
package com.example.g04_broadcastreciver04;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootComplete extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent intent2=new Intent(context,MainActivity.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
}
}
(3)在清单文件注册Receiver
[java] view
plaincopy
<receiver android:name="com.example.g04_broadcastreciver04.BootComplete" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" >
</action>
<category android:name="android.intent.category.HOME" >
</category>
</intent-filter>
</receiver>
上一节已经介绍过BroadcastReceiver实现实时监听电量的功能,这节就来介绍一下如果实现开机自动启动的功能,这个比监听电量还简单不少
(1)在清单文件注册权限
[java] view
plaincopy
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
(2)实现 BroadcastReceiver接口
[java] view
plaincopy
package com.example.g04_broadcastreciver04;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootComplete extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent intent2=new Intent(context,MainActivity.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
}
}
(3)在清单文件注册Receiver
[java] view
plaincopy
<receiver android:name="com.example.g04_broadcastreciver04.BootComplete" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" >
</action>
<category android:name="android.intent.category.HOME" >
</category>
</intent-filter>
</receiver>
相关文章推荐
- Android开发之使用BroadcastReceiver实现开机自动启动(源代码分享)
- Android开发之使用BroadcastReceiver实现开机自己主动启动(源码分享)
- Android开发之使用BroadcastReceiver实现开机自己主动启动(源码分享)
- Android开发:系统自动实现开机启动
- Android开发:系统自动实现开机启动
- Android开发:系统自动实现开机启动
- Android开发:系统自动实现开机启动
- Android开发:系统自动实现开机启动
- Android开发:系统自动实现开机启动
- Android开发:系统自动实现开机启动
- Android开发之使用SharedPreferences实现QQ登陆的选项框记忆功能(源代码分享)
- Android开发:系统自动实现开机启动
- android如何实现开机自动启动Service或app(转)
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- Android开发之自定义dialog的实现(源代码分享)
- Android开发之发送邮件功能的实现(源代码分享)
- Android开发之使用Preferences设计软件设置界面(源代码分享)
- Delphi XE开发 Android 开机自动启动
- android如何实现开机自动启动Service或app