Skip to content

Commit

Permalink
Merge pull request #18 from guolindev/master
Browse files Browse the repository at this point in the history
Fix bug guolindev#51
  • Loading branch information
fengjixuchui committed Sep 26, 2021
2 parents 8bc661d + b965c2d commit fde7896
Show file tree
Hide file tree
Showing 108 changed files with 1,979 additions and 4,545 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ fastlane/screenshots
fastlane/test_output
fastlane/readme.md

releaseToBintray.txt
releaseToBintray.txt

gradle.properties
25 changes: 9 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ PermissionX is an extension Android library that makes Android runtime permissio
Edit your build.gradle file and add below dependency.

```groovy
repositories {
google()
mavenCentral()
}
dependencies {
implementation 'com.permissionx.guolindev:permissionx:1.4.0'
implementation 'com.guolindev.permissionx:permissionx:1.5.1'
}
```

Expand Down Expand Up @@ -47,7 +52,7 @@ PermissionX.init(activity)
}
```

Pass any instance of FragmentActivity into **init** method, and specify the permissions that you want to request in the **permissions** method, then call **request** method for actual request.
Pass any instance of FragmentActivity or Fragment into **init** method, and specify the permissions that you want to request in the **permissions** method, then call **request** method for actual request.

The request result will be callback in the request lambda. **allGranted** means if all permissions that you requested are granted by user, maybe true or false. **grantedList** holds all granted permissions and **deniedList** holds all denied permissions.

Expand Down Expand Up @@ -104,7 +109,7 @@ PermissionX.init(activity)
}
```

The parameters in **showRequestReasonDialog** method are similar with **showRequestReasonDialog** method. When user click positive button, PermissionX will forward to the settings page of your app and user can turn on the necessary permissions very quickly. When user switch back to app, PermissionX will request the necessary permissions again automatically.
The parameters in **onForwardToSettings** method are similar with **showRequestReasonDialog** method. When user click positive button, PermissionX will forward to the settings page of your app and user can turn on the necessary permissions very quickly. When user switch back to app, PermissionX will request the necessary permissions again automatically.

<img src="screenshots/3.gif" width="32%" />

Expand All @@ -131,22 +136,10 @@ The rationale dialog provided by PermissionsX support Android dark theme automat

<img src="screenshots/5.gif" width="32%" />

## Permission-Support

If your app is still not ready for AndroidX, you need to use Permission-Support library instead. The API of Permission-Support library is completely same as PermissionX, except declare another dependency in your build.gradle file.

```groovy
dependencies {
implementation 'com.permissionx.guolindev:permission-support:1.4.0'
}
```

This library won't be long term supported, and could be deprecated at any time. So try to switch to AndroidX as soon as you can.

## License

```
Copyright (C) guolin, PermissionX Open Source Project
Copyright (C) guolin, PermissionX Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
applicationId "com.permissionx.app"
minSdkVersion 15
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -28,11 +28,11 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation project(':permissionx')
}
34 changes: 22 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.permissionx.app">

<uses-permission android:name="android.permission.INTERNET" />
Expand Down Expand Up @@ -31,6 +32,15 @@
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

<application
android:allowBackup="true"
Expand All @@ -39,20 +49,20 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainJavaActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- <activity android:name=".MainJavaActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- <activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>-->
<activity android:name=".MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>-->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
58 changes: 18 additions & 40 deletions app/src/main/java/com/permissionx/app/MainJavaActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@

import android.Manifest;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.permissionx.app.databinding.ActivityMainJavaBinding;
import com.permissionx.guolindev.PermissionX;
import com.permissionx.guolindev.callback.ExplainReasonCallbackWithBeforeParam;
import com.permissionx.guolindev.callback.ForwardToSettingsCallback;
import com.permissionx.guolindev.callback.RequestCallback;
import com.permissionx.guolindev.request.ExplainScope;
import com.permissionx.guolindev.request.ForwardScope;

import java.util.List;

public class MainJavaActivity extends AppCompatActivity {

Expand All @@ -24,37 +16,23 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityMainJavaBinding binding = ActivityMainJavaBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
binding.makeRequestBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PermissionX.init(MainJavaActivity.this)
.permissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.explainReasonBeforeRequest()
.onExplainRequestReason(new ExplainReasonCallbackWithBeforeParam() {
@Override
public void onExplainReason(ExplainScope scope, List<String> deniedList, boolean beforeRequest) {
// CustomDialog customDialog = new CustomDialog(MainJavaActivity.this, "PermissionX needs following permissions to continue", deniedList);
// scope.showRequestReasonDialog(customDialog);
scope.showRequestReasonDialog(deniedList, "PermissionX needs following permissions to continue", "Allow");
}
})
.onForwardToSettings(new ForwardToSettingsCallback() {
@Override
public void onForwardToSettings(ForwardScope scope, List<String> deniedList) {
scope.showForwardToSettingsDialog(deniedList, "Please allow following permissions in settings", "Allow");
}
})
.request(new RequestCallback() {
@Override
public void onResult(boolean allGranted, List<String> grantedList, List<String> deniedList) {
if (allGranted) {
Toast.makeText(MainJavaActivity.this, "All permissions are granted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainJavaActivity.this, "The following permissions are denied:" + deniedList, Toast.LENGTH_SHORT).show();
}
}
});
}
});
binding.makeRequestBtn.setOnClickListener(view -> PermissionX.init(MainJavaActivity.this)
.permissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.explainReasonBeforeRequest()
.onExplainRequestReason((scope, deniedList, beforeRequest) -> {
// CustomDialog customDialog = new CustomDialog(MainJavaActivity.this, "PermissionX needs following permissions to continue", deniedList);
// scope.showRequestReasonDialog(customDialog);
scope.showRequestReasonDialog(deniedList, "PermissionX needs following permissions to continue", "Allow");
})
.onForwardToSettings((scope, deniedList) -> {
scope.showForwardToSettingsDialog(deniedList, "Please allow following permissions in settings", "Allow");
})
.request((allGranted, grantedList, deniedList) -> {
if (allGranted) {
Toast.makeText(MainJavaActivity.this, "All permissions are granted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainJavaActivity.this, "The following permissions are denied:" + deniedList, Toast.LENGTH_SHORT).show();
}
}));
}
}
1 change: 0 additions & 1 deletion appsupport/.gitignore

This file was deleted.

34 changes: 0 additions & 34 deletions appsupport/build.gradle

This file was deleted.

3 changes: 0 additions & 3 deletions appsupport/gradle.properties

This file was deleted.

21 changes: 0 additions & 21 deletions appsupport/proguard-rules.pro

This file was deleted.

59 changes: 0 additions & 59 deletions appsupport/src/main/AndroidManifest.xml

This file was deleted.

This file was deleted.

Loading

0 comments on commit fde7896

Please sign in to comment.