Create notification without it popping up - android

I'm trying to add an android notification to the "tray" in android 3, but I don't want it to "pop up" every time I call notify().
I managed to kind of do this by setting the FLAG_ONLY_ALERT_ONCE flag on the notification, but it will still alert when I set it for the first time.
It seems like this is possible, but I'm not sure how to do this (an example is the Prime ROM for the Asus transformer. When you plug in the dock, a new ongoing notification will be added to the notification area, but there is no alert, or "popup" there.. It just adds another icon to the list quietly. How can I do the same?

Just set the tickerText to null. You can do this when creating your notification with:
Notification notification = new Notification( R.drawable.icon, null, System.currentTimeMillis());

Related

i need to remove notification without affecting foreground service

I need to remove the notification.without affecting the foreground service of the application.thanks in advance
Notification note = new Notification(R.drawable.ic_blank,"",System.currentTimeMillis());
Intent i=new Intent(this, MyLocationListener.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pi=PendingIntent.getActivity(this, 0,i, 0);
note.setLatestEventInfo(this, "","", pi);
note.flags |= Notification.FLAG_NO_CLEAR;
startForeground(42, note);
Android OS don’t like you to do this because users are entitled to know you are running a foreground serivce on their devices.
But if you must remove notification of foreground service :
In order to remove the notification icon in the notification area (the status bar) while foreground service still running :
Just set the priority to minimum (-2) in the notification builder:
for example:
/* (Notification.PRIORITY_MIN) will remove the notification in statusbar */
builder.setPriority(Notification.PRIORITY_MIN)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Service Started")
.setTicker("Music Playing")
.setWhen(System.currentTimeMillis());
This will only remove the small notification icon in the notification area.
if you also need to get rid of the detail notification rectangle in the notification drawer :
then what you need to do is more complex:
you need to start your service as foreground, then start another foreground service with the same notification ID as you have in your original service.
Then close ( stopself() ) the new foreground service, and Android system will remove the notification (while your original service that started previously will stay in foreground without the notification).
This works fine in 5.1.1, I don’t know if android team already close this breach in marshmallow .
BTW:
In order to do this there is also a non-programmatically way :
Go to settings -> applications -> application manager find your application and press on it.
You will get inside your application info.
Disable the “show notifications” option in your application info.
This will get rid of all notifications for your app but it also disable toast messages..
I don’t think there is a way to disable this option in settings programmatically from inside the application - I think android prevent it for security reasons. If anyone knows how to change this programmatically please tell..
if while trying to avoid the notification detail rectangle in the drawer you will remove these lines in your notification builder:
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Service Started")
.setTicker("Music Playing")
.setWhen(System.currentTimeMillis());
Then Android system will keep on showing a notification rectangle about your service (with the title “This service is running, touch for more information or stop the service ” ) and pressing on this rectangle will lead the user to Your application info on settings -> applications -> application manager with option to “force stop” this service.
Regarding that you can read more here https://plus.google.com/105051985738280261832/posts/MTinJWdNL8t
hope it helps :-)
Adding this line builder.setPriority(Notification.PRIORITY_MIN) will remove the notification icon from the status bar and lock screen.
Also removing or commenting builder.setSmallIcon(R.drawable.ic_launcher) removes the notification icon even when you scroll down notifications when device is unlockedbut i m not sure how it will work in android N

I am getting pushwoosh response null

I have integrated pushwoosh in android application (not in titanium)..
I am successfully getting notification also..
My issue is,
Text is displayed on notification area which I passed from woosh..
BUT NOT ABLE to extract it from intent
intent.getExtras().getString(PushManager.PUSH_RECEIVE_EVENT)
Also my notification does not remain on notification area..
it only displayed once and disappear, I am not able to click on that
because it is not staying there..as like other notification..!!??
Please can anybody suggest any thing..?
For notification to remain on the notification bar there is falg to set in Android Notification.
Notification not= new Notification(R.drawable.icon,title+" "+context.getString(R.string.Start_in),System.currentTimeMillis());
not.flags=Notification.FLAG_NO_CLEAR;
For Android Notification there is One falg to Clear the notification or not. So I think there will some flag to Not clear the Notification when it arrives.
So Try to find out the flag for not clearing the Notification.
As you are setting flag for sound
pushManager.setSoundNotificationType(SoundType.ALWAYS);

Switching Android notification from FLAG_ONGOING_EVENT to cancelable

I have an ongoing task and after it finishes, I want the notification to become cancelable.
For that, I create a new notification with notification.flags as zero, but the notification keeps being un-cancelable.
Apparently, FLAG_FOREGROUND_SERVICE prevented the notification from turning into cancelable, even after reseting the flags.
After removing FLAG_FOREGROUND_SERVICE and using only 0 or FLAG_ONGOING_EVENT, the notification could be made cancelable or un-cancelable - respectively.
Please take a look here : Android update notification
In short what you will do is this:
Create your notification first time and assign a notification ID to it.
Once your service is done executing create a new cancelable notification with the same id
fire that notification, it should make the previous notification cancelable .

How to silently add a notification?

I'd like to selectively hide and show a notification based on what a user does.
Since that would happen pretty often, I'd like to have it appear in the notification dropdown without having the text message appear in the status bar every time I show it.
Task manager does it when I toggle it in its preference screen.
When you create the Notification object, pass null for the ticker text.
Notification n = new Notification(R.drawable.icon, null, System.currentTimeMillis());

Android Notification without click event?

I would like to try and make a Notification that does not respond to a click. Is this possible? i.e. when it is visible in the Notification area, and the user touches it, I want "nothing" to happen.
This is different to a normal Notification - when it is visible, and the user touches it, the Notification Area hides, and the Intent is launched. I do not want the Notification Area to hide when it is touched.
I can make one that doesn't launch an activity:
Possible to make an Android Notification that does not call an Intent?
Android - notification manager, having a notification without an intent
But it still responds to a click, by hiding the notification bar again (i.e. standard expected behaviour).
This question is a duplicate of How to disable a click event of notification in android development but that question does not have an answer. (if there is a better way to ~bump~ that question up again, I will do that & delete this question)
Note: I know this is not "the Android way", but it is still something I would like to try.
I do not want the Notification Area to hide when it is touched.
That would require firmware modifications. You are not in control over the notification area; the OS is.
Use Intent intent = new Intent() and insert this into the PendingIntent.
Have you ever tried
new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// Set the intent null or empty and autoCancel false
.setContentIntent(null)
.setAutoCancel(false);
For more info about setAutoCancel() check Android Document here.

Categories

Resources