Linking.getInitialUrl() returns null when opening the app from a local notification from react-native-push-notifications - react-native

I have implemented react-native-push-notification to show localNotification from a RemoteMessage that I receive from FCM. I receive the notification but on tapping the notification, Linking.getInitialUrl() returns null. I also have react-native-bootsplash integrated for a splash screen. All the integration is as shown below.
AndroidManifest.xml
...
<activity android:name=".MainActivity" android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:exported="true" android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
<activity android:name="com.zoontek.rnbootsplash.RNBootSplashActivity"
android:theme="#style/BootTheme" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
...
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RNBootSplash.init(R.drawable.bootsplash, MainActivity.this);
}
It seems that the data associated with the notification intent is not being sent to the Activity. So I am not able to find as to how I send the data.

Related

You uploaded an APK or You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver withintentfilter

I'm having an issue when i'm uploading app bundle to the play console that You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without 'android:exported' property set. This file can't be installed on Android 12 or higher. but my manifest file includes the property android:exported="true". i.stack.imgur.com/Ux97W.png
here is my manifest file.
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
tools:replace="android:allowBackup"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="#style/AppTheme"
android:resizeableActivity="false">
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="af8c-110-235-232-163.ngrok.io"
android:scheme="https"/>
</intent-filter>
</activity>
<activity
android:exported="true"
android:name="com.zoontek.rnbootsplash.RNBootSplashActivity"
android:theme="#style/SplashTheme"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:exported="true" android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
android:value="false"/>
<receiver android:exported="true" android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
<receiver android:exported="true" android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:exported="true" android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:exported="true" android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
</application>

React Native Android launchMode singleTask getLaunchOptions doesn't get called again

I am developing a react-native app for Android. The app takes image sharing with this intent-filter on the main activity
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
I am able to get the initial sharing intent images by overriding getLaunchOptions(), but with this default launchMode="singleTask", I am not able to get new sharing intent when I have the existing instance of the app running.
So, how can I get the new sharing intent while have an instance of the app running?
PS: changing the launchMode to standard to standard kind of solved my problem, but that will create multiple instances of the app.
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I have the same problem. If the launchMode isn't in AndroidManifest.xml the situation is like standart.
I've found a solution for my case (receiving intents for .txt files)
In AndroidManifest.xml
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
...
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
In MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
onNewIntent(this.getIntent());
}
#Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// here are received intents
}
In such way I receive intents when app in background or it is not run at all and only ONE instance of the app.
I'm using React Native 0.61 and was having the exact same problem.
I've used the react-native-share-menu lib to make it work.
Alternatively, If you don't want to add a new lib to your project, it might be worth taking a look at how they did it for Android and modify your code accordingly:
https://github.com/meedan/react-native-share-menu/tree/master/android/src/main

problem with RTL layout in react native project only when i release apk

i am building an app that need to support only rtl layout no matter what is the phone language.
my problem is when i am in debug mode its work just fine and show the layout rtl as i wanted regardless the phone language but after i release the app it show the the layout direction as the phone language.
can anyone tell me what it may be ?
i tried the following solution:
add this line in the constructor of the main page
I18nManager.allowRTL(true);
I18nManager.forceRTL(true);
also add this line in android manifest:
android:supportsRtl="true"
both in activity tag and also in application tag
manifest :
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true"
android:supportsRtl="true"
>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:supportsRtl="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
constructor in App.js
constructor(){
super();
I18nManager.allowRTL(true);
I18nManager.forceRTL(true);
}
this is the good result
https://i.imgur.com/S2nV0a4.jpg
this one is not what i want
https://i.imgur.com/VXzYWI1.png
Add these three lines in your MainActivity.java
+ import com.facebook.react.modules.i18nmanager.I18nUtil;
#Override
public void onCreate() {
super.onCreate();
// FORCE RTL
+ I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
+ sharedI18nUtilInstance.allowRTL(getApplicationContext(), true);
....
}

onNotificationOpened and getInitialNotification not getting triggered react-native-firebase

I have used react-native-firebase in my react native project[android platform] to show the app notification. With this library i am able to show the notification when the app is in the foreground/background/closed state.
According to the react native firebase documentation the onNotificationOpened should be triggered when the app is opened by the notification tap. However this is not happening in my case, the onNotificationOpened method is never called and getInitialNotification method always gets a null value.
I am also using react-native-splash-screen library to display the splashscreen.
Here's my code from App.js >> componentDidMount()
firebase.messaging().requestPermission()
.then(() => {
const myAppChannel = new firebase.notifications.Android.Channel('my-channel',
'my Channel', firebase.notifications.Android.Importance.Max)
.setDescription('my channel');
firebase.notifications().android.createChannel(myAppChannel);
this.messageListener = firebase.messaging().onMessage((message) => {
const {title, body} = message.data;
const notificationDisplay = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle(title)
.setBody(body)
.setData({
key1: 'value1',
key2: 'value2',
}).setSubtitle('notification')
.setSound('default');
notificationDisplay
.android.setChannelId('my-channel')
.android.setSmallIcon('ic_launcher')
.android.setAutoCancel(true).android.setPriority(firebase.notifications.Android.Priority.High);
firebase.notifications().displayNotification(notificationDisplay);
});
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) => {
//never gets called
console.log('onNotificationOpened was triggered on notification taped');
});
})
.catch(error => {
// User has rejected permissions
console.log("user rejected");
console.log(error);
});
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name=".MainApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="#string/default_notification_channel_id" />
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:launchMode="singleTop"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:exported="true"
android:label="#string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize" />
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
UPDATE: Problem was caused by the react-native-splash-screen library, I was able to fix this after removing the react-native-splash-screen library from the android project. However i am still not sure how i can make this work when using the react-native-splash-screen.
Adding intent-filter to MainActivity and click-action to notification JSON did the trick for me.
<intent-filter>
<action android:name=".MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Notification JSON
{
"to":"ID",
"notification" : {
**"click_action" : ".MainActivity",**
"body": "Message Body",
"title" : "Call Status",
"sound": "default",
"badge":"5"
},
"data": {
"type": 1,
"body": "Message Body",
"title" : "Call Status"
}
}
My manifest.xml looks like this
<application
tools:replace="android:allowBackup"
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="false"
android:theme="#style/AppTheme">
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<activity
android:name=".SplashActivity"
android:theme="#style/SplashTheme"
android:launchMode="singleTop"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTop"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name=".MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
Hope this helps

Splash screen on Android

I have a problem with the splashscreen on Android. Here is everything what I am doing:
Creating background_splash.xml file:
xml version="1.0" encoding="utf-8"?>
layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#android:color/darker_gray"/>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/splash"/>
</item>
I remove < in the first two lines because stackoverflow cannot display them. This file is located in drawable.
I added the following to styles.xml:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
and this is my manifest files:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />
<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:theme="#style/AppTheme">
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
And also the activity:
import android.content.Intent;
import android.os.Bundle;
import com.facebook.react.ReactActivity;
public class SplashActivity extends ReactActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
This is the error I have:
Starting the app on 51d123cc (adb -s 51d123cc shell am start -n com.test/.MainActivity)...
Starting: Intent { cmp=com.test/.MainActivity }
java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10000000 cmp=com.test/.MainActivity } from null (pid=20601, uid=2000) not exported from uid 11152
at android.os.Parcel.readException(Parcel.java:1540)
at android.os.Parcel.readException(Parcel.java:1493)
at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:2589)
at com.android.commands.am.Am.runStart(Am.java:768)
at com.android.commands.am.Am.onRun(Am.java:307)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.am.Am.main(Am.java:102)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:255)
UPDATE:
To the answer of #Ankit Prajapati I will add also that I set
android:largeHeap="true"
which was an error from Android Studio (running from the terminal this error wasn't reported) and this happen after changing activity to SplashActivity.
Also it was necessary to change edit configurations and changing "Launch Activity" to "Specified Activity" and setting com.test.SplashActivity.
Second way of managing splash screen on Android and which I use right now is with this tutorial:
Splash Screen Android
Try using this in
android:exported="true" in the manifest file in the activity you are trying to start (Loading Activity)
Like this
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:theme="#style/SplashTheme"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Also Add
Intent intent = new Intent(SplashActivity.this, MainActivity.class);