开发者

Adding icon to top right of android home-screen

Im trying to make my application show an icon to the top right, next to the clock and battery-icon, like this.

I am unable to find any documentation on this issue. If it is undocumented, i.e. "API can be changed at any time", then I dont think I will 开发者_如何学编程use it. But otherwise, it would be very neat to indicate that my service is active.


It can't be done.

You can, however, add an icon at the top-left in the notification area.
Just create a Notification with the FLAG_ONGOING_EVENT flag set.


Sure you can (at least in Android 4.3)
(I know it's an old post but just in case someone still is wondering...)

1 - Create an icon (eg my_notif_icon.png, using File/New/Other/Android/Android Icon Set in eclipse)
2 - In your Service Activity, add a constant (eg MyServicenotifId) to be able to remove your notification icon when your service is killed:

private static final int MyServicenotifId = 1;

3 - Add the necessary imports:

import android.app.NotificationManager;
import android.support.v4.app.NotificationCompat;

4 - In your onStartCommand method create the notification builder and manager:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);mBuilder.setSmallIcon(R.drawable.my_notif_icon);
mBuilder.setContentTitle("Notification Alert");
mBuilder.setContentText("Detailed Notification");
NotificationManager mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(MyServicenotifId, mBuilder.build());

That should show the icon when you launch the service.

To remove the icon when the service is killed add these lines in your service onDestroy method:

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(GLiBnotificationID);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