想要实现一个自启动的功能,要扑捉系统的开机广播,我理解成时系统启动的广播通知: 不说了,直接上代码:
扑捉系统启动广播通知的类。 要继承系统 BroadcastReceiver类,
并且实现
view sourceprint?
public void onReceive(Context aContext, Intent aIntent),还是看下边的代码:
view sourceprint?
package com.amir.bootflag;
import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent;
public class BootMointor extends BroadcastReceiver {
public void onReceive(Context aContext, Intent aIntent) {
if (aIntent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent in = new Intent(aContext, BufferServices.class); in.setAction(\"com.amir.bootflag.BUFFER_SERVICES\"); aContext.startService(in); } } }
实现要启动的Service 的类: view sourceprint?
package com.amir.bootflag;
import com.amir.dbbuf.service.Md_0XEECMD_; import com.amir.dbbuf.service.OX_ECMD_Service;
import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log;
public class BufferServices extends Service{
public IBinder onBind(Intent arg0) { return null; }
public void onCreate() { super.onCreate();
Log.v(\"<====>\ }
public void onDestroy() { super.onDestroy();
Log.v(\"<====>\ }
public void onStart(Intent intent, int startId) { super.onStart(intent, startId);
System.out.println(\"OnStart Service\"); OX_ECMD_Service ecmd = new
OX_ECMD_Service(this.getBaseContext()); Md_0XEECMD_ o1 = new Md_0XEECMD_(); System.out.println(\"databases object\"); o1.setiCmdTypeField(0); o1.setiPrimaryKeyField(1); o1.setiReasonField(0); o1.setiYnField(1);
ecmd.InsertL(o1); }
public int onStartCommand(Intent intent, int flags, int startId) { Log.v(\"<====>\
return super.onStartCommand(intent, flags, startId); } }
咱们再看看 AndroidManifest.xml 里,要写一些什么: view sourceprint?
要想扑捉系统启动的广播通知,需要添加下边的权限: view sourceprint?
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- howto234.com 版权所有 湘ICP备2022005869号-3
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务