通知の作成に行き詰まっています。ステータス バー (通知バー) にバッテリー レベルを表示したいだけです。通知は永続的です。これはコードの一部です:
private BroadcastReceiver batteryInfoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int level= intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
String[] status = {
"Level: "+level
. . .
};
NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,"Level",System.currentTimeMillis());
notification.flags = Notification.FLAG_ONGOING_EVENT;
Intent i = new Intent(context, MainActivity.class);
PendingIntent penInt = PendingIntent.getActivity(getApplicationContext(), 0 , i , 0);
notification.setLatestEventInfo(getApplicationContext(), +level+"%", penInt);
notifi.notify(215,notification);
}
};
それが正しいか?たとえば、マニフェストに追加するものは他にありますか? 通知用に指定されたクラスがないので、この行をこのように書きました:Intent i = new Intent(context, MainActivity.class);
しかし、それが正しいかどうかはわかりません。