android如何实现开机自动启动Service或app(转)
来源:互联网 发布:北京启明星辰知乎 编辑:程序博客网 时间:2024/06/11 17:45
第一步:首先创建一个广播接收者,重构其抽象方法 onReceive(Context context, Intent intent),在其中启动你想要启动的Service或app。
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BootBroadcastReceiver extends BroadcastReceiver {
//重写onReceive方法
@Override
public void onReceive(Context context, Intent intent) {
//后边的XXX.class就是要启动的服务
Intent service = new Intent(context,XXXclass);
context.startService(service);
Log.v("TAG", "开机自动服务自动启动.....");
//启动应用,参数为需要自动启动的应用的包名
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
context.startActivity(intent );
}
}
第二步:配置xml文件,在receiver接收这种添加intent-filter配置
<receiver android:name="BootBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
第三步:添加权限 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- android如何实现开机自动启动Service或app(转)
- android如何实现开机自动启动Service或app(转)
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- android如何实现开机自动启动Service或app
- 专访李果:初生牛犊不怕虎的移动创业者
- 在PROCESS ON VALUE-REQUEST事件中获取屏幕值
- linux LCD 驱动 (二) --- Framebuffer
- 我的Android进阶之旅------>android之向Gallery中添加倒影3D效果
- linux性能调优工具
- android如何实现开机自动启动Service或app(转)
- linux LCD 驱动 (三) --- 图形显示
- 为雅安祈福css 网页黑白特效
- Android中定时器的3种实现方法
- java开发线程篇2:sleep() 和 wait() 有什么区别? (做线程的必知!)
- 输入年月日,算出那天是当年的第几天
- Python的类
- Android 中插件的编写方法
- 黑马程序员 08 Java基础教学 - 08 - 面向对象(4) 之 多态