android


How to get the status of location access permission to warn user


How can I detect the status of location access when user rejected the permission in the permission manager of the app.
this is not about Android M,but all the API Level
I tried to use Context#checkPermission,but it always return true.so i can't get the right status of location access permission if the user rejected it.
private static boolean checkPermission(Context context, String permName, String pkgName){
PackageManager pm = context.getPackageManager();
if(PackageManager.PERMISSION_GRANTED == pm.checkPermission(permName, pkgName)){
System.out.println(pkgName + "has permission : " + permName);
return true;
}else{
//PackageManager.PERMISSION_DENIED == pm.checkPermission(permName, pkgName)
System.out.println(pkgName + "not has permission : " + permName);
return false;
}
}
Using ContextCompat.checkSelfPermission() has worked for me:
if(ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED){
return true;
}else{
Log.d(LOG_TAG, "Permission not granted: " + permission);
return false;
}

Related Links

The method onListItemClick(ListView, View, int, long) of type MainActivity must override or implement a supertype method
Android remove Popmenu scroll option
Proguard obfuscation giving database is locked error
Android Volley with Image Caching
Android alpha testing “Item not found”
Retrieving images using its path from server to android app
RecyclerView notifyItemChanged Prevent Scroll [duplicate]
Google Analytics doesn't report Real-time Android
Edit text integer
Titanium Alloy crash on android, Cannot call method 'open' of undefined
Native components, armeabi-v7a, and thumb?
Checkbox getting deselected in arrayadapter in listview
Android: member variable becoming null
How to detect color of the center of camera streaming in android without OpenCV
Missing App Icon after modifying Manifest
Save Image from res/drawable to Image Gallery Android

Categories

HOME
grok
hyperlink
fuelux
jax-rs
mysql-workbench
serialization
components
sublimetext
pdfbox
gembox-spreadsheet
special-characters
arangodb
g++
dkim
openpyxl
enthought
resultset
emoji
ycsb
nancy
gruntfile
package.json
dimensional-modeling
vuejs
forgot-password
google-container-registry
nim
topology
ember-cli
joptionpane
game-theory
slidetoggle
jquery-multiselect
appirater
gp
testbed
hunspell
hibernate-search
browser-extension
swagger-php
parse-tree
diacritics
apache-stanbol
file-sharing
strftime
snapchat
puredata
openal
lampp
serde
hammer.js
carrot2
custom-font
qtranslate
edit
android-testing
excel-dna
er-diagram
pybrain
reachability
winusb
nikeplus-api
drawstring
installshield-2010
nio2
assertion
qt5.2
binomial-theorem
viola-jones
amiga
ms-access-2000
fail2ban
nodelist
android-cookiemanager
viewer
ghcjs
raygun
named-parameters
ray
dct
dot42
ora-06550
solace-mq
modular
merb
argouml
thttpd
pylucene
massive
cuteeditor
msr
tmx
dot-emacs
addchild
isapi-extension
lalr
complex-event-processing
xpsdocument
scrubyt
fail-fast-fail-early
java1.4
dsoframer

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App