通知の写真を変更できるとは思いませんが、複数の通知を作成して、必要に応じて呼び出すことができます。より良い答えがあるかもしれませんが、これで十分です。
通知を作成および破棄するメソッド
private NotificationManager notificationManager;
/* Params:
* int imageResourceId: The resource image to set
* String titleText: the title of the notification
* String statusText: the subtitle of the notification
*/
public void createNotification(int imageResourceId, String titleText, String statusText)
{
Notification notification = new Notification(imageResourceId, titleText, System.currentTimeMillis());
notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.setLatestEventInfo(mContext, titleText, statusText, null);
notificationManager.notify(1, notification);
}
/* Destroys all notifications */
public void destroyNotification()
{
if (notificationManager != null)
notificationManager.cancelAll();
}
わかりました、これは通知の作成と削除をカバーしていますが、さまざまなバッテリーのパーセンテージに合わせて通知を変更するにはどうすればよいでしょうか? 画像リソースに応じて、このような単純なもの。
使用例
if (batteryPercentage > 85)
{
destroyNotification();
createNotification(R.drawable.highBatteryIcon, "Good Battery", "85-100%");
}
else if (batteryPercentage <= 85)
{
destroyNotification();
createNotification(R.drawable.lowBatteryIcon, "OK Battery", "0-85%");
}
すべての画像を描画可能なフォルダーに入れ、必要に応じてすべてのパーセンテージなどに合わせてコードを変更します。しかし、それは私が個人的に行う方法です。
また、通知の latestEventInfo を更新し、notificationManager に再通知することで、動的パーセンテージなどを表示できますが、それを楽しむことができます ;)