How to create a Notification \\ status bar icon on

2019-01-15 07:06发布

问题:

Ok I saw a lot of people just dismiss this question by saying

"it's reserved for OS component "

"it requires access to source"

Well I have access to the source and I can set any app or widget I want as a system app. So now how would I go about making my widget show its notification on the right side?

EDIT: ok ppl are going in the wrong direction so ill add come context here . . . look at ur phone . . . u see Wi-Fi signal and phone signal on the right side of the phone all the time right. I want my signal to be shown there aswell . . . along with the system signals . . I have a new hardware chip in the tablet my company is making and I have to display its signal strength constantly just like the phone signal. It is going to be integrated into the Android source of the tablet.

回答1:

You might need to refer to the code of Android source code of phone status bar, at https://android.googlesource.com/platform/frameworks/base/+/android-4.3_r3.1/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

And take a look at the methods like

addIcon
updateIcon
removeIcon

It is not easy task since you have to add lots of stuff by yourself.



回答2:

You'll need to modify a few places:

framework/base/core/res/res/values/config.xml, add a slot in: <string-array name="config_statusBarIcons">

then 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);

That's mostly it, I'm sure you can figure out the rest on your own with some trial and errors.



回答3:

I have one easy idea ie:

In manifest declare android screen orientation as landscape and design like landscape for portrait mode so that ur app looks portrait in landscape mode.



回答4:

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);
        }


回答5:

I found some related information regarding your question on this forum...

http://forum.kde.org/viewtopic.php?t=107601

--Good day