2011-10-12 78 views
2

當系統沒有啓動完成時,我需要將數據寫入文件。 我使用廣播接收器「android.intent.action.REBOOT」下面是我的代碼和清單文件重新啓動廣播接收機?

public class broadcastreceiver extends BroadcastReceiver{ 
@Override 
public void onReceive(Context context, Intent intent) { 
Log.i("LOG_TAG","rebooted"); 
} 

清單文件:

<application android:icon="@drawable/icon" android:label="@string/app_name"> 
<activity android:name=".broadcast" 
android:label="@string/app_name"> 
<intent-filter> 
<action android:name="android.intent.action.MAIN" /> 
<category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter> 
</activity> 
<receiver android:name="com.example.broadcastreceiver.broadcastreceiver" 
android:enabled="true" 
android:exported="true" 
android:permission="android.permission.REBOOT"> 
<intent-filter>  
<action android:name="android.intent.action.REBOOT" /> 
</intent-filter> 
</receiver> 
</application> 

,但我不能寫,甚至一個日誌時重新啓動。 注:我想DONOT在廣播接收器使用Bootcompleted行動

回答

2

我不明白爲什麼你不希望使用BootCompleted,你能提供你的原因是什麼?

沒有其他動作會提醒您的廣播接收器啓動。您將不得不使用BootCompleted。作爲一個說明,我希望你註冊你的廣播接收器的上下文(因爲你沒有包括該代碼)。如果你不使用BootComplete,我不知道你已經註冊了什麼行動來期望你的上面的代碼執行。

+0

我需要維護接收器一個用於重新啓動,一個用於bootcompleted .i通過android.developers.com廣播recivers提示可能使用重新啓動操作。 – RanjitRock

+1

+1爲答案。你應該使用BootCompleted,如果你想趕上日誌輸出 – androidnoob

+1

,因爲「android.intent.action.REBOOT」被系統使用,它只能在side用戶應用程序中使用。我們需要用平臺key.i來簽署apk使用boot_completed ..感謝每一個 – RanjitRock