1
백그라운드에서 실행되는 응용 프로그램을 개발했으며 시작 부분에 IntentService
을 사용했습니다.백그라운드에서 응용 프로그램을 실행하십시오. IntentService
이 내 코드입니다 : 나는 ADB 쉘에서 서비스를 시작하려는 매니페스트
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.servicesusb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app`enter code here`_name"
android:theme="@style/AppTheme" >
<service android:name=".UsbService" >
</service>
</application>
</manifest>
그래서 난이 명령
am startservice -n com.example.servicesusb/.UsbService
을 사용
public class UsbService extends IntentService {
/**
* A constructor is required, and must call the super IntentService(String)
* constructor with a name for the worker thread.
*/
public UsbService() {
super("UsbService");
}
/**
* The IntentService calls this method from the default worker thread with
* the intent that started the service. When this method returns, IntentService
* stops the service, as appropriate.
*/
@Override
protected void onHandleIntent(Intent intent) {
Log.e("why", "fofo");
Toast.makeText(getApplicationContext(), "starting", Toast.LENGTH_LONG).show();
// mNotification.notify(132, builder.build());
// Normally we would do some work here, like download a file.
// For our sample, we just sleep for 5 seconds.
/* long endTime = System.currentTimeMillis() + 5*1000;
while (System.currentTimeMillis() < endTime) {
synchronized (this) {
try {
wait(endTime - System.currentTimeMillis());
} catch (Exception e) {
}
}
}*/
}
}
... 서비스가 시작되지 않고 문제를 알지 못합니다.
도와주세요!
오류는 없지만 paramte에서 보았을 때 내 srvice가 시작되었음을 알 수 없음 – user2326926
그래서 내 생각에는 솔루션을 heres ..... ..... 패키지가 설치되어있을 때 패키지가 설치되어있을 때 아무도 실제로 서비스를 제공하지 않습니다 그 서비스를 시작합니다. 그러면 adb를 통해 시작하는 것이 유일한 옵션입니다. 설정> 응용 프로그램/실행 중 전화에서 해당 서비스를 볼 수 있습니다 ............ 패키지 이름으로/위에서 사용 된 hv ...이 adb 셸은 com.example.servicesusb/.UsbService 대신 startservice com.example.servicesusb.UsbService 입니다. – cafebabe1991