WEB开发网
开发学院手机开发Android 开发 Android添加一个系统service 阅读

Android添加一个系统service

 2010-08-22 04:48:00 来源:WEB开发网   
核心提示:msg.arg1 = val;mHandler.sendMessage(msg);}private class EneaWorkerThread extends Thread{public EneaWorkerThread(String name) {super(name);}public void run() {Lo

msg.arg1 = val;

mHandler.sendMessage(msg);

}

private class EneaWorkerThread extends Thread{

public EneaWorkerThread(String name) {

super(name);

}

public void run() {

Looper.prepare();

mHandler = new EneaWorkerHandler();

Looper.loop();

}

}

private class EneaWorkerHandler extends Handler {

private static final int MESSAGE_SET = 0;

@Override

public void handleMessage(Message msg) {

try {

if (msg.what == MESSAGE_SET) {

Log.i(TAG, "set message received: " + msg.arg1);

}

} catch (Exception e) {

// Log, don't crash!

Log.e(TAG, "Exception in EneaWorkerHandler.handleMessage:", e);

}

}

}

}

Add to the system server

services/java/com/android/server/SystemServer.java

try {

Log.i(TAG, "Enea Service");

ServiceManager.addService(Context. ENEA_SERVICE, new EneaService(context));

} catch (Throwable e) {

Log.e(TAG, "Failure starting Enea Service", e);

}

Add a constant value to Context

./core/java/android/content/Context.java

public static final String ENEA_SERVICE = "enea";

最后

make update-api

make

上一页  1 2 

Tags:Android 添加 一个

编辑录入:coldstar [复制链接] [打 印]
赞助商链接