Ask Permission - Simple RunTime permission manager

Overview

Ask Permission

https://kishanjvaghela.github.io/Ask-Permission/

Download Android Arsenal Stories in Ready

Simple RunTime permission manager

How to use

Add url to your gradle file

compile 'com.kishan.askpermission:askpermission:1.0.3'

If you got conflicting in support library then

compile('com.kishan.askpermission:askpermission:1.0.3', {
        exclude group: 'com.android.support'
    })

Now you can Ask for permission

new AskPermission.Builder(this)
        .setPermissions(Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE)
        .setCallback(/* PermissionCallback */)
        .setErrorCallback(/* ErrorCallback */)
        .request(/* Request Code */);

Here you have two callback

PermissionCallback

@Override
  public void onPermissionsGranted(int requestCode) {
    // your code
  }

  @Override
  public void onPermissionsDenied(int requestCode) {
    // your code
  }

ErrorCallback

Example

  @Override
  public void onShowRationalDialog(PermissionInterface permissionInterface, int requestCode) {
    // Alert user by Dialog or any other layout that you want.
    // When user press OK you must need to call below method.
    permissionInterface.onDialogShown();
  }

  @Override
  public void onShowSettings(PermissionInterface permissionInterface, int requestCode) {
    // Alert user by Dialog or any other layout that you want.
    // When user press OK you must need to call below method.
    // It will open setting screen.
    permissionInterface.onSettingsShown();
  }

This Library support Activity,Fragment and SupportFragment.

 new AskPermission.Builder(/* android.app.Activity */)
 new AskPermission.Builder(/* android.app.Fragment */)
 new AskPermission.Builder(/* android.support.v4.app.Fragment */)
