OK ,我發現找到了一種方法來做到這一點:)也許這不是一個美麗的一個,但它工作正常:
創建服務:
在AndroidManifest
註冊爲具有這些屬性
服務 android:name=".rtmpdumpService"
android:exported="false"
android:process=":rtmp"
啓動服務:
Intent rtmpdumpIntent = new Intent(getApplicationContext(), rtmpdumpService.class);
eSendIntent.putExtra("rtmp", "RTMP CODE");
startService(rtmpdumpIntent);
有時候,你不得不等待,直到它完成:
的售後服務(startService(rtmpdumpIntent):
do {
try {
Thread.sleep(500);
}
catch (InterruptedException e) {
//Log
}
} while(isServiceRunning(rtmpdumpService.class) == true);
isServiceRunning功能:
private boolean isServiceRunning(Class cl) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (cl.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}