2013-09-28 36 views
0

我有一個巨大的問題,我正在開發一個應用程序,啓動後啓動。使用BOOT_COMPLETED意圖動作很容易實現,至少在Android 3.1之前,所有已安裝的應用程序都處於「停止」狀態(正確?)並且必須明確啓動以註冊所有BroadcastReceivers。因此,我添加了一項活動,讓我的應用程序第一次啓動(因爲其餘是基於服務,啓動器中沒有圖標)並註冊接收者。奇怪的事情發生在2.2上,它完美的工作,而在Android 4.0和4.1(我猜所有在3.1以上)我得到錯誤「無法啓動服務意圖{...}找不到」。我認爲這很奇怪我的cmp = smth/.service而不是smth.service。你能解釋一下與這個問題有關係統的區別嗎?無法啓動服務意圖(4.0 vs 2.2)

我的清單(應用程序的一部分,它的其餘部分是不相關的):

<application android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <receiver android:name=".ReceiverCall" android:exported="false" android:enabled="true" > 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      <action android:name="android.intent.action.USER_PRESENT" /> 
      <action android:name="android.intent.action.SCREEN_ON" /> 
      <action android:name="android.intent.action.SCREEN_OFF" /> 
      <action android:name="com.android.ondeath" /> 
     </intent-filter> 
</receiver> 
    <service android:name="TheService" android:label="@string/app_name" android:exported="false" android:enabled="true" /> 
    <activity android:name=".Main" 
      android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

,也是接收器:

public class ReceiverCall extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 
    if(TheService.running() == false) 
    { 
    Log.d("Service", "ReceiverCall onReceive()"); 
    context.startService(new Intent(context, TheService.class)); 
    } 
} 
} 

我的活動剛剛開始,沒有佈局,它運行的onCreate這本身內部只有「完成()」。

感謝您的任何建議,可能會導致我的解決方案:)

@EDIT

我希望這是你的意思。

09-28 16:26:09.509: E/Trace(599): error opening trace file: No such file or directory (2) 
09-28 16:26:09.639: I/ActivityThread(599): Pub com.android.calendar:  com.android.providers.calendar.CalendarProvider2 
09-28 16:26:09.869: D/ExchangeService(550): !!! EAS ExchangeService, onStartCommand, startingUp = true, running = false 
09-28 16:26:09.929: D/dalvikvm(182): WAIT_FOR_CONCURRENT_GC blocked 0ms 
09-28 16:26:10.140: D/dalvikvm(182): GC_EXPLICIT freed 544K, 13% free 11241K/12871K, paused 23ms+38ms, total 214ms 
09-28 16:26:10.259: D/dalvikvm(615): Not late-enabling CheckJNI (already on) 
09-28 16:26:10.289: I/ActivityManager(182): Start proc co.appdemo for broadcast co.appdemo/.ReceiverCall: pid=615 uid=10044 gids={3003, 1015, 1028} 
09-28 16:26:10.629: E/Trace(615): error opening trace file: No such file or directory (2) 
09-28 16:26:10.729: D/Service(615): running() 
09-28 16:26:10.729: D/Service(615): ReceiverCall onReceive() 
09-28 16:26:10.749: W/ActivityManager(182): Unable to start service Intent { cmp=co.appdemo/.TheService }: not found 
09-28 16:26:11.079: D/dalvikvm(294): GREF has increased to 201 
+0

請發佈實際堆棧跟蹤,並附帶完整的錯誤消息。另外,如果您的''在未導出時運行正常,我會感到很驚訝,因爲第三方應用程序無法發送廣播。 – CommonsWare

+0

好吧,你需要什麼?接收器工作正常,因爲所有的廣播都是由系統發送的(對嗎?),最後一個是從這個包裏面發送出來的(並且不管用)。 – Ziker

+0

「接收器工作正常,因爲所有廣播都是由系統發送的(對吧?)」 - 我不知道系統可以發送廣播給非導出的接收器。 'startService()'調用是否失敗了您在活動中顯示的調用? – CommonsWare

回答

0

而不是

<service android:name="TheService" 

你可能需要有

<service android:name=".TheService" 
+0

試過之前,還預先全包名稱,沒有工作。 – Ziker

0

我真的不認爲你的服務或接收這個錯誤培訓相關。因爲它說這個類無法找到:com.android.providers.calendar.CalendarProvider2

因此,可能你正在使用一些第三方庫或什麼的,是嗎?如果是這樣,那麼它可能是一個問題相關如何實現它?

如果它是一個jar,我會建議你去屬性> Java構建路徑,如果你的jar沒有打勾,把它放在上面然後清理你的項目再次運行。

+0

nope,它是來自其他應用程序的日誌的一部分,錯誤與co.appdemo有關。 – Ziker

+0

所以你的「TheService」類在co.appdemo.TheService的位置是正確的嗎?你的軟件包名稱是「co.appdemo」嗎? – yahya

+0

是的,就像我說的那樣,它在Android 2.2上完美運行,所以我找不到在其他版本上無法正常工作的原因。 – Ziker

相關問題