java - Battery Broadcast Not Triggered -
i have written below code in manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="jss.battery"> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundicon="@mipmap/ic_launcher_round" android:supportsrtl="true" android:theme="@style/apptheme"> <activity android:name=".mainactivity"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <receiver android:name=".batteryreceiver"> <intent-filter > <action android:name="android.intent.action.action_power_connected"/> </intent-filter> </receiver> </application> </manifest>
and below code receiver:
public class batteryreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { toast.maketext(context, "broadcast received", toast.length_long).show();}}
but m not getting toast on app launch. , here code mainactivity:
public class mainactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity); } }
is there error in code? read many pages similar issue here none of solution worked. referred https://developer.android.com/training/monitoring-device-state/battery-monitoring.html#determinechargestate .at testing time battery level 80% +.
quoting the documentation, broadcast "will sent after action_battery_low
once battery has gone okay state". in case, battery @ 80%, past low/okay dividing line (which think around 15%, might vary hardware or os version).
Comments
Post a Comment