Unity in AndroidManifest increased authority does not pop up when the punch card application permissions apply

When you first open a screen pop apk permission:

在Activity下添加<meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true" />。

Two in the desired location and then request permission rights:

unity side:

a using UnityEngine;
 #if UNITY_ANDROID 
AndroidJavaClass androidClass = new new AndroidJavaClass ( " com.xxx.xxx.UnityPlayerActivity " ); // get class, fill in the correct Activity 

androidClass.CallStatic ( " requestExternalStorage " ); // call the static method, requestExternalStorage this function you can take your own name, remember that it is a static function 
#endif

 

java end:

Import android.support.v4.content.PermissionChecker;
 Import android.support.v4.app.ActivityCompat;
 // As mentioned static methods, android.permission.WRITE_EXTERNAL_STORAGE is an external storage permissions, other permissions empathy can also be dynamically request 
public  static  void requestExternalStorage () {
     // check the permissions to avoid duplication of the same request permission parameters: activity, authority name 
        IF (PermissionChecker.checkSelfPermission ( the this !, "android.permission.WRITE_EXTERNAL_STORAGE") = 0 ) { 
            ActivityCompat.requestPermissions ( the this , new new String [] { "android.permission.WRITE_EXTERNAL_STORAGE"}, 100); // request permission parameters: activity, authority name, request code (different permission requirements of different request code, may set their own, such as my authority 100 the other can fill 102, 103 ...)
        }
}

 

If the players reject the authorization request permission:

// If the player refused authorization, need to apply again and explain the reasons for applying 
@Override
 public  void onRequestPermissionsResult ( int requestCode, @NonNull String [] the Permissions, @NonNull int [] grantResults) {
    Super .onRequestPermissionsResult (requestCode, the Permissions, grantResults);
  IF (! 100 = requestCode) return ; // request code we have just defined is 100
  // give a pop inform the players that privilege does not affect him  
  IF (ActivityCompat.shouldShowRequestPermissionRationale ( "the access permissions are not privacy, beg Well what you drive "," android.permission.WRITE_EXTERNAL_STORAGE " )) { 
      ( new new  Builder (b)). setMessage (string.storage_permissions_remind)
      .setPositiveButton ( " the OK ", new new OnClickListener() {
           public void onClick(DialogInterface var1, int var2) {
          //点击ok,则再次请求
          requestExternalStorage();
           }
      }).setNegativeButton("Cancel", new OnClickListener() {
          public void onClick(DialogInterface var1, int var2) {
              //点击cancel,todo
          }
      }).create().show();
  super.onRequestPermissionsResult(requestCode, permissions, grantResults); 
}

 

Guess you like

Origin www.cnblogs.com/fengxing999/p/11420124.html