2013-11-14 159 views
0

我看到這已被問了很多,但我似乎無法解決我的問題。自動啓動應用程序問題

我的onReceive()廣播接收器中的方法沒有被調用。

清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.app.test" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.app.test.TestActivity" 
     android:configChanges="orientation|keyboardHidden|screenSize" 
     android:label="@string/app_name" 
     android:theme="@style/FullscreenTheme" > 

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

    </activity> 
    <receiver android:enabled="true" android:name=".BootUpReceiver" 
    android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> 

    <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
    </receiver> 
</application> 

</manifest> 

BootUpReceiver.java

package com.app.test; 

public class BootUpReceiver extends BroadcastReceiver { 

private static final String TAG = "TESTAPP_BootUpReceiver"; 

@Override 
public void onReceive(Context context, Intent intent) { 
    Log.d(TAG, "helllllllllllllllo"); 
    Toast.makeText(context, "boot completed received", Toast.LENGTH_LONG).show(); 
    // Intent i = new Intent(context, TestActivity.class); 
    // i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    // context.startActivity(i); 
} 
} 

必須使用全路徑,而不是試圖.BootUpReceiver,沒有工作。沒有看到任何來自logcat或任何Toast消息。進入adb shell併發出boot_completed事件這種方式並不能幫助設備重新啓動。

有什麼我做錯了嗎?我讀了一些關於應用程序在設備啓動時處於不活動狀態的問題,這是否會影響我的問題?

+0

您不需要在 -tag內再次給予許可。儘管一見鍾情,但我沒有看到我的工作復興和你的區別。我現在仔細觀察:) – bofredo

+0

測試它。雖然日誌消息未顯示在我的日誌中,但Toast在鎖屏上可見。 – bofredo

+0

這就是爲什麼吐司在那裏 - 我讀日誌沒有啓動並在事件發送之前運行。我無法在鎖屏中看到它,也許我會嘗試其他設備。 – tbh1

回答

0

下面是Android開發者網站
http://developer.android.com/guide/topics/data/install-location.html

廣播接收機一些參考監聽「啓動完成」之前,外部存儲設備安裝到設備 該系統提供的ACTION_BOOT_COMPLETED廣播。如果您的應用程序安裝在外部存儲器上,它永遠不會收到此廣播。

+0

尚未在清單中提供'installLocation',因此它默認進入內部。 – tbh1