Permissions.askAsync not resolving on Android standalone app

#1

Hi,

I have a problem where Permissions.askAsync(...) is not resolving for my standalone Android app (note: its a detached ExpoKit app). I have implemented PermissionAwareActivity methods inside MainActivity.java but for some reason it does not resolve and just waits forever.

MainActivity.java:

package host.exp.exponent;

import android.os.Bundle;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.annotation.Nullable;

import com.facebook.react.ReactPackage;
import com.facebook.react.modules.core.PermissionAwareActivity;
import com.facebook.react.modules.core.PermissionListener;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import host.exp.exponent.generated.DetachBuildConstants;
import host.exp.exponent.experience.DetachActivity;

import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import io.fabric.sdk.android.Fabric;

public class MainActivity extends DetachActivity implements PermissionAwareActivity {

  @Nullable private PermissionListener mPermissionListener;

  @Override
  public String publishedUrl() {
    return "exp://exp.host/@flyreel/flyreel";
  }

  @Override
  public String developmentUrl() {
    return DetachBuildConstants.DEVELOPMENT_URL;
  }

  @Override
  public List<String> sdkVersions() {
    return new ArrayList<>(Arrays.asList("26.0.0"));
  }

  @Override
  public List<ReactPackage> reactPackages() {
    return ((MainApplication) getApplication()).getPackages();
  }

  @Override
  public boolean isDebug() {
    return BuildConfig.DEBUG;
  }

  @Override
  public Bundle initialProps(Bundle expBundle) {
    // Add extra initialProps here
    return expBundle;
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics(), new Answers());
  }

  // Allow using PermissionsAndroid in react-native-background-location library
  // Didn't work with Expo. See https://github.com/expo/expo/issues/784
  // Copied solution from https://github.com/wix/react-native-navigation/pull/470/files
  @TargetApi(Build.VERSION_CODES.M)
  public void requestPermissions(String[] permissions, int requestCode, PermissionListener listener) {
    mPermissionListener = listener;
    requestPermissions(permissions, requestCode);
  }

  public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
      if (mPermissionListener != null && mPermissionListener.onRequestPermissionsResult(requestCode, permissions, grantResults)) {
          mPermissionListener = null;
      }
  }
}

My JS:

console.log("test1");
 const camera = await Permissions.askAsync(Permissions.CAMERA);
console.log("test2");
const audio = await Permissions.askAsync(Permissions.AUDIO_RECORDING);
console.log("test3");

It never gets to console.log("test2"). And what is also interesting is that requestPermissions never gets called in MainActivity.java.

#2

Hi @darkwata - could you explain what you’re trying to achieve by implementing PermissionAwareActivity inside of your MainActivity.java? If you take that out, do the calls to await Permissions.askAsync(...) still hang?

#3

Hi @esamelson based on the following Github issue you need to implment PermissionAwareActivity: https://github.com/expo/expo/issues/784

#4

Hi @darkwata - that issue is quite old and likely outdated. Expo does permissions differently from vanilla react native and does not use PermissionAwareActivity. Could you explain what happens if you remove all references to PermissionAwareActivity in MainActivity.java and try calling await Permissions.askAsync(...) then?

closed #5

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.