Inside a fork of react-native-fs ( https://github.com/johanneslumpe/react-native-fs ), I'm attempting to add this code:
public class RNFSManager extends ReactContextBaseJavaModule {
public RNFSManager(ReactApplicationContext reactContext) {
super(reactContext);
}
@ReactMethod
public void openFile(String filepath, Callback callback) {
try {
File file = new File(filepath);
MimeTypeMap myMime = MimeTypeMap.getSingleton();
Intent newIntent = new Intent(Intent.ACTION_VIEW);
String mimeType = myMime.getMimeTypeFromExtension(fileExt(filepath).substring(1));
newIntent.setDataAndType(Uri.fromFile(file), mimeType);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
currentActivity.startActivity(newIntent);
} else {
this.getReactApplicationContext().startActivity(newIntent);
}
} catch (Exception ex) {
ex.printStackTrace();
callback.invoke(makeErrorPayload(ex));
}
}
But when I build it, I get this error:
.../android/src/main/java/com/rnfs/RNFSManager.java:138: error: cannot find symbol
Activity currentActivity = getCurrentActivity();
^
symbol: method getCurrentActivity()
1 error
I think I'm using the ReactContextBaseJavaModule in exactly the same way as this, in the core React Native repo:
https://github.com/facebook/react-native/blob/235b16d93287061a09c4624e612b5dc4f960ce47/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java
It turns out that react-native-fs has its own internal react-native dependency in its build process. So even though the whole app was building off of react native v0.25, react-native-fs was building itself off of react-native v0.12, which does not have the APIs I was trying to use. This is absolutely nuts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With