アプリケーションでバッテリレベルをパーセンテージで表示するように通知を作成しました。私のマニフェストファイルは、私はバッテリーレベルを受け取り、ステータスバーに通知するBroadcastReceiverを拡張する別のクラスを作成しブロードキャストでバッテリの変更値が更新されない
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.create.bg"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.BATTERY_STATS"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".CreateBgActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".BatteryReceive" >
<intent-filter>
<action android:name="android.intent.action.BATTERY_CHANGED"></action>
</intent-filter>
</receiver>
</application>
です。私のコードは次のとおりです。
public class BatteryReceive extends BroadcastReceiver {
private String bat = "android.intent.action.BATTERY_CHANGED";
@Override
public void onReceive(Context context, Intent intent) {
//Log.d("Battery Level", ""+intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1));
if(intent.getAction().equals(bat)) {
Toast.makeText(context, "Battery Level"+intent.getIntExtra("level", 0), Toast.LENGTH_SHORT).show();
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.ic_launcher,""+intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1),System.currentTimeMillis());
//notifyDetails.flags = Notification.FLAG_AUTO_CANCEL;
notifyDetails.setLatestEventInfo(context, "Batter Level", ""+intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1), null);
mNotificationManager.notify(1, notifyDetails);
}
}
}
私は任意の通知を取得したり、バッテリーレベル用の出力をログ:(それは私のコードに何か問題ですいくつかのいずれかが、このうち私を助けてcould't
ここではhttp://code.google.com/p/batterywidget/source/checkout – Rishi
@Rishi私はすでに1つを見たバッテリーウィジェットの完全なソースです。私のコードで実装したのと同じことですが、うまくいきません。 –
下記のクラスを参照してください://code.google.com/p/batterywidget/source/browse/trunk/a_batterywidget/src/com/geekyouup/android/widgets/battery/BatteryWidget.java?r = 5 Remoteviewビルドのアップデートあなたはあなたのバッテリーレベルを取得 – Rishi