1

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?

Keselme
  • 3,779
  • 7
  • 36
  • 68

1 Answers1

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) {
    }
}
Usama Shahid
  • 769
  • 6
  • 9
  • Correct me if I'm wrong, but I think AsyncTask is deprecated when using api 30 and above. – Keselme Jan 24 '22 at 17:21
  • Yes it is, However. I think you may consider the alternative approach.Let me share you the link https://stackoverflow.com/questions/58767733/the-asynctask-api-is-deprecated-in-android-11-what-are-the-alternatives – Usama Shahid Jan 24 '22 at 17:25