简体   繁体   English

在Android主屏幕的右上方添加图标

[英]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, ie "API can be changed at any time", then I dont think I will use it. 如果没有记录,即“ API可以随时更改”,那么我认为我不会使用它。 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. 只需创建带有FLAG_ONGOING_EVENT标志的Notification FLAG_ONGOING_EVENT

Sure you can (at least in Android 4.3) 当然可以(至少在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) 1-创建图标(例如,使用eclipse中的File / New / Other / Android / Android Icon Set)(例如my_notif_icon.png)
2 - In your Service Activity, add a constant (eg MyServicenotifId) to be able to remove your notification icon when your service is killed: 2-在“服务活动”中,添加一个常量(例如MyServicenotifId),以便在服务被终止时能够删除通知图标:

private static final int MyServicenotifId = 1;

3 - Add the necessary imports: 3-添加必要的导入:

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

4 - In your onStartCommand method create the notification builder and manager: 4-在您的onStartCommand方法中,创建通知生成器和管理器:

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: 要在服务被终止时删除图标,请在服务的onDestroy方法中添加以下行:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android的主屏幕上制作自己的主屏幕并只使用一个按钮/图标? - How to make our own HOME-SCREEN & take only one button/icon on Home Screen in Android? 从网站为移动firefox提供主屏幕图标 - Provide home-screen icon for mobile firefox from web site 是否可以在Android主屏幕上制作动画移动小部件? - is it possible to make a animated moving widget on Android home-screen? 如何指定应用程序的主屏幕图标标题? - How do I specify my app's home-screen icon caption? 使用类别“ Home”和“ Default”来创建自定义主屏幕替换Android TV(不能在同一Android Phone上运行)吗? - Use category “Home” and “Default” for create a custom home-screen replacement Android TV (not work same Android Phone )? 二次点击Android主屏幕小部件不起作用 - Taping an android home-screen widget doesn't work the second time 如何为Android创建自定义主屏替换应用程序? - How can I create a custom home-screen replacement application for Android? Android主屏幕/启动器选择器不会显示“此操作默认使用”选项 - Android home-screen/launcher chooser does not show 'use by default for this action' option 在 Android Firefox 上添加到主屏幕不会屏蔽图标 - Adding to home screen on Android Firefox does not mask icon 单击时更新主屏幕小部件的TextView - Update the TextView of an home-screen widget on-clicking
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM