How to go back to react native activity from android native modules - react-native

I implemented android native bridge module in which I call native like below, and I don't know how to navigate back to react native
#ReactMethod public void createMerchantEvent(){ Intent intent = new Intent(getReactApplicationContext(),LoadingActivity.class); getCurrentActivity().startActivity(intent); }

Related

PermissionsAndroid for iOS in React Native

I use this code to get user permission in android
async componentWillMount() {
await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION);
}
How to use this for ios?
This library used only with android , Use Third party library Like :
https://github.com/yonahforst/react-native-permissions

Why Android App showing blank screen when coming out of an App with back button React Native Navigation?

I am working on React Native Application and integrated react-native-navigation package for navigation inside app, link of package
Android App got stuck and show blank screen. This happens if I am closing app using back button in case of Android app. At the end I have a listing screen, after reopen the application it shows blank screen because it's not calling Navigation.registerComponent again, it might be destroying app when closed using back button.
This is a code inside my index.js::
import { Navigation } from "react-native-navigation";
import App from './src/app';
Navigation.registerComponent("appName", () => App);
Killing the app and restarting would fix the stuck on splash screen issue. But shouldn't be stuck in the first place. Just an issue when closing through back button.
Does anyone have a fix for this? Please suggest how can I handle and call my Navigation.registerComponent once again after closing app using back button.
Environment
React Native Navigation version: 2.12.0
React Native version: 0.58
Platform(s) : Android only
To resolve this you need to make modification inside react-native-navigation package. Open NavigationActivity.java file and replace below code with new one:
Replace this code:
#Override
public void invokeDefaultOnBackPressed() {
if (!navigator.handleBack(new CommandListenerAdapter())) {
super.onBackPressed();
}
}
With this one:
#Override
public void invokeDefaultOnBackPressed() {
if (!navigator.handleBack(new CommandListenerAdapter())) {
this.moveTaskToBack(true);
//super.onBackPressed();
}
}
After saving your changes check on android device.

Passing data to react-native from native with proguard

Without proguard=true following is WritableMap which is passed to React native.
{isDone:true}
And I enable obfuscation
{a:true}
I want pro guard not to touch this class. What to add in proguard file?
Add following to proguard-rules.pro:
-keep, includedescriptorclasses public class packagename.model.** {*; }

React Native Headless js, Module AppRegistry is not a registered(calling startHeadlessTask)

I am having react native background service issue - Headless JS
I am using Expo framework
Android Studio Error MSG:
E/ReactNativeJS: The Expo SDK requires Expo to run. It appears the native Expo modules are unavailable and this code is not running on Expo. Visit https://docs.expo.io to learn more about developing an Expo project.
E/unknown:ReactNative: Unable to launch redbox because react activity is not available, here is the error that redbox would've displayed: The Expo SDK requires Expo to run. It appears the native Expo modules are unavailable and this code is not running on Expo. Visit https://docs.expo.io to learn more about developing an Expo project.
E/ReactNativeJS: Module AppRegistry is not a registered callable module (calling startHeadlessTask)
E/unknown:ReactNative: Unable to launch redbox because react activity is not available, here is the error that redbox would've displayed: Module AppRegistry is not a registered callable module (calling startHeadlessTask)
The JS API:(App.js)
const LockScreenOpenService = async (taskData) => {
DeviceEventEmitter.addListener('LockScreenOpen', function(e: Event) {
// handle event.
console.log("== Debug: Received LockScreen View Open");
});
};
AppRegistry.registerHeadlessTask('LockScreenOpenService', () =>
LockScreenOpenService);
LockScreenOpenService.java:
public class LockScreenOpenService extends HeadlessJsTaskService {
#Override
protected #Nullable
HeadlessJsTaskConfig getTaskConfig(Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
return new HeadlessJsTaskConfig(
"LockScreenOpenService",
Arguments.fromBundle(extras),
5000, // timeout for the task
false // optional: defines whether or not the task is allowed in foreground. Default is false
);
}
return null;
}
}
Service Start:
public void startLockViewService(){
Intent listenIntent = new Intent(getApplication(), LockScreenOpenService.class);
Bundle bundle = new Bundle();
listenIntent.putExtras(bundle);
startService(listenIntent);
}
AndroidManifest.xml
<service
android:name=".lockscreen.LockScreenOpenService"
android:enabled="true"
android:exported="true" />
I have no idea why 'Module AppRegistry is not a registered callable module (calling startHeadlessTask)' occured!?

Linking with android os settings in react native

I'm trying to link with android os settings page.
Going to Phone Dail with Linking is work.
Linking.openURL('tel: +959 XXXXXXXX');
Can I use Linking to link with android os settings page like android location settings page?
Linking.openURL can only open correctly formatted urls. There are no standardized urls for the android settings. You would have to write some native code to do this, and then build a React Native Module to trigger it.
Here is some example Android code:
public void openWifiSettings() {
Intent intent = new Intent(Intent.ACTION_WIFI_SETTINGS);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}