如何在右侧创建通知/状态栏图标?

12

好的,我看到很多人只是简单地回答说:

"它是为操作系统组件保留的"

"它需要访问源代码"

好吧,我可以访问源代码,并将任何应用程序或小部件设置为系统应用程序。那么现在我该如何使我的小部件在右侧显示通知呢?

编辑: 好的,人们走了错误的方向,所以我要添加一些上下文... 看看你的手机...你总是在手机的右侧看到Wi-Fi信号和电话信号,对吧。 我也想在那里显示我的信号...与系统信号一起...我们公司正在制造平板电脑,其中集成了新的硬件芯片,我必须不断显示其信号强度,就像手机信号一样。它将被集成到平板电脑的Android源中。


你是在谈论如何制作一个类似于Android平板电脑的状态栏吗? - Robin
不要……看看你的手机……你总是能在手机右侧看到Wi-Fi信号和电话信号,对吧。我也想让我的信号显示在那里……与系统信号一起。我们公司正在制作一款新的平板电脑硬件芯片,我必须像手机信号一样不断地显示它的信号强度。它将被集成到Android源代码中。 - Prince Champappilly
这么多浏览量却没有答案……能否有人点赞这个问题,让人们感到有必要回答它?或者赏金是怎么回事? - Prince Champappilly
嘿,如果你已经解决了这个问题,请分享一段代码片段。 - Zen
Google日语输入在右侧显示A或あ图标。它不是系统应用程序,而只是您可以从Play商店下载的普通应用程序。它在4.4.2三星设备和5.1.1 Nexus设备上都能正常工作。因此一定有某种API。 - Damn Vegetables
5个回答

7

终于有一个好的线索了,谢谢伙计 :) - Prince Champappilly
@PrinceChampappilly,这个答案有进展吗?Vallathum Nadakkumo? - Vishnudev K
@VishnudevK 问我要怎么做……是的,这就是答案……但是您需要在Android框架中添加自定义侦听器。我的方法是拉下双卡手机的代码,并将第二张卡的信号通知替换为我的自定义通知……这样我只需要在整个代码中编辑该实例即可。我没有完成整个过程……当时我已被重新分配到另一个项目。 - Prince Champappilly
我想问一下你是怎么回答这个问题的?我的意思是,你是学习了整个Android源代码还是使用了工具来搜索代码? - VSB
@VSB 你好。你现在知道那个问题的答案了吗? - Edw590
1
@DADi590,这是很久以前的事了。不幸的是,我无法检查或记起来了。 - VSB

2

你需要修改一些地方:

framework/base/core/res/res/values/config.xml,在以下位置添加一个插槽: <string-array name="config_statusBarIcons">

然后在frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java中:

mService.setIcon("<your slot name>", R.drawable.yourlogo, 0, null);
mService.setIconVisibility("<your slot name>", setVisible);

基本上就是这些了,相信通过一些试验和错误,你可以自己解决其余的问题。

0

我有一个简单的想法,即:

在清单文件中将 Android 屏幕方向声明为横向,并在纵向模式下设计成横向模式,这样您的应用程序在横向模式下看起来就像是纵向的。


哈哈...这只在应用程序内部运行...我想让它在小部件按钮按下时工作,这样即使在主页上也会一直可见...顺便说一句,不错的技巧 :P - Prince Champappilly
你需要在一定程度上修改Android操作系统,但由于Android是开源的,这不是问题。问题是将其安装在手机上 - 如果你注意到了,拥有自定义用户界面的唯一公司也是手机制造商,因此他们可以直接在其手机上预装该软件。 - Ruban
我正在制造平板电脑,已经在我的平板电脑上运行了Android源代码。我只想知道需要编辑源代码的哪个部分,以将我的信号栏添加到通知部分。 - Prince Champappilly
这就是为什么我打上了android-source标签,只有那些有编辑Android源代码经验的人才能帮助我……不过还是谢谢你的努力 :) - Prince Champappilly

-2

我正在寻找 Android 通知栏,不是那个 :P - Prince Champappilly

-2
public class GCMIntentService extends GCMBaseIntentService {

public static final String PROJECT_ID = "4898989797";
private static final String TAG = "GCMIntentService";
ModelNotificationMessage modelNotificationMessage;

public GCMIntentService() {
    super(PROJECT_ID);
    Log.d(TAG, "GCMIntentService init");
}

@Override
protected void onError(Context ctx, String sError) {
    // TODO Auto-generated method stub
    Log.d(TAG, "Error: " + sError);

}

@Override
protected void onMessage(Context ctx, Intent intent) {

    Log.d(TAG, "Message Received");

    String message = intent.getStringExtra("message");

    Log.d(TAG, "Message Received" + message);

    sendNotification(message);
    Intent broadcastIntent = new Intent();
    broadcastIntent.setAction("GCM_RECEIVED_ACTION");

    broadcastIntent.putExtra("gcm", message);

    ctx.sendBroadcast(broadcastIntent);
}




 private void sendNotification(String message) {
            // this
            String ns = Context.NOTIFICATION_SERVICE;
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

            int icon = R.drawable.notification;
            CharSequence tickerText = message; // ticker-text
            long when = System.currentTimeMillis();
            Context context = getApplicationContext();
            CharSequence contentTitle = modelNotificationMessage.getKey();
            CharSequence contentText = message;
            Intent notificationIntent = null;
            int NOTIFICATION_ID = 9999;



                NOTIFICATION_ID = CommonVariable.notification_message;
                notificationIntent = new Intent(this, ViewMessages.class);
                contentText = arrayList.get(0).getDescription();
                tickerText = arrayList.get(0).getDescription();

            // and this
            PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                    notificationIntent, 0);
            Notification notification = new Notification(icon, tickerText, when);
            // Play default notification sound
            notification.defaults |= Notification.DEFAULT_SOUND;
            notification.setLatestEventInfo(context, contentTitle, contentText,
                    contentIntent);
            mNotificationManager.notify(NOTIFICATION_ID, notification);
        }

这不是他想要的,他希望通知栏中的图标显示在右侧。 - Sunil Mishra
请在上述代码中找到以下行:Notification notification = new Notification(icon, tickerText, when); 这行代码用于在状态栏中显示通知的图标。 - dipali
这将创建一个默认通知,请查看http://developer.android.com/reference/android/app/Notification.html。 - Sunil Mishra
Dipali,这是为了在左侧创建一个简单的通知。我知道这个。我们想要的是将其放在右侧,并带有信号强度和电池图标。 - Prince Champappilly
它是内置的功能,用于显示通知。 - dipali
是的,是的,每个人都知道如何制作通知……谢谢你的努力……但我不是在寻找“如何显示通知”。 - Prince Champappilly

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接