2011-12-02 72 views
16

我知道,我不是第一個有這個問題的onbe,但我嘗試了很多解決方案,我找到了,沒有人工作......也許你可以找到錯誤Android:無法啓動服務意圖:找不到?

錯誤(也沒有。類並用/.Client取決於其他設置)

12-02 16:40:15.359:W/ActivityManager(74):無法啓動服務 意圖{ACT = com.android.fh.EnOceanApp。 Client.class}:未找到

在清單中,這包含在應用程序中,不包含活動(試了也在活動,並與 「.Client」

在的onCreate的代碼()

startService(new Intent(this, Client.class)); 

startService(new Intent(this.getApplicationContext(), Client.class)); 

Intent intent=new Intent("com.android.fh.EnOceanApp.Client.class"); 
    this.startService(intent); 

Intent intent=new Intent("com.android.fh.EnOceanApp.Client"); 
    this.startService(intent); 

而現在,我沒有一個想法了.... com.android.fh.EnOceanApp是包,Client.java服務類在這個包

和清單我忘了:

<application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:label="@string/app_name" 
      android:name=".EnOceanAppActivity" > 
      <intent-filter > 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter>  
     </activity> 

     <activity android:name=".ListView" 
      android:label="List View"> 
     </activity> 
     <activity android:name=".GraphView" 
      android:label="Graph View"> 
     </activity> 
     <service 
      android:name=".Client"></service> //with and without ., of course without this comment 
    </application> 
+1

後您的清單。 –

+0

在您的清單中聲明您的服務 – njzk2

回答

2

所以..只是最終幫助他人或不:

我做了一個新的項目,複製源代碼,並試圖運行它的服務現在被發現。 有什麼區別,或換句話說:我認爲可能會產生問題: 長包名或以com.android開頭。 。在新的項目中,我只是選擇了com.enocean

4

有時您需要在清單中完全限定您的類名,而不是使用shortform(.classname)。我已經看到,當我使用不同包中的類時,但可能會對此有所幫助,因爲服務意圖可能會超出應用程序範圍。

+0

迄今爲止這並沒有改變任何東西:( – nico

+0

幫助了我,我的服務與我的主要活動 – Tirtha

+0

com.andorid。*在Playstore上有所限制(僅供參考) – scottyab

21

由於用戶njzk2讓我看到發生了什麼事。

我遇到了同樣的問題。如果您之前未在您的專家的清單文件中註冊,那麼Android OS似乎找不到您請求的服務類。

請記住,服務就像一個活動,但沒有圖形界面。這意味着,服務需要註冊後才能使用它們

這是你如何在你的Android項目註冊服務:

<application> 
    <!-- your code --> 
    <activity> 
     <!-- your code --> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <service android:name="com.your.own.service.class"></service> 
</application> 

只記得YourService類需要從服務擴展,如果不是你的班級不會是一項服務。

public class YourService extends Service{} 
+3

也有同樣的問題,並注意到如果我用「/>」關閉標籤,它在應用升級後不會檢測到服務,但如果我關閉「」,它會在應用升級後檢測到它。 Weeiird。 – Danail

+0

@Danail謝謝你解決了我的問題! :-) – Ostkontentitan

+0

@Konstantin,認爲你只需要清除整個項目。這是我的問題。 – Danail

0

我犯了一個愚蠢的錯誤,即將標籤添加到單獨的清單中。

在這種情況下,當前應用程序無法找到定義的服務。

希望你跳過那個錯誤:)

謝謝。

1

儘管所有在這篇文章中的答案和許多相關Unable to start service Intent: not foundUnable to start Service Intent,我仍然掙扎,我花了一些時間讓這一切。由於我試圖在不同的應用程序中啓動服務,因此我的情況稍微複雜一些,因爲我正在調用該應用程序。我想通了,這裏是所有的細節,以及一些獎金代碼。服務(Application標籤內的服務標籤)的 這是

<service android:name="com.example.core.MusicService"> 
     <intent-filter> 
      <action android:name="com.example.core.MusicService1234"></action> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="com.example.core.MusicService.TOGGLE_PLAYBACK"></action> 
     </intent-filter> 
    </service> 

MusicService.java

:調用的意圖(或徘徊無論)

Intent intent=new Intent("com.example.core.MusicService.1234"); 
//Or Intent intent=new Intent("com.example.core.MusicService.TOGGLE_PLAYBACK"); 
PendingIntent pendingIntent = PendingIntent.getService(this, 99, intent, PendingIntent.FLAG_CANCEL_CURRENT); 

艙單

MainActivity

@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
    if(intent != null){ 
     if(intent.getAction() != null){ 
      if(intent.getAction().contentEquals("com.example.core.MusicService.TOGGLE_PLAYBACK")){ 
       //Do work here 
      } 
     } 
    } 
} 

注意

  • 服務並不需要啓動,這種意圖將啓動
  • 「com.example.core.MusicService1234」 和 「com.example.core.MusicService.TOGGLE_PLAYBACK」可以是任何你想要的,但顯然需要將服務清單中的意圖過濾器與調用意圖進行匹配。您可以放置​​其中的多個,這樣您可以在服務啓動時採取不同的操作,具體取決於您的意圖的價值。
  • 99可以是任何您想要的,但必須是唯一的,如果您使用通知
  • 我不是確定有可能在不使用意圖過濾器的情況下調用另一個應用程序中的服務(如此) - 如果是,請指教某人。我試過了,它不起作用。

信用:從所有職位:)累計信息

+0

這個答案看起來很有趣,但沒有太多的代碼來嘗試提供的解決方案 – Lisitso

0

這是Android的

愚蠢的錯誤則無法使用此

<service 
      android:name=".classname"/> 

但是這會工作,有獨立的關閉標籤

<service 
      android:name=".classname"></service> 
0

對我來說,我不得不清理這個項目。它有時會發生在爲包/項目中的服務創建了新的Java類之後,但不會在後期建立/清理項目的情況。就我而言,我只需清理該項目即可擺脫錯誤。

0

如果有人看到這一點,並有我做了同樣的問題,那是因爲我也跟着指南和使用context.startService()代替context.startActivity()

相關問題