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() {
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
更多精彩
赞助商链接