问题
I'm making an Android app with ActionScript using FlashBuilder. I need to use The WiFi permission for my app. The application works on desktop with no problems(AIR Desktop project). Now when I tried to make it for Android(Mobile Project), it showed me no errors. I enabled the permissions I needed (Network and wifi) and made the .apk file. However, when I install the .apk file on my Android 6.0.1 device(Note 5) it claims that the app asks for no permissions. I decided to ask for all the permissions from the adobe website
<android>
<manifestAdditions>
<![CDATA[
<manifest>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
]]>
</manifestAdditions>
It asks for some but not for some. The ones it doesn't ask for are the following
<manifest>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>
I tried making a new MobileProject with FlashBuilder. I left it as default(blank screen) and asked for the internet permission. It also doesn't ask for the permission. Both apps crash upon lunch immediately.
Now there's a warning on the file containing the permissions, "No grammar constraints (DTD or XML schema) detected for the document" but that actually appears on a new project before I even touch anything in it.
回答1:
Actually android has new policy to show runTime premission from the marshmallow to you need to implement premission at runtime like this in Activity
protected void checkPermissionForReadWriteStorage() {
final int writeExternalStorage = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
final int readExternalStorage = ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE);
if (writeExternalStorage == PackageManager.PERMISSION_GRANTED && readExternalStorage == PackageManager.PERMISSION_GRANTED) {
} else {
boolean requestPermissionRationale = ActivityCompat.shouldShowRequestPermissionRationale(BaseActivity.this, android.Manifest.permission.READ_EXTERNAL_STORAGE);
if (requestPermissionRationale) {
Toast.makeText(BaseActivity.this, "Please provide permission for reading images from gallery.", Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", BaseActivity.this.getPackageName(), null);
intent.setData(uri);
BaseActivity.this.startActivity(intent);
} else {
ActivityCompat.requestPermissions(BaseActivity.this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 2);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case 2:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// getLocationAndSaveInDatabaseOrEnableGPS();
}
break;
}
}
回答2:
public void verifyStoragePermissions() {
if (ContextCompat.checkSelfPermission(YourActivityName.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getBaseContext(), "Denied", Toast.LENGTH_SHORT).show();
if (ActivityCompat.shouldShowRequestPermissionRationale(YourActivityName.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
} else {
}
}else{
Toast.makeText(getBaseContext(), "Granted",Toast.LENGTH_SHORT).show();
}
}
Just change the codes below to the permission you needed to display
if (ContextCompat.checkSelfPermission(YourActivityName.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED)
来源:https://stackoverflow.com/questions/36031636/permissions-not-showing-while-installing-apk