开发者

Broadcast receivers on reboot?

开发者 https://www.devze.com 2023-04-12 04:55 出处:网络
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

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>
</receiv开发者_开发技巧er>
</application>

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


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.


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"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消