一、java.lang.IllegalStateException:You need to use a Theme.AppCompat theme (or descendant) with this activity
代码示例:
public class MyIntentModule extends ReactContextBaseJavaModule {
private static final String TAG = "MyIntentModule";
ReactApplicationContext mCallerContext;
public MyIntentModule(ReactApplicationContext reactContext) {
super(reactContext);
mCallerContext = reactContext;
}
@Override
public String getName() {
return "RCTMap";
}
@ReactMethod
public void getLocation(ReadableMap readableMap, Promise promise) {
// 申请定位权限
try {
AndPermission.with(getCurrentActivity()) // 此处如果传入mCallerContext会报错
.runtime()
.permission(
Permission.ACCESS_COARSE_LOCATION,
Permission.ACCESS_FINE_LOCATION
)
.onGranted(data -> {
})
.onDenied(data -> {
})
.start();
} catch (Exception e) {
Log.e(TAG, "getLocation: "+e );
}
}
}
原因:传入的上下文有问题,例如在申请权限、获取定位,不能传ReactApplicationContext
解决:传getCurrentActivity()