Android开源:AndroidPermissionX-运行时权限库
laxlee
8年前
<h2>AndroidPermissionX</h2> <p>Setup</p> <p>in your application's build.gradle</p> <pre> <code class="language-java">allprojects { repositories { ... maven { url 'https://jitpack.io' } } }</code></pre> <p>in your app's build.gradle</p> <pre> <code class="language-java">dependencies { compile 'com.github.fccaikai:AndroidPermissionX:0.1.0' }</code></pre> <h3>Usage</h3> <p>create a PermissionCompat.Builder instance</p> <pre> <code class="language-java">PermissionCompat.Builder builder = new PermissionCompat.Builder(Context);</code></pre> <p>add Permissions Array</p> <pre> <code class="language-java">builder.addPermissions(new String[]{Manifest.permission.CAMERA});</code></pre> <p>to show Rationale Dialog when shouldShowRequestPermissionRationale() retuen true , to explain why need the permission</p> <pre> <code class="language-java">builder.addPermissionRationale("say why need the permission");</code></pre> <p>add <a href="/misc/goto?guid=4959737819794885107" rel="nofollow,noindex">OnRequestPermissionsCallBack</a> ,like:</p> <pre> <code class="language-java">builder.addRequestPermissionsCallBack(new OnRequestPermissionsCallBack() { @Override public void onResult(String[] permissions, int[] grantResults) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.d(TAG, "success"); //do something } else { Log.d(TAG, "falied"); } } @Override public void onAuthorized() { Log.d(TAG, "Authorized"); //do something } })</code></pre> <p>request permission</p> <pre> <code class="language-java">builder.build().request();</code></pre> <p> </p> <p> </p>