Comments
  • do action after permission granted

    do action after permission granted

    after get permission and granted permission i can show Log on onPermissionsGranted method, and it doesnt work

    public class FragmentAboutUs extends Fragment implements PermissionCallback, ErrorCallback {
        ...
        private int WRITE_EXTERNAL_STORAGE = 1;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }
    
        @Override
    
        public View onCreateView(LayoutInflater inflater, final ViewGroup container,
                                 Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.fragment_about_us, container, false);
    
            ...
    
            //@formatter:off
                about_us_title        = (TextView)   view.findViewById(R.id.about_us_title);
                about_us_description  = (TextView)   view.findViewById(R.id.about_us_description);
                about_us_image        = (ImageView)  view.findViewById(R.id.about_us_image);
            //@formatter:on
    
            aboutUs = SQLite.select().from(AboutUs.class).querySingle();
            if (aboutUs == null) {
                if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    new AskPermission.Builder(this).setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                            Manifest.permission.WRITE_EXTERNAL_STORAGE)
                            .setCallback(this)
                            .setErrorCallback(this)
                            .request(WRITE_EXTERNAL_STORAGE);
                } else {
                    taskManager.addJobInBackground(new TaskGetAboutUsInformation(UUID.randomUUID().toString()));
                }
            } 
    
            return view;
        }
        ...
    
        @Override
        public void onShowRationalDialog(PermissionInterface permissionInterface, int requestCode) {
            permissionInterface.onDialogShown();
        }
    
        @Override
        public void onShowSettings(PermissionInterface permissionInterface, int requestCode) {
    
        }
    
        @Override
        public void onPermissionsGranted(int requestCode) {
            Log.e("onPermissionsGranted","");
        }
    
        @Override
        public void onPermissionsDenied(int requestCode) {
            Log.e("onPermissionsDenied","");
        }
    }
    
    opened by pishguy 9
  • My Application crash on resume

    My Application crash on resume

    when i trying to use this library, i dont have any problem on opening application on first time, but after change permission on android setting and reopen paused application i get this error:

    Caused by: java.lang.IllegalAccessException: void com.kishan.askpermission.ShadowFragment.<init>() is not accessible from java.lang.Class<android.app.Fragment>

    My code:

        public void onCreate(@Nullable Bundle savedInstanceState) {
            if (Build.VERSION.SDK_INT >= 21) {
                getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
            }
    
            super.onCreate(savedInstanceState);
    
            context = getBaseContext();
            alachiq = (Alachiq) getApplication();
            handler = new Handler();
            activity = ActivityRegister.this;
    
            /** Set connection Listener */
            setRealTimeConnectionListener(this);
    
            binding = DataBindingUtil.setContentView(this, R.layout.activity_register);
            ActivityRegisterPresenter presenter = new ActivityRegisterPresenter(this);
    
            binding.setPresenter(presenter);
            int hasPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS);
            if (hasPermission == PackageManager.PERMISSION_GRANTED) {
                attachFragmentsToRegisterUser();
            }else{
                new AskPermission.Builder(this).setPermissions(Manifest.permission.READ_CONTACTS,
                    Manifest.permission.READ_CONTACTS)
                    .setCallback(this)
                    .setErrorCallback(this)
                    .request(READ_CONTACTS);
            }
        }
    
    opened by pishguy 2
  • onPermissionsGranted called twice

    onPermissionsGranted called twice

    Hi, after requesting permision for Camera and Write External Storage, the function onPermissionsGranted is executed two times.

    public void reqPermission() {
            new AskPermission.Builder(this).setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.CAMERA)
                    .setCallback(this)
                    .setErrorCallback(this)
                    .request(REQUEST_PERMISSIONS);
        }
    
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_new_post);
            recognized = (TextView) findViewById(R.id.recognized);
            if (savedInstanceState != null) {
                imageUri = Uri.parse(savedInstanceState.getString(SAVED_INSTANCE_URI));
                recognized.setText(savedInstanceState.getString(SAVED_INSTANCE_RESULT));
            }
    
            detector = new TextRecognizer.Builder(getApplicationContext()).build();
            myBeerDetector = new MyBeerDetector(detector);
    
    //        myBeerDetector.setProcessor(/* include your processor here */);
    
            if (savedInstanceState == null)
                mCameraSource = new CameraSource.Builder(this, myBeerDetector)
                        .setAutoFocusEnabled(true)
                        .build();
    
            // Initialize de DB.
            mDatabase = FirebaseDatabase.getInstance().getReference();
    
            reqPermission();
    
        }
    
        @Override
        public void onPermissionsGranted(int requestCode) {
            if (requestCode == PHOTO_REQUEST)
                takePicture();
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (requestCode == PHOTO_REQUEST && resultCode == RESULT_OK) {
                textRecognize();
    
                new QueryWordsTask().execute(words, null, null);
            }
        }
    
        private void takePicture() {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File photo = new File(Environment.getExternalStorageDirectory(), "picture.jpg");
            imageUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", photo);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
            startActivityForResult(intent, PHOTO_REQUEST);
        }
    

    Any idea why it happens? Thanks!

    opened by alexxgarci 1
  • - Application is crash, if user deny the requested permission. This hap…

    - Application is crash, if user deny the requested permission. This hap…

    …pen second time when we try to request.

    • After investigation found that getActivity in alert dialog is returning null, that is due of eariler call of the remove fragment.
    • Before open the Alert Dialog, it wil remove the fragment from the transaction manager, then close the dialog will try to open the settings screen that could't found the fragment attached.
    • Fixed by stop calling the onRequestPermissionDenined().
    opened by Bhavdip 1
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced by 6% 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png | 10.24kb | 9.45kb | 7.73% | | /app/src/main/res/mipmap-xxhdpi/ic_launcher.png | 7.54kb | 7.04kb | 6.66% | | /app/src/main/res/mipmap-xhdpi/ic_launcher.png | 4.73kb | 4.46kb | 5.76% | | /app/src/main/res/mipmap-hdpi/ic_launcher.png | 3.34kb | 3.24kb | 2.90% | | /app/src/main/res/mipmap-mdpi/ic_launcher.png | 2.15kb | 2.10kb | 2.40% | | | | | | | Total : | 28.00kb | 26.28kb | 6.12% |


    📝docs | :octocat: repo | 🙋issues | 🏅swag | 🏪marketplace

    opened by imgbot[bot] 0
  • waffle.io Badge

    waffle.io Badge

    Merge this to receive a badge indicating the number of issues in the ready column on your waffle.io board at https://waffle.io/Kishanjvaghela/Ask-Permission

    This was requested by a real person (user Kishanjvaghela) on waffle.io, we're not trying to spam you.

    opened by waffle-iron 0
  • using Ask-Permission with Asynctask in MainActivity.java

    using Ask-Permission with Asynctask in MainActivity.java

    hello, i've been trying to use this library within Asynctask method but the app didn't show askpermission menu. is the library itself compatible with Asynctask? If so, can you give some code examples to solve this problem?

    opened by Jokurilism 0
  • Crash: v13 support libraries missing when using `exclude group: 'com.android.support'`

    Crash: v13 support libraries missing when using `exclude group: 'com.android.support'`

    https://github.com/Kishanjvaghela/Ask-Permission/blob/master/askpermission/src/main/java/com/kishan/askpermission/ShadowFragment.java#L7

    IntelliJ highlights "app" as red.

    https://github.com/Kishanjvaghela/Ask-Permission/blob/master/askpermission/src/main/java/com/kishan/askpermission/ShadowFragment.java#L52

    When running the app, when I try requesting permissions it crashes with:

    java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v13/app/ActivityCompat;


    My module-level build.gradle contains:

    android {
        defaultConfig {
        compileSdkVersion 28
            minSdkVersion 19
            targetSdkVersion 28
    ...
    dependencies {
        implementation('com.kishan.askpermission:askpermission:1.0.3', {
            exclude group: 'com.android.support'
        })
    ...
    

    I think I know what went wrong. https://github.com/Kishanjvaghela/Ask-Permission#how-to-use tells me to exclude group: 'com.android.support', but this causes the v13 support library to never get downloaded. I'm not sure how to fix the documentation to warn of this issue...


    Also it seems that https://developer.android.com/reference/android/support/v13/app/ActivityCompat is deprecated:

    This class was deprecated in API level 27.1.0. Use android.support.v4.app.ActivityCompat.

    opened by nyanpasu64 4
  • Source code spelling: Rational when you mean Rationale

    Source code spelling: Rational when you mean Rationale

    While reading the source code around https://github.com/Kishanjvaghela/Ask-Permission/blob/0b8874b33a75cdacb85a831fcf274f6eaa3df735/askpermission/src/main/java/com/kishan/askpermission/AskPermissionImp.java#L52 to understand your behavior around PackageManager.PERMISSION_GRANTED, I noticed that you misspell "rationale" as "rational", mainly in the term "showRationalDialog". These words have different meanings.

    This word was confusing for me, as I thought "RationalDialog" meant "logical dialog" (well, I had no clue what was a logical dialog) instead of "reasons for requesting".

    opened by nyanpasu64 1
  • Location not updated on permission granted

    Location not updated on permission granted

    Hello i am developing with google maps, so after requesting the location permissions, i get "permission granted" for first time, but the apps freezes doesn't make anything else. if i re open it it takes the location updates. the problem is on permission granted

    opened by juanjoserodrigolazaro 1
  • Manifest merger failed with multiple errors, see logs

    Manifest merger failed with multiple errors, see logs

    Error:Execution failed for task ':app:processDebugManifest'.

    Manifest merger failed with multiple errors, see logs although I have added like compile('com.kishan.askpermission:askpermission:1.0.3', { exclude group: 'com.android.support' })

    opened by abunayem 0
📱 objection - runtime mobile exploration

objection is a runtime mobile exploration toolkit, powered by Frida, built to help you assess the security posture of your mobile applications, without needing a jailbreak.

SensePost 5.6k Jan 5, 2023
Scoper - Access any file with zero permission required

Scoper - Access any file with zero permission required With this codebase you will able to access file from your mobile without requiring permission o

Fakhrul Alam Siddiqei 5 Oct 4, 2022
Secure Preference Manager for android. It uses various Encryption to protect your application's Shared Preferences.

Secure-Pref-Manager ##Secure Preference Manager is a simple Library to help you protect your Shared Preferences. Secure Preference Manager for android

Prashant Solanki 72 Nov 25, 2022
XClipper is a clipboard manager for Windows & Android which helps to track clipboard activities and makes it easier to interact with them.

XClipper XClipper is a clipboard manager for Windows & Android which helps to track clipboard activities and makes it easier to interact with them ❤️

Kaustubh Patange 134 Dec 31, 2022
Simple-Claim-Form - Android App for creating a simple dynamic form with MVVM architecture

Simple-Claim-Form Android App for creating a simple dynamic form with MVVM archi

Shubham Gangpuri 1 Aug 14, 2022
a simple cache for android and java

ASimpleCache ASimpleCache 是一个为android制定的 轻量级的 开源缓存框架。轻量到只有一个java文件(由十几个类精简而来)。 1、它可以缓存什么东西? 普通的字符串、JsonObject、JsonArray、Bitmap、Drawable、序列化的java对象,和 b

Michael Yang 3.7k Dec 14, 2022
✔️ Secure, simple key-value storage for Android

Hawk 2.0 Secure, simple key-value storage for android Important Note This version has no backward compatibility with Hawk 1+ versions. If you still wa

Orhan Obut 3.9k Dec 20, 2022
A simple library for validating user input in forms using annotations.

ValidationKomensky for Android A simple library for validating user input in forms using annotations. Features: Validate all views at once and show fe

Inmite s.r.o. 512 Nov 20, 2022
Create a simple and more understandable Android logs.

DebugLog Create a simple and more understandable Android logs. #Why? android.util.Log is the most usable library of the Android. But, when the app rel

mf 418 Nov 25, 2022
A small library which will save you from writing the same intent creation code again and again for the most simple tasks

Android Intents A small library which will save you from writing the same intent creation code again and again for the most simple tasks. I found myse

MarvinLabs 420 Nov 20, 2022
A simple Android utils library to write any type of data into cache files and read them later.

CacheUtilsLibrary This is a simple Android utils library to write any type of data into cache files and then read them later, using Gson to serialize

Wesley Lin 134 Nov 25, 2022
A simple and easy to use stopwatch and timer library for android

TimeIt Now with Timer support! A simple and easy to use stopwatch and timer library for android Introduction A stopwatch can be a very important widge

Yashovardhan Dhanania 35 Dec 10, 2022
A helper library to ease the most repetitive codes with simple reusable attributes.

ak-universal-android-helper A helper library to ease the most repetitive codes with simple reusable attributes. AKUAH can help you with many repetitiv

Aakash Kumar 20 Jul 8, 2020
Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platform the code is running.

Trail Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platfor

Mauricio Togneri 13 Aug 29, 2022
Expirable Disk Lru Cache is a secure(with encryption) wrapper for [DiskLruCache](https://github.com/JakeWharton/DiskLruCache) that allows expiring of key/value pairs by specifying evictionTimeSpan. It has very simple API.

ExpirableDiskLruCache ExpirableDiskLruCache is a wrapper for DiskLruCache that allows expiring of key/value pairs by specifying evictionTimeSpan. It h

Vijay Rawat 24 Oct 3, 2022
A Simple Android Library for Kenyan Counties

A Simple Android Library for Kenyan Counties

Joel Kanyi 18 Jul 12, 2022
Format numbers using a string pattern with this simple number formatted like ##-####-##

AndroidPattern Format numbers using a string pattern with this simple number formatted like ##-####-## Installation To get a Git project into your bui

Hussein Habibi Juybari 2 Oct 25, 2021
Simple project to help people track their crusade progress

Crusade-helper Simple project to help people track their crusade progress Core module Contains: model - package with all database structure service -

null 4 Nov 2, 2021
Simple Keyboard can adjustable keyboard height for more screen space

Simple Keyboard About Features: Small size (<1MB) Adjustable keyboard height for more screen space Number row Swipe space to move pointer Delete swipe

Raimondas Rimkus 681 Dec 27, 2022