Close notification drawer after clicking button - android

My app creates a notification when some data is available. It has a button to copy that data to clipboard on the user's request. After doing so, the notification bar should close (without opening a new activity), so the user can paste the data they just copied into the app they were just using.
So far, I achieved this by sending sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); when the button was pressed, but targeting Android Sdk Version 31, this no longer is permitted (it says I need android.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS but even with this added to the manifest, I get the SecurityException).
I understand that "closing system dialogs" is nothing, that an app should do, but in my case the user clicked a notification which should dismiss the notification drawer. Is there a way to do this without the broadcast mentioned above?

Related

Can the setKeepAliveInBackground method be set to display as optional?

This API ensures the Android app runs in the background as per the worklight documentation. But with this, user is always shown a notification that the app is running in the background in the notification bar and user can not clear it.
Is there anyway to make this notification display as optional and not to show it in case not required?
As you can see in the documentation for Worklight 6.2 in regards to this API call:
For Android devices and hybrid applications, to ensure that the
application will continue to run in the background use
WL.App.setKeepAliveInBackground(true, options). Using this API binds
the application to a foreground service. By default, if no options are
specified, the application's name and icon are displayed. Tapping on
the notification takes the user back to the last activity that made
the call to WL.App.setKeepAliveInBackground(true). The notification is
present until the app exits, or WL.App.setKeepAliveInBackground(false)
is called. For details on using the options to change the text, the
icon, or which activity gets called when the user presses on the
notification, see the method setKeepAliveInBackground as defined in
the WL.App class.
Here is a link to the Knowledge Center outlining this:
http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.dev.doc/devref/t_keeping_app_running_in_background.html?lang=en
Here is a link to the WL.App class the above is referencing:
http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.apiref.doc/html/refjavascript-client/html/WL.App.html?cp=SSZH4A_6.2.0%2F10-0-0-1-2

Clicking on a generated notification cancels an existing AlertDialog

I'm building an Android app that handles incoming events.
When I receive 1 such event, if my app is in the foreground, I immediately generate an AlertDialog that requires the user's attention.
However, when the app is in the background, the user does not see this, even though the AlertDialog has already been generated. If I manually go back to my app, I see the AlertDialog and I'm able to click OK or cancel.
I tried generating a notification dialog that appears when my app is in the background. This works, and I put the PendingIntent as MainActivity. When I tap on the notification, it brings me back to my app. However, the AlertDialog isn't there anymore.
Comparing the logcats of tapping on the notification vs manually going back to my app, I notice several differences.
When I manually go back to my app, I see MainActivity is resumed immediately. However, when I tap on the notification, it first goes back to the constructor of the class that generated the notification, a few other classes/fragments, before finally resuming MainActivity.
Does anyone know why this might be the case?
Thanks.
The default behaviour of a foreground notification is to re-launch the activity. Try setting your intent flag for the PendingIntent to use this:
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
And that will then have the same behaviour as if you navigated to the activity through your app.
From docs:
If set, the activity will not be launched if it is already running at the top of the history stack.
it seems that,you are is creating new instance of app when resuming from notification
so,add this in manifest,it might help:
android:launchMode="singleInstance"
in other case it resumes hence dialog going to be persisted.

How to hide the pop up for my application?

Have a look on the below pic
The foreground pop up is handsent sms app.The back ground is my app. My problem is whenever an sms received popup window opens.The bad thing is even my app runs .Their pop up box may disturb my app users.How can block their pop up on my screens. The dafault sms app is opened then handsent sms app wont show popup on the window.Like that I also want to block other popup on my app screens.
Their pop up box may disturb my app users..How can block their pop up on my screens
You don't know that. This is not something you should try to control, if the user has an app that pops up, that is probably their preference. Your app should however be prepared for interruptions, i.e handle your app's lifecycle properly

Is there any way to clear the Voicemail notification that was added by my app in ICS?

My app is using the new VoicemailContract functionality in ICS to insert voicemails that show up in the stock call log. I've got it working perfectly, but I can't figure out how to control the new Voicemail notification that pops up when the new voicemails are added. The notifications seem to be controlled by the Phone app, and even if I manually update the voicemail's IS_READ attribute, the notification doesn't go away. In fact, I can delete the voicemail altogether, and the notification doesn't go away. The only way that it goes away is if that notification is clicked, or if I manually go into the call log and open one of the new voicemails.
Does anyone have any idea on how to control that programmatically from my app?
Unfortunately you can't. Status bar notifications can only be cleared by the app that placed them there. The phone app is the app that placed it there and this is why only that app is able to clear it.
I wish there was a way to do this myself, but currently, there is not :(

Notification to not reload app in android

I am currently developing an android app which uses the android web browser and notifications.
What I want to be able to do is the user clicks on an item which loads the android web browser and makes a notification in the notification bar as well.
The user should be on the browser when they go the notification, so when the user is on the browser and they click on the notification I want the notification to perform its task but not redisplay the app activity instead just return to where the user was on the browser.
I've tried setting the different flags on the activity but none of them seem to make any difference.
Thanks for any help you can provide.
According to the following quote from the Android documentation, it sounds like there isn't a way to do some kind of background task without starting an activity when a user clicks a notification. Although you may want to look into sending an Intent to a Service. I've have not tried that before so I can't say whether it works or not.
A notification always starts an
activity as a new task (that is, it
puts FLAG_ACTIVITY_NEW_TASK in the
intent it passes to startActivity())
The documentation also suggests you could have a dedicated activity that could perform the copy paste, and then the user could simply press back to get back to the browser:
For example, when the user receives a
Calendar notification, choosing that
notification starts a special activity
that displays a list of upcoming
calendar events — this view is
available only from the notification,
not through the Calendar's own user
interface. After viewing this upcoming
event, to ensure that the user
pressing the BACK key will return to
the activity the user was in when they
picked the notification, you would
make sure this dedicated activity does
not have the same task affinity as the
Calendar or any other activity. (You
do this by setting task affinity to
the empty string, which means it has
no affinity to anything.)
To get round this as I did not want to have a service running in the background to perform this simple task what I have done is called the method at the end of the activity that the notification calls.
I call moveTaskToBack(true); which places the task into the background. As if the user presses the home button.

Categories

Resources