Keselme
Keselme

Reputation: 4279

Using start activity for result in React Native module

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?

Upvotes: 0

Views: 2739

Answers (1)

Usama Shahid
Usama Shahid

Reputation: 865

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) {
    }
}

Upvotes: 0

Related Questions