2011-10-12 122 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