美文网首页
react native android 8.0 兼容apk自动

react native android 8.0 兼容apk自动

作者: Mylovesunshine | 来源:发表于2019-12-25 19:51 被阅读0次

    https://www.jianshu.com/p/86da2f4a2e21
    主要是onActivityResult回调如何写

    public class ImagePickerModule extends ReactContextBaseJavaModule implements ActivityEventListener {
        public ImagePickerModule(ReactApplicationContext reactContext) {
            super(reactContext);
            reactContext.addActivityEventListener(this);
        }
    }
    现在我们可以获取到相册返回的数据了。
    
    @Override
    public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
        if (pickerSuccessCallback != null) {
            if (resultCode == Activity.RESULT_CANCELED) {
                pickerCancelCallback.invoke("ImagePicker was cancelled");
            } else if (resultCode == Activity.RESULT_OK) {
                Uri uri = intent.getData();
    
                if (uri == null) {
                    pickerCancelCallback.invoke("No image data found");
                } else {
                    try {
                        pickerSuccessCallback.invoke(uri);
                    } catch (Exception e) {
                        pickerCancelCallback.invoke("No image data found");
                    }
                }
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:react native android 8.0 兼容apk自动

          本文链接:https://www.haomeiwen.com/subject/plvbyctx.html