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
Related
I need to show an activity on push received, but I am getting Background activity start from package-name blocked. system Toast.
This is an authentication activity where user needs to perform some task. I do not manage phone or NFC interaction thus I don't need to actually start 'special' service but showing notification is not enough - I need that activity.
SYSTEM_ALERT_WINDOW permission doesn't help.
So, should I re-implement all my flows to work only with notifications? Is there any possibility to start activity when application was closed (No activity in back stack)?
Android Q places restrictions on when apps can start activities. This behavior change helps minimize interruptions for the user and keeps the user more in control of what's shown on their screen.You can see the full document here
As of Android Q Beta 4, this change has the following properties:
Affects your app if you launch activities without user interaction
Mitigate by using notification-triggered activities
Disable restrictions by turning on the Allow background activity starts developer option
I'm going to show notification in any view in my Android application, but I didn't find any way how to do it without getting current activity.
On iOS we can just do
Window.AddSubview(customNotification);
But is there any way to do it in Android?
When you refer to notifications in Android, it means the notifications you can see out side the app (see notifications documentation for an explanation). I assume this is not what you are referring to because you are referring to the iOS Window.
Android also has a Window class. However, an Activity is usually the right UI component you should be looking at when adding a custom View. As opposed to iOS, an Android app almost always needs to work in a certain Context to add UI components and you can't just add one to a static Window.
My suggestion is then to change the logic a bit. I assume you have a running Activity at any point (if otherwise and you are running from a Service, perhaps notifications are the right solution after all). So what you can do is to broadcast your request to show certain data and the active Activity will pick it up and add your custom view to itself in the right spot.
Another option is to start a new dialog Activity using the application context.
I'd like to prevent my application from starting when an Android for Work profile is not available for my application (not yet configured, or deployed on the device). Instead, I'd like to be able to display a Toast like message telling the user to contact his IT administrator. Example of this at the bottom of this message.
Example:
Divide Productivity Suite of application displays this message (mail, notes, etc).
"Configuration from managing application required. Contact your IT admin for details".
Screen Capture
Is there a way to implement this? I've tried to hook into MainActivity onCreate function, or even put it directly in the Application onCreate() function. Hooking code in here seem to still have launched the application (the title bar is displayed despite there's no content displayed).
I was able to figure out how to determine if your Application was running on a for Work profile and display a alert dialog here:
Android for work - How to check if my application is running in the work profile?
Man i can give you specific topic . You can search for services instead of Activities. Activity codes performing only when application is running .
But you can call services everytime without your app is not running.
You can look here
Apparently, this was actually pretty trivial.
In your AndroidManifest.xml, you reference a new Activity that starts your main application. This activity will use the "Theme.Translucent.NoTitleBar"
When you are unable to configure Android for Work profile, use a Toast.makeToast() message to notify your user, then call finish() and return from your onCreate() function.
When you are able to complete Android for Work configuration, start your MainActivity by creating an Intent, set the action and category and then call startActivity() from your initial Activity.
I am given a task to show local push notification. I have successfully completed showing push notification on bar. But also I have to show local notification on app launching icon on home screen like in i-phone. See the image
I want this kind of notification. Here, may be the dialog I create using custom AlertDialog. But I'm stuck with the notification on the app icon i.e. that bubble containing notification no on upper right corner of app icon. I think this functionality is not given by android sdk. but our client says that she has seen these kinds of notifications on her Android mobile for some applications.
So is it possible in Android, and if yes then how to do it?
What you're looking for is a "badge" and I'm sorry to tell you that this does not exist on Android - your client must be mistaken.
One workaround you could do is to create a widget for your app (and you can even make it look like an app icon if you wish...), and you can add a badge or update how it looks any way you choose.
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.