AppCompatActivity
으로 확장되는 활동이 있습니다. 이 활동을 실행하려면 앱에 ACCESS_COARSE_LOCATION
및 WRITE_EXTERNAL_STORAGE
권한을 부여해야합니다. Android Studio 3.0으로 업데이트 할 때까지 모든 것이 잘 작동했습니다. requestPermissions 프롬프트가 표시되지 않습니다.
WRITE_EXTERNAL_STORAGE
권한을 요구하는 메시지가 표시되지 않고, 함수
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults)
가 반환 -1 grantResults에서도 요구없이.
허용되는대로 ACCESS_COARSE_LOCATION
권한을 요청하면이 동작이 발생하지 않습니다. 다른
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (this.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("This app needs location access");
builder.setMessage("Please grant location access so this app can detect beacons.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);
}
});
builder.show();
}
}
그리고 : 이하, 코드가 모두 검사를 호출
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final int PERMISSION_REQUEST_COARSE_LOCATION = 1;
if (this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("This app needs sd access");
builder.setMessage("Please grant sd access so this app can save files.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
}
});
builder.show();
}
}
대응하는 부분을 내 매니페스트에하는 것은 다음과 같습니다 : 나는 많은 것들을 읽었습니다
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
, 그러나 이것은 꽤 이상한데, 어떤 종류의 권한이 요청 대화 상자를 보여줄 때, 다른 것들은 그렇지 않습니다. 그런데 장치에는 SD 카드가 없습니다 (항상 내부 저장소가 사용됨). 그러나 문제가되지 않았습니다.
모두 내 targetSdkVersion
및 compileSdkVersion
도 제대로 작동 26
편집
기타 관련 권한과 같은 READ_EXTERNAL_STORAGE
이다. 쓰기 권한과 관련된 문제 일뿐입니다. 사전에
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_device_discovery);
context = this;
wm = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);
intent = getIntent();
if(intent.getBooleanExtra("LOCAL_NETWORK", true) == true){
ipAddress = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
port = DEFAULT_LIGHT_PORT;
}
else{
ipAddress = intent.getStringExtra("TRACK_IP");
port = intent.getIntExtra("TRACK_PORT", DEFAULT_GATEWAY_PORT);
}
font = Typeface.createFromAsset(MainActivity.mainActivity.getAssets(), "RepRg.ttf");
mHandler = new Handler();
deviceArrayList = new ArrayList<>();
devicesBufferList = new ArrayList<>();
lightListAdapter = new LightListAdapter(this, deviceArrayList, intent);
discoveredListView = (ListView) findViewById(R.id.paired_devices);
discoveredListView.setAdapter(lightListAdapter);
listAllCheckBox = (CheckBox) findViewById(R.id.listAllCheckBox);
refreshButton = (ImageButton) findViewById(R.id.refreshButton);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("This app needs sd access");
builder.setMessage("Please grant sd access so this app can save files.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
}
});
builder.show();
}
}
listAllCheckBox.setTypeface(font);
listAllCheckBox.setTextSize(18);
listAllCheckBox.setTextColor(Color.parseColor("#202020"));
listAllCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
lightListAdapter.clear();
processDeviceListing();
}
});
refreshButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
refreshButton.setImageResource(R.drawable.refresh_down);
break;
case MotionEvent.ACTION_UP:
refreshButton.setImageResource(R.drawable.refresh_up);
refreshDevicesList();
break;
case MotionEvent.ACTION_CANCEL:
refreshButton.setImageResource(R.drawable.refresh_up);
break;
}
return false;
}
});
}
감사 : 두 안드로이드 장치 및 에뮬레이터
전체에서 onCreate 메소드에서 테스트.
다른 사람에 유용 바랍니다. 문제는 ACCESS_COARSE_LOCATION을 (를) 요청할 때 권한 요청에 대한 프롬프트가 표시되지만 WRITE_EXTERNAL_STORAGE를 요청할 때는 표시되지 않는 것입니다. 당신과 내 코드 모두에서 일어나는 일들. 게시하기 전에 설명서를 읽었습니다.) – gotramaval
내 업데이트 된 답변 확인 – diegoveloper
그건 복사 - 붙여 넣기 문제였습니다. 죄송합니다. 나는 그것을 바꿨지 만, 여전히 문제를 풀지 않고있다. – gotramaval