RanjitRock
RanjitRock

Reputation: 1441

Broadcast receivers on reboot?

I need to write data in to a file ,when system reboots not on boot complete. i am using broadcast receiver "android.intent.action.REBOOT" Below is my code and manifest files

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

manifest file:

<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>

but i am not able to write even a log when reboots. note:i donot want to use Bootcompleted action in broadcast receiver

Upvotes: 2

Views: 3808

Answers (2)

user3427635
user3427635

Reputation: 1

Add this, to me work, but on new devices, there are no testing. For example in the recent nexus not working.

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

Upvotes: 0

HXCaine
HXCaine

Reputation: 4258

I can't see why you don't want to use BootCompleted, could you provide your reasons?

There is no other action that will alert your broadcast receiver of the boot. You will have to use BootCompleted.

As a note, I hope you are registering you BroadcastReceiver with the context (since you didn't include that code). If you're not using BootComplete, I don't know what action you've registered to expect your above code to execute.

Upvotes: 2

Related Questions