Android show icon in Status bar - android

I want to show my App Icon in status bar without notification tray/drawer. just like alarm icon shows. I am also making application similar to alarm clock.
I have dig out few questions on stackoverflow, some say it is not possible without notification tray/drawer, but I have seen few apps doing this.
Can any one guide me better?
Thanks

You gave some alarm clock applications as examples, so I think you can start from understanding what this alarm clock icon in status bar is, and how it is shown there.
I note, that, as you can see, application "Alarm Clock Plus" doesn't set its own icon to status bar, just system icon for alarm.
You can see here how you can manipulate this icon on Pre-Lollipop only:
protected void setStatusBarIcon(boolean enabled)
{
Intent alarmChanged = new Intent("android.intent.action.ALARM_CHANGED");
alarmChanged.putExtra("alarmSet", enabled);
sendBroadcast(alarmChanged);
}
If you can give an example of application that puts its own (different from system alarm icon) icon to status bar (not as notification), it could help to see that it is possible.
Unfortunately, I don't think that it is possible.
Even just logically: there are two parts of status bar – user (notifications) and system (other). If system allows to put something to system part – there will be so much useless icons (posted by other applications), and there will be no consistency, and it might break all of the use experience. I think.
Hope it helps

Related

Customizing full screen intent notifications android

Project Target API 30 Android 10, Min API 19 KitKat
I am creating a parental control app where parents can restrict certain apps.
I have a foreground service where I would I ideally trigger an activity-like notification from the service that would envelop the user's entire screen or take them to the home screen.
I have learned that starting activities, including going to the home screen, is no longer possible under normal circumstances as of API 29. https://developer.android.com/guide/components/activities/background-starts
After reading the documentation it seems creating a full screen intent notification is the most highly recommended workaround to the activity restriction.
I am currently working with the following code for my full screen intent notification:
Intent blockedIntent = new Intent(App.getContext(), BlockedItemReceiver.class);
blockedIntent.putExtra("currentApp", restrictedApp.name);
PendingIntent pendingBlockedIntent = PendingIntent.getActivity(App.getContext(), 50, blockedIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder blockedNotificationBuilder = new NotificationCompat.Builder(App.getContext(), CHANNEL_BLOCKED_FROM_ITEM)
.setSmallIcon(R.drawable.ic_baseline_lock_24)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentTitle(restrictedApp.packageName + " was Blocked!")
.setContentText(restrictedApp.name + " will be available again DAY at TIME")
.setCategory(NotificationCompat.CATEGORY_CALL)
.setFullScreenIntent(pendingBlockedIntent, true);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(5, blockedNotificationBuilder.build());
I looked at some documentation for customizing notifications, but the information I found does not have a full screen intent notification example, and when I attempt to add the methods in the documentation example for NotificationCompat.Builder such as setCustomContentView() with custom layouts, my notification fails to appear without an error message.
https://developer.android.com/training/notify-user/custom-notification
Besides, I do not want a collapsed and expanded version of my notification as the example in the link has, just one full screen view.
TLDR; I want a notification that always engulfs the screen until the user presses a button on the notification to dismiss it. How can I further customize my full screen intent notification to truly take up the full screen? Ideally with a layout. If I must have a collapsed version of my notification, I don't want the user to ever see it, because I always want my notification to engulf the screen while it's showing.
There are existing apps such as AppBlock that have found a workaround to launching an activity-like thing from a foreground service that takes up the full screen, so what I am trying to do is possible even if the specific question I'm asking won't lead me to that result. Please suggest another way of accomplishing what I am after if what I am asking to do in my question is "impossible". What I generally want to do is certainly possible.

Custom Notification Manager

I can't remove my app notification from notification bar by sliding/swiping or with default "clear all" option in android.
I got .setAutoCancel(true) in code as well.
But it seems that doesn't work.
anyway to make it removable by swiping like I can do on other app notification. Mine just stuck there.
I know the cancel() and cancelAll(), and giving an intent method to remove by touch (from other stackflow posts).
I just found an help in another stackflow post..(was opposite of my requirement).
For me, I needed to make false in ongoing
nBuilder.setOngoing(false);
where, nBuilder is my Notification.builder

Difference in ways of maintaining Notifications

What is the difference between the function FLAG_ONGOING_EVENT and FLAG_NO_CLEAR how do they make the Notification behave differently? Do they both make the Notification permanent.
Documentation says :
FLAG_ONGOING_EVENT: Bit to be bitwise-ored into the flags field that should be set if this notification is in reference to something
that is ongoing, like a phone call. It should not be set if this
notification is in reference to something that happened at a
particular point in time, like a missed phone call.
FLAG_NO_CLEAR :Bit to be bitwise-ored into the flags field that should
be set if the notification should not be canceled when the user clicks
the Clear all button.
I think in these words they have different meanings so mixing these flags will give you a permanent notification until your program process ends , if you use just FLAG_ONGOING_EVENT this cause your notification runs until your binding service like phone call ends and it's also cancelable by developer or it can be clear by user and when you mix it with the other, user can't clear it from status bar.

Android: Make app transparent and act on the background application

Is it feasible to make our Android application completely transparent (as if its not active at all) and work on the other apps?
My Requirement:
First last an app and after some few settings, make it transparent. Once its transparent, the user will not know that this app is active, however, our app should respond to only specific controls.
This is because of the Broadcast receiver limitation, I will have to use the Volume button for some actions in my application. But, this button doesn't broadcast. So, currently I am using Power button which is not the requirement.
Please throw some light on this. I did some research but, couldnt find any. :(
This is because of the Broadcast receiver limitation, I will have to use the Volume button for some actions in my application. But, this button doesn't broadcast.
I am not sure it this is right. If you read Android BroadCastReceiver for volume key up and down question, it seems that you can detect it in BroadCastRceiver. I've never tried but it might be worth a try. Do something like following:
In your BroadcastReceiver onReceive function, do something like following:
public void onReceive(Context arg0, Intent intent) {
if (intent!=null){
int volume = (Integer)intent.getExtras().get("android.media.EXTRA_VOLUME_STREAM_VALUE");
// Get the old volume from the SharedPOreferences
// volume variable contains the current volume
// Compare it to the old value saved. If it is greater than old value then user pressed the UP Volume button else DOWN volume.
}
}
Also I am not sure that you can make it transparent and still keep it running. You can have a background of an activity as transparent though. How do I create a transparent Activity on Android?. Hope it helps.

android: alarm statusicon like the original alarm app?

I am making a alarm app and was just wondering how do I show a alarm icon at the right side of the statusbar like the original alarm app? normal notifications appear in the left side and I cant find anything about this....
Have searched for days and found it now in the alarm source code =)
Intent alarmChanged = new Intent("android.intent.action.ALARM_CHANGED");
alarmChanged.putExtra("alarmSet", true/*false if you want to hide it*/);
context.sendBroadcast(alarmChanged);
SDK applications can only use Notifications, which go on the left side of the status bar. Firmware applications can place icons elsewhere.

Categories

Resources