Service启动demo
来源:互联网 发布:服务器常用端口 编辑:程序博客网 时间:2024/06/01 09:59
package com.testpublic class BootService extends Service {private static final String TAG = "BootService";//receiver yzyl boot start serviceprivate static final String SERVER_ACTION = "com.test.BootStart";//start boot receiver public static final String BOOT_ACTION = "com.test.BootStart";@Overridepublic void onCreate() {// TODO Auto-generated method stubsuper.onCreate();}@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {// TODO Auto-generated method stubif(intent == null) return super.onStartCommand(intent, flags, startId);; String action = intent.getAction();Log.i(TAG, "onStartCommand::action : " + action);if(SERVER_ACTION.equals(action)) {boolean isBootStart = ToolUtils.isBootStart(this);Log.i(TAG, "onStartCommand::isBootStart : " + isBootStart);if(isBootStart) {sendBootCompletedReceiver(this);}}return super.onStartCommand(intent, flags, startId);}@Overridepublic IBinder onBind(Intent arg0) {// TODO Auto-generated method stubreturn null;}private void sendBootCompletedReceiver(Context ctx) {if(ctx == null) return;Intent intent = new Intent(BOOT_ACTION);ctx.sendBroadcast(intent);}}//在manifest里声明service和action名字 <service android:name="com.test.BootService" android:exported="true" > <intent-filter> <action android:name="com.test.BootStart" /> </intent-filter> </service>//调用的地方 public static void startBootervice(Context mContext) { if (!AppPkgUtil.isAppInstalled(mContext, JiLinEdog)) { return; } ExternalAppManager.enableSingleApp(mContext, JiLinEdog); String pkgName = "com.test; //待启动的包名 String pkgClassName = "com.test.BootService"; //待启动的service名字 Intent explicitIntent = new Intent(); ComponentName comp = new ComponentName(pkgName, pkgClassName); explicitIntent.setComponent(comp); explicitIntent.setAction(ACTION_START_TUZHISERVICE); try { mContext.startService(explicitIntent); } catch (Exception e) { e.printStackTrace(); } }
二、调试的打开service的方法
adb shell am startservice -n com.hdsc.edog/.BootService -a com.hdsc.edog.BootStart
0 0
- Service启动demo
- 启动Service
- web service demo
- InStall SerVice Demo
- Web Service 入门Demo
- web service cxf demo
- Service服务调用示例Demo
- 【Demo】Windows Service 定时服务
- Android Service: 启动service, 停止service
- ORACLE SERVICE不能启动
- VC# Service 无法启动
- 开机启动Service
- Android开机启动Service
- Android Service 自动启动
- HIVE Service自动启动
- 监听网络,启动Service
- Android Service---启动服务
- Android开机启动Service
- EJB中的@ejb注解
- lintcode,报数
- PCA的数学原理
- 第十五周项目五链接字符串
- 堆和栈理论以及程序内存分配
- Service启动demo
- const(一):(转) 一个函数名后面加const表示什么意思
- LeetCode 165. Compare Version Numbers
- 设计模式学习5——原型模式
- 安卓辅助功能 滴滴自动刷单
- 【HTML5】IIC
- 小白笔记-------------------------------leetcode(169. Majority Element)
- 设计模式随笔-状态模式
- RxJava使用入门(二)