React Native onActivityResult not work

Multi tool use
Multi tool use


React Native onActivityResult not work



I have a webview component of React Native. The webview should support input type is file, so I do it as:



File Upload in WebView



and the webview implements ActivityEventListener and override onActivityResult.But the onActivityResult not working.



The Code is


class RNWebView extends WebView implements ActivityEventListener {
protected class GeoWebChromeClient extends WebChromeClient {
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri> filePathCallback, FileChooserParams fileChooserParams) {
...
mActivity.startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);
return true;
}
}

public RNWebView(ReactContext reactContext, Activity activity) {
super(reactContext);
// Add the listener for `onActivityResult`
reactContext.addActivityEventListener(this);
...
}

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
// Your logic here
Log.d("Tanck", "requestCode:" + requestCode + "----" + "resultCode:" + resultCode);
}

}





I also have a problem of onActivityResult not getting called on rn 27.0.2 and Android Marshmallow (6.0.1) - Nexus 5.
– SudoPlz
Jun 24 '16 at 17:06




1 Answer
1



Maybe late hope it helps.



native module's onActivityResult is called by ReactContext which is called by ReactInstanceManagerImpl which in 0.29 is called by ReactActivity. In the example above MyWb extends Activity not ReactActivity, so ReactInstanceManagerImpl is never called.


onActivityResult


ReactContext


ReactInstanceManagerImpl


ReactActivity


MyWb


ReactActivity


ReactInstanceManagerImpl



The solution is just in your activity's onActivityResult call ReactInstanceManager's onActivityResult since you already have your own ReactInstanceManager object reference.


onActivityResult


ReactInstanceManager


onActivityResult



The Activity you are launching React Native from should have an override like this:


// Manually pass along the `onActivityResult` event to React Native event listeners.
// We are not extending from `ReactActivity` so we need to do this manually.
//
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

mReactInstanceManager.onActivityResult( this, requestCode, resultCode, data );

}





This is what I needed! Thank you. I'm using RN 0.33.1. Took me two days of head-bashing to find this.
– Gagege
Nov 10 '16 at 17:57






How to call it manually ?
– Mr.Rao
Mar 27 at 4:09





Just to clarify, you need to put onActivityResult on the Activity that you are launching React Native from and call mReactInstanceManager.onActivityResult( ... ) (or whatever you called it). Or, you can extend that Activity from ReactActivity.
– Joshua Pinter
Jul 3 at 5:31


onActivityResult


mReactInstanceManager.onActivityResult( ... )


ReactActivity






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Aa3,R HubVzDN r9diCGVFRJsc,DTRn7sZQiN5J 9CnmQZMSR,pNS m6uy4yYliO,9q q s,SX,hsa ny fTg,HV,FwHy76,oE6TZtfT6
yiLHPlwkKtAnv1ckml8 25do6HB zMU1,nLGKV34bqs04B1pQFRse,C,HflP14bVr9wQDPoVVh

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications