0

I have native module in my React application, I want to navigate the user to the settings

   @ReactMethod
    public void manageStoragePermission() {
        if (Build.VERSION.SDK_INT >= 30) {
            if (!Environment.isExternalStorageManager()) {
                Intent getpermission = new Intent();
                getpermission.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
                reactContext.getCurrentActivity().startActivity(getpermission);
            }
        }
    }

I want to wait for the result when the user returns after granting/not granting permissions. So I tried to start the activity with startActivityForResult(), but I don't have onActivtyResult() callback in my module. I also saw that startActivityForResult() is deprecated and I should use registerForActivityResult instead, but I also don't have this method in React's native module. What is the correct way to wait for the activity result when dealing with native modules?

1

1 Answer 1

0

I think you need to use AsyncTask to handle the request.

public abstract class AsyncTask<Params, Progress, Result> {
    @WorkerThread
    protected abstract Result doInBackground(Params... params);
    @MainThread
    protected void onPreExecute() {
    }
    @SuppressWarnings({"UnusedDeclaration"})
    @MainThread
    protected void onPostExecute(Result result) {
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Correct me if I'm wrong, but I think AsyncTask is deprecated when using api 30 and above.
Yes it is, However. I think you may consider the alternative approach.Let me share you the link stackoverflow.com/questions/58767733/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.