0

写真付きのライブ進行中のCPU(および/または)RAM通知を作成したいのですが、システムから取得した値と写真をリンクする方法がわかりません。

画像例:

アイドルの場合 --->http://imageshack.us/photo/my-images/840/idleq.png/

10 ~ 24% --->http://imageshack.us/photo/my-images/841/18037282.png/

25 ~ 49% --->http://imageshack.us/photo/my-images/267/74169930.png/

50 ~ 79% --->http://imageshack.us/photo/my-images/692/63885257.png/

80 ~ 99% --->http://imageshack.us/photo/my-images/20/39599298.png/

100% --->http://imageshack.us/photo/my-images/715/100to.png/

imageshack.us を使用して申し訳ありませんが、まだ画像をアップロードできません。

どうもありがとう。

4

1 に答える 1

0

通知の写真を変更できるとは思いませんが、複数の通知を作成して、必要に応じて呼び出すことができます。より良い答えがあるかもしれませんが、これで十分です。

通知を作成および破棄するメソッド

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 に再通知することで、動的パーセンテージなどを表示できますが、それを楽しむことができます ;)

于 2012-03-16T20:11:02.397 に答える