一、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) {
// 申請(qǐng)定位權(quán)限
try {
AndPermission.with(getCurrentActivity()) // 此處如果傳入mCallerContext會(huì)報(bào)錯(cuò)
.runtime()
.permission(
Permission.ACCESS_COARSE_LOCATION,
Permission.ACCESS_FINE_LOCATION
)
.onGranted(data -> {
})
.onDenied(data -> {
})
.start();
} catch (Exception e) {
Log.e(TAG, "getLocation: "+e );
}
}
}
原因:傳入的上下文有問題笨篷,例如在申請(qǐng)權(quán)限醉箕、獲取定位爬虱,不能傳ReactApplicationContext
解決:傳getCurrentActivity()