Android 开机自启动应用
来源:互联网 发布:华珍养血荣发颗粒淘宝 编辑:程序博客网 时间:2024/05/16 13:57
Android启动时,会发出一个系统广播 ACTION_BOOT_COMPLETED,它的字符串常量表示为 “android.intent.action.BOOT_COMPLETED”
开机自启动程序,只需要“捕捉”到这个消息再启动你的程序即可,我们要做的是接收这个消息,并实现一个BroadcastReceiver。
1 xml 配置
在AndroidManifest.xml中Application节点内,添加自定义的广播类:
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<!-- 这是一个开机自启动程序 -->
<manifest xmlns:android=
"http://schemas.android.com/apk/res/android"
package
=
"com.ajie.bootstartdemo"
android:versionCode=
"1"
android:versionName=
"1.0"
>
<uses-permission android:name=
"android.permission.RECEIVE_BOOT_COMPLETED"
></uses-permission><--权限-->
<application android:icon=
"@drawable/icon"
android:label=
"@string/app_name"
>
<activity android:name=
".BootStartDemo"
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=
".BootBroadcastReceiver"
>
<intent-filter>
<action android:name=
"android.intent.action.BOOT_COMPLETED"
/>
<category android:name=
"android.intent.category.HOME"
/>
</intent-filter>
</receiver>
</application>
</manifest>
2 自定义广播类 BootReceiver
public class BootReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { // boot
Intent ootStartIntent = new Intent(context, ReadCardLoginActivity.class);
ootStartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(ootStartIntent);
}
}
3 Activity
- public class MainActivity extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- }
}
0 0
- Android 开机自启动应用
- Android 开机自启动应用
- Android 开机自启动应用
- Android 开机自启动应用
- Android 开机自启动应用
- Android开机自启动应用
- Android 开机自启动应用
- Android开机自启动应用
- Android 开机自启动应用
- Android应用开机自启动
- android应用开机自启动&service开机自启动
- Android开机自启动应用开发
- android 开机自启动服务或应用
- Android应用开机自启动失败原因
- Android 定制开机自启动应用
- android开发设置应用开机自启动
- android 开机自启动应用 (详细)
- Android开机自启动应用通过广播
- ajax跨域取值
- iOS 兼容性 判断新版本函数可用
- Hello World
- pylab 画直方图,numpy画直方图。
- js遍历 子节点 子元素
- Android 开机自启动应用
- WM_VSCROLL // WM_HSCROLL
- 黑马程序员——面向对象_基础(2)
- JMX之Notification
- go调用其它C库,若采用命令行方式,不支持重定向的输出解决;smp协议未打开,发送信息到对方,没人响应
- 13062hubyee
- 56883xanjzw
- 13416hoizhr
- 青蛙的约会(数论)