I am an Android developer and I want to write an if statement in my application. In this statement I want to check which app is run which time in my mobile like Facebook, messenger,You Tube,chrome etc when its open and when its close. How can I do this programmatically?
I'm not sure what you mean with the if statement part but I guess that what you are looking for is UsageStatsManager.
Take into account that this API requires the permission android.permission.PACKAGE_USAGE_STATS, which is a system-level permission and will not be granted to third-party apps. However, declaring the permission implies intention to use the API and the user of the device can grant permission through the Settings application.
Related
i have a question related to Android app run time permissions.
Is it preferrable/allowed practice for developers to save users' permission preferences i.e. each user has allowed/denied any permission, on our remote server database?
Offcourse we are asking run time permission for every feature we want to use, but is it preferrable that we log on server that if user has allowed for any permission or not, please let know. Thanks
Android framework has restricted the developers to ask only those permissions which are necessary to implement a specific feature and that too if there's no other way to implement the feature without that specific permission. In your case, it seems like you have already taken care of the permissions and just want to hold the result of the asked permissions.
So the answer is YES, You can save this data and it's even considered good practice for handling permissions. Here's the reference from the official android documentation.
Greater flexibility in granting permissions
Users can deny access to individual permissions at the time they’re requested and in settings, but they may still be surprised when functionality is broken as a result. It’s a good idea to monitor how many users are denying permissions (e.g. using Google Analytics) so that you can either refactor your app to avoid depending on that permission or provide a better explanation of why you need the permission for your app to work properly. You should also make sure that your app handles exceptions when users deny permission requests or toggle off permissions in settings.
https://developer.android.com/training/permissions/usage-notes
I want to enable phone permission by default for an Android application. On checking multiple posts I see that it is getting added up at runtime explicitly by user during installation. Can I avoid it and enable it by default?
I am adding the permission READ_PHONE_STATE in Android Manifest. But this doesn't enable it by default unless and until the user goes to the setting and enable it manually.
Permission needs to be requested from the user. If you try to use the feature without permission, it will crash the app. The permission needs to be in the manifest and you need to request permission from the user as well. There is no way to do it automatically.
Side note: I believe this permission specifically is under higher scrutiny when submitted to the Play Store. The announcement they sent last year mentioned that you'll only be able to use this permission if you provide a valid reason such as making an alternative dialer app.
How to monitor another app behaviors in android like QualityTime in Google Play?
I try this by using UsageStatsManager with PACKAGE_USAGE_STATS permission. But it returns nothing from
queryAndAggregateUsageStats(long beginTime, long endTime)
https://play.google.com/store/apps/details?id=com.zerodesktop.appdetox.qualitytime
APP monitor
As it says on the docs:
"NOTE: This API requires the permission android.permission.PACKAGE_USAGE_STATS, which is a system-level permission and will not be granted to third-party apps. However, declaring the permission implies intention to use the API and the user of the device can grant permission through the Settings application."
You are a third party app. So you won't get this permission granted on install. And you won't get any results unless the user goes to the settings application, and explicitly turns on this for your app.
When you open the camera the user is prompted to grant the app permission to access the camera.
Is there any way in Codename one to tell if the user has denied this permission?
With either a callback or some kind of global call?
This specific to iOS but with the recent updates to Android the same question is also relevant there.
This is now built in to the CodenameOne platform - https://www.codenameone.com/blog/switching-on-android-marshmallow-permission-prompts.html
Currently we haven't enabled the Marshmallow permission prompts by default in part due to the lack of an API to indicate that.
We have a standard API for contacts permissions which we needed in iOS and most of the API's should be ready for Marshmallow since iOS always had the ability to deny permissions.
But we need to re-think the API's for querying that detail and whether we want them to follow the style of isContactsPermissionGranted.
I noticed there is no issue to track the progress of this so I filed it.
is there any way for hide the android manifest Permissions for some reasons and user couldnt see during installing the app?
Taken from the support page from Google Play:
Google Play shows you which permission groups an app will be able to
access. This information can help you decide whether you want to
install the app.
The whole sole purpose of those permissions is for people to see what your app can access and decide whether they want to share (all) that information with you.
In Android L and lower, this is impossible. If you do not ask for a permission, you will get a crash when you try to access the thing that needs permission. Thus, you cannot hide permissions from users.
In Android M, the whole permission idea is changed: instead of asking for lots of permission at the install, the app is installed without permissions, and when you need a specific permission, for example for camera, the user will have the option of accepting or declining the permission. Thus, the user will have a clearer view of what a permission is asked for.