![](/img/trans.png)
[英]react-native-document-picker app closes/crashes after document selection
[英]react-native-document-picker not returning anything
不知道这是因为 react native 版本还是其他原因导致了这种情况。 所以我刚刚将我的 android 应用程序与 React Native 集成并迁移到 AndroidX。 在我进行集成和迁移之前,这段代码非常好,我得到了结果和一切。 但是,在集成和迁移后,我只能从图像列表中查看并单击照片,没有结果, console.log()
不起作用,甚至我在catch
块上也没有收到任何错误
我正在使用https://github.com/Elyx0/react-native-document-picker和 React Native 0.60.5 中的 react-native-document-picker
我试过使用这个不同的库https://www.npmjs.com/package/react-native-file-picker ,但问题是一样的
try {
const res = await DocumentPicker.pick({
type: [DocumentPicker.types.images],
});
console.log(res) //not showing anything
if (res.size <= 3145728) {// 3 MB
dispatch({
type: ACTION_TYPE_PICK_PHOTO_PROFILE_SUCCESS,
payload: res,
});
} else {
dispatch({
type: ACTION_TYPE_PICK_PHOTO_PROFILE_EXCEED,
payload: res
});
}
} catch (err) {
console.log(err) //not showing anything
if (DocumentPicker.isCancel(err)) {
// User cancelled the picker, exit any dialogs or menus and move on
}
}
任何帮助都会很棒! 提前致谢。
解决了。 原来我忘了为 onActivityResult 添加函数。 这是我使用的代码。
private final int OVERLAY_PERMISSION_REQ_CODE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SoLoader.init(this,false);
mReactRootView = new RNGestureHandlerEnabledRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setCurrentActivity(this)
.setBundleAssetName("index.android.bundle")
.setJSMainModulePath("index")
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
} else {
startReactNative();
}
}
private void startReactNative() {
// The string here (e.g. "MyReactNativeApp") has to match
// the string in AppRegistry.registerComponent() in index.js
mReactRootView.startReactApplication(mReactInstanceManager, "NusaTalent", null);
setContentView(mReactRootView);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == OVERLAY_PERMISSION_REQ_CODE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this)) {
Log.e(TAG, "onActivityResult: SYSTEM_ALERT_WINDOW permission not granted");
} else {
startReactNative();
}
}
}
Log.d(TAG, "onActivityResult: " + data);
mReactInstanceManager.onActivityResult( this, requestCode, resultCode, data );
}
非常感谢@arthur-bachtiar提供的解决方案,在我的情况下,它工作所需的全部内容是:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
...
}
我真的很失望,直到今天,图书馆的维护人员还没有在存储库中澄清这个现有问题,也没有包含任何关于此过程的安装步骤的工作示例或说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.