When developing Android apps these days, we often suffer from Android Runtime Permission. Runtime by just adding one line </ font> to the correspondence of Runtime Permission I have created a library that can handle Permission. https://github.com/TakuKobayashi/RuntimePermissionChecker If you like, I'd like to receive "stars" and "likes", or "share" and spread it. M (_ _) m
build.gradle (see image below)
Added the following contents to the dependencies of
build.gradle
dependencies {
implementation 'net.taptappun.taku.kobayashi:runtimepermissionchecker:1.1.1'
}
This will introduce the library to your Android project.
Once the library is installed, add it to your Activity as shown in the example below.
MainActivity.java
public class MainActivity extends Activity {
private static final int REQUEST_CODE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
RuntimePermissionChecker.requestAllPermissions(this, REQUEST_CODE);
}
}
this
RuntimePermissionChecker.requestAllPermissions(Activity activity, int requestCode);
After that, the process of checking Android Permission is automatically executed by adding to any place. * Since the dialog for confirming Android Permission will only appear, please do not forget to add the Permission setting to AndroidManifest.xml as shown below. </ Font> >
AndroidManifest.xml
<uses-permission android:name="Permission name" />
MainActivity.java
public class MainActivity extends Activity {
private static final int REQUEST_CODE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
RuntimePermissionChecker.requestPermission(this, REQUEST_CODE, Manifest.permission.CAMERA);
}
}
this
RuntimePermissionChecker.requestPermission(Activity activity, int requestCode, String requestPermission);
By adding to any place, the process of confirming the specified Permission is executed by specifying the Permission name you want to hear individually in the above third argument (String requestPermission). (In the above case, the camera permission confirmation screen will be displayed.)
In that case, [onRequestPermissionsResult](https://developer.android.com/reference/android/app/Activity.html#onRequestPermissionsResult(int, java.lang.String [], int [])) as shown in the following example. Makes the process execute when the callback of is called.
MainActivity.java
public class MainActivity extends Activity {
private static final int REQUEST_CODE = 1;
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if (requestCode != REQUEST_CODE)
return;
if(!RuntimePermissionChecker.existConfirmPermissions(this)){
// write features you want to execute.
}
}
}
this
RuntimePermissionChecker.existConfirmPermissions(Activity activity);
Will be ture </ font> if there are still permissions to listen to.
If you want to check whether individual Permission is permitted instead of when all Permission is permitted above
RuntimePermissionChecker.hasSelfPermission(Activity activity, String requestPermission);
You can check using this method. Permission name that you want to check individually in the second argument of this method If you specify and it is already allowed, it will be ture </ font>.
The above processing also includes the correspondence in this case.
The above processing also includes the correspondence in this case.
Starting with Android 6.0 Marshmallow (API Level 23), you need to ask for a user's permission to use a specific feature when running the app, and you can't use the feature without that user's permission. .. (Storing information on a camera, microphone, SD card, etc.) In short, it's a dialog like this. Of course, in order to display this dialog, it is necessary to write the process on the application side. See here for more details
As a person who develops many Android apps and has been developing Android apps since the time of Android 2 series, I do not want to think about implementing this Runtime Permission, so as a maximum concession, I managed to add only one line. I wanted to. Therefore, no matter what app you make
So I tried to make it something that would solve everything.
Postscript 2017/12/13 (Wed) I was able to register for Bintray. I was also able to register with jcenter, so I updated the library installation method.
Recommended Posts