6.0以上等級列為dangerous會要求權限
例如GPS
底下列一下如何請求GPS權限
mLocationManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
mLocationListener=new MyLocationListener();
底下為要求權限(要求GPS還有藍芽)
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
String[] pers = new String[]{
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.BLUETOOTH
};
ActivityCompat.requestPermissions(this,pers,7777);
return;
}
這樣就可以要求三項權限囉
筆記一下
留言列表