Skip to content

Commit

Permalink
gradle plugin updated
Browse files Browse the repository at this point in the history
new permission added
  • Loading branch information
tiromansev committed Dec 15, 2022
1 parent 3a3b780 commit 0c6ac9d
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 46 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdkVersion 33
defaultConfig {
applicationId "com.tiromansev.permissionmanager.example"
minSdkVersion 14
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
Expand All @@ -19,9 +19,9 @@ android {
}

dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
implementation project(':permissionmanager')
}
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tiromansev.permissionmanager.example">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.CAMERA" />

<application
Expand All @@ -12,7 +12,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.tiromansev.permissionmanager.example;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.tiromansev.permissionmanager.PermissionsManager;

public class MainActivity extends AppCompatActivity {
Expand All @@ -16,21 +16,16 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

Button btnCheck = (Button) findViewById(R.id.btnCheck);
btnCheck.setOnClickListener(new View.OnClickListener() {
btnCheck.setOnClickListener(v -> PermissionsManager.get().checkReadImagesAccess(new PermissionsManager.PermissionCallback() {
@Override
public void onClick(View v) {
PermissionsManager.get().checkPermissions(new PermissionsManager.PermissionCallback() {
@Override
public void permissionAccepted() {
Toast.makeText(MainActivity.this, getString(R.string.message_permission_accepted), Toast.LENGTH_LONG).show();
}
public void permissionAccepted() {
Toast.makeText(MainActivity.this, getString(R.string.message_permission_accepted), Toast.LENGTH_LONG).show();
}

@Override
public void permissionRejected() {
Toast.makeText(MainActivity.this, getString(R.string.message_permission_rejected), Toast.LENGTH_LONG).show();
}
}, PermissionsManager.WRITE_EXTERNAL_REQUEST, PermissionsManager.CAMERA_REQUEST);
@Override
public void permissionRejected() {
Toast.makeText(MainActivity.this, getString(R.string.message_permission_rejected), Toast.LENGTH_LONG).show();
}
});
}));
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.android.tools.build:gradle:7.3.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
12 changes: 5 additions & 7 deletions permissionmanager/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 30
compileSdkVersion 33
defaultConfig {
minSdkVersion 14
targetSdkVersion 30
versionCode 1
versionName "1.0"
targetSdkVersion 33

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

Expand All @@ -20,8 +18,8 @@ android {
}

dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
testImplementation 'junit:junit:4.13.2'
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.7.0'
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
package com.tiromansev.permissionmanager;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import android.util.Log;

import java.util.ArrayList;

import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.Manifest.permission.ADD_VOICEMAIL;
Expand All @@ -26,6 +12,9 @@
import static android.Manifest.permission.READ_CALL_LOG;
import static android.Manifest.permission.READ_CONTACTS;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.READ_MEDIA_AUDIO;
import static android.Manifest.permission.READ_MEDIA_IMAGES;
import static android.Manifest.permission.READ_MEDIA_VIDEO;
import static android.Manifest.permission.READ_PHONE_STATE;
import static android.Manifest.permission.READ_SMS;
import static android.Manifest.permission.RECEIVE_MMS;
Expand All @@ -41,6 +30,21 @@
import static android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS;
import static android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;

import java.util.ArrayList;

public class PermissionsManager {

public final static int LOCATION_REQUEST = 100;
Expand Down Expand Up @@ -68,6 +72,9 @@ public class PermissionsManager {
public final static int RECEIVE_WAP_PUSH_REQUEST = 122;
public final static int RECEIVE_MMS_REQUEST = 123;
public final static int READ_EXTERNAL_STORAGE_REQUEST = 124;
public final static int READ_MEDIA_AUDIO_REQUEST = 125;
public final static int READ_MEDIA_IMAGES_REQUEST = 126;
public final static int READ_MEDIA_VIDEO_REQUEST = 127;

private ArrayList<String> permissionsToRequest;
private ArrayList<String> permissionsRejected;
Expand Down Expand Up @@ -295,6 +302,30 @@ public void checkReadExternalAccess(PermissionCallback permissionCallback, Strin
checkPermissions(permissionCallback, rationaleMessage, READ_EXTERNAL_STORAGE_REQUEST);
}

public void checkReadAudioAccess(PermissionCallback permissionCallback) {
checkPermissions(READ_MEDIA_AUDIO_REQUEST, permissionCallback);
}

public void checkReadAudioAccess(PermissionCallback permissionCallback, String rationaleMessage) {
checkPermissions(permissionCallback, rationaleMessage, READ_MEDIA_AUDIO_REQUEST);
}

public void checkReadVideoAccess(PermissionCallback permissionCallback) {
checkPermissions(READ_MEDIA_VIDEO_REQUEST, permissionCallback);
}

public void checkReadVideoAccess(PermissionCallback permissionCallback, String rationaleMessage) {
checkPermissions(permissionCallback, rationaleMessage, READ_MEDIA_VIDEO_REQUEST);
}

public void checkReadImagesAccess(PermissionCallback permissionCallback) {
checkPermissions(READ_MEDIA_IMAGES_REQUEST, permissionCallback);
}

public void checkReadImagesAccess(PermissionCallback permissionCallback, String rationaleMessage) {
checkPermissions(permissionCallback, rationaleMessage, READ_MEDIA_IMAGES_REQUEST);
}

private void checkPermissions(int permissionId, @NonNull PermissionCallback permissionCallback) {
checkPermissions(permissionCallback, permissionId);
}
Expand Down Expand Up @@ -462,7 +493,15 @@ public String getPermissionStr(int requestCode) {

case READ_EXTERNAL_STORAGE_REQUEST:
return READ_EXTERNAL_STORAGE;


case READ_MEDIA_IMAGES_REQUEST:
return READ_MEDIA_IMAGES;

case READ_MEDIA_VIDEO_REQUEST:
return READ_MEDIA_VIDEO;

case READ_MEDIA_AUDIO_REQUEST:
return READ_MEDIA_AUDIO;
}

return null;
Expand Down

0 comments on commit 0c6ac9d

Please sign in to comment.