This question already has answers here:
Android M - check runtime permission - how to determine if the user checked "Never ask again"?
(29 answers)
Closed 5 years ago.
When I call the getLastKnownLocation () method I get an error "Java Android call requires permission which may be rejected by user...". Apparently it's due to API23.
I can't find a valid solution yet.
You can use shouldShowRequestPermissionRationale() to check if you need to show the reason why you need this permission (and if it returns true - show the reason), and, of course, you need to request permissions with requestPermissions() method.
So, you can't do anything if user rejected the permission. It is meant to give error if user reject the request. You can do one thing if user deny then give a dialog to user asking to accept it otherwise the functionality will not work and redirect him to that permission dialog.
Related
This question already has an answer here:
How to set and retrieve the global variable's values in the feature file in karate?
(1 answer)
Closed 1 year ago.
I was wondering if anyone knows this karate problem I have.
Scenario: a user can create his profile
Given path '/signup'
And request { "username":"#(username)", "password":"#(password)" }
When method POST
Then status 200
the username has to have a unique value to get a 200 response. In this case it runs once but for obvious reasons doesn't run again.
Is there a way to hypothetically run the post request or perhaps use a dummy value?
Have you tried Postman? It's a program for testing APIs.
So I have an app where I get access on the camera. I am doing all the permission things like described here. In the end when the user denies the access, which happens in the onRequestPermissionResult function, I call onBackPressed(I also tried finish).
Now as expected after I deny the access, I don't get into the camera and go back to my service. Now the permission box appears the second time and I don't understand why, since onCreate isn't called anymore after I finish, right?
How do I get the second permission box away after I already denied access through the first one that popped.
Thanks for any help!
Try saving the result into shared preferences if they accepted or rejected then you can check if it has been rejected before you call for the request.
Link on shared preferences:
https://developer.android.com/training/data-storage/shared-preferences
This question already has answers here:
Run a piece of code only once when an application is installed [duplicate]
(4 answers)
Closed 5 years ago.
I have an if condition in my Java code in Android and I want to enter the block it's the first time the user has run the app. But for the second time and thereafter, they ignore the conditions.
How can I restrict the if block in my Java code?
This is my if block condition:
if(AppSharedPrefs.getInstance(SplashActivity.this)
.readPrefs(SplashActivity.this, "language").isEmpty())
{
AppSharedPrefs.getInstance(SplashActivity.this)
.writePrefs(SplashActivity.this, "language","English");
}
You need to have shared preference for your purpose. On first time store value true to shared preference and when next time user comes to the app get value from shared preference if that is true you dont need to call your code
"Simple": you pick one of the options for storing data on the device.
And then, your code reads that data back every time the application starts.
See here for an overview of options, and there for the option you should pick (shared preferences).
In other words: the whole idea is that you have to enable yourself to store data; so that your code can later make decisions based on that data. That is all there is to this.
This question already has answers here:
How to programmatically clear application data
(10 answers)
Closed 8 years ago.
am making a app that clears the internet cache when you click a button. In which i want it to have the permission you clear other app data. I have tried many different codes and cant find a one that is used for this purpose. Is there a special permission i need or is it even possible.
I have tried this code in MainActivity.java but cant seem to get it to work:
private void clearPreferences() {
try {
// clearing app data
Runtime runtime = Runtime.getRuntime();
runtime.exec("pm clear com.android.browser");
} catch (Exception e) {
e.printStackTrace();
}
}
Any help would be great. Thanks!
To clear it you simply delete the contents of it's data directory. There are 2 locations one on the SD, and another internally. You can clear the one on SD no problem, just use Apache FileUtils from Apache Commons, it has a function to delete a directory recursively. The internal dir requires root access. Or to be of same user. If you made both apps then it should be no problem just make sure they are the same user by setting sharedUserId parameter. If not, then your app could only work as root. See this answer to get data directory.
An alternative to rooting, you can open up the app info page for the app in question and tell the user to clear the app data manually by tapping on the clear data & clear cache buttons.
This question already has answers here:
Log in screen on first start
(4 answers)
Closed 10 years ago.
I want to make an app similar to SetupWizard. My app should initialize ONLY ONCE when the phone is turned on for the first time and after that it is never displayed. I got the way to autorun it on every boot as a service but how to make it run only once?
I HAVE RESEARCHED
You can store some value in SharedPreferences. And place a check on the value, if it exists and, then it means the app has already initialized.
SharedPreferences can be cleared by the user(just like web-session). If you want to ensure that your solution works even if user clears his phone, then you can get the device IMEI(example here) and send it to some server, which checks whether this device has already initialized or not?