1

バックグラウンドで実行されるアプリケーションを開発し、IntentService最初に を使用しました。

これは私のコードです:

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) {
                  }
              }
          }*/
      }
}

マニフェスト

<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>

ADBシェルからサービスを開始したいので、このコマンドを使用しました

am startservice -n com.example.servicesusb/.UsbService

...しかし、サービスが開始されず、問題がわかりません

お願い助けて!

4

1 に答える 1

0

サービスが存在する場合は、次のように開始できます

adb shell am startservice <packageofservice>

それでもうまくいかない場合は、このコマンドを実行した後に受け取ったエラーを投稿してみてください

于 2013-05-01T12:11:34.183 に答える