0
私はBATTERY_LOW放送を受信したいので、現在の活動に頼らないために、放送受信機を宣言しました。ここに私がやったことだマニフェストで宣言されたバッテリー放送受信機が動作しません
<?xml version="1.0" encoding="utf-8"?>
<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">
<receiver android:name=".BatteryLevelReceiver">
<intent-filter>
<action android:name="android.intent.action.BATTERY_LOW"/>
<action android:name="android.intent.action.BATTERY_OKAY"/>
<action android:name="android.intent.action.POWER_CONNECTED"/>
<action android:name="android.intent.action.POWER_DISCONNECTED"/>A
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
とBatteryLevelReceiver自体(パッケージcom.wayruha.serviceguard.onduty):。
public class BatteryLevelReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.w(this.getClass().getName(),intent.getAction());
Log.w(this.getClass().getName(),"Low level:"+intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1));
}
}
t receive any of declared events!There are some similar questions here, but none of them helps me. I
mエミュレータでは、telnetを使用して容量を設定したり、「ac on/off」を設定することができます。
助けにはなりませんでした。私の知る限り、この許可はまったく異なる目的を持っています –