How can I determine the route of the application through deep linking based on the link - react-native

This is my code
‍App.js‍ :
function App() {
const getInitialURL = async () => {
const url = await Linking.getInitialURL();
console.log('This is url',url)
if (url !== null) {
return url;
}
return undefined
}
const deepLinking = {
prefixes: ['https://www.example.com','https://*.example.com','http://www.example.com','app://'],
config: {
initialRouteName:'HOME',
screens: {
HOME: 'home',
LIVE: 'live/:uuid',
TAGList: 'tag/:enVal'
}
},
getInitialURL
}
return (
<NavigationContainer linking={deepLinking}>
<stack.Navigator
initialRouteName={'SPLASH'}
screenOptions={{headerShown: false}}>
<stack.Screen name = "SPLASH" component={Splash}/>
<stack.Screen name = 'HOME' component = {Home}/>
<stack.Screen name = "LIVE" component={LiveOne}/>
<stack.Screen name = "TAGList" component={TagList}/>
</stack.Navigator>
</NavigationContainer>
);
}
export default App;
android/app/AndroidManifest.xml
<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:scheme="app" />
<data android:scheme="https" android:host="www.example.com" />
<data android:scheme="http" android:host="www.example.com" />
<data android:scheme="https" android:host="example.com" />
<data android:scheme="http" android:host="example.com" />
</intent-filter>
So, with this code, when I click on the link started by example.com, the app opens HOME screen, but I need for example, when the example.com is clicked, the HOME screen opens, and when the example.com/m/uuid is clicked, the app opens and change the screen to the LIVE screen and send the uuid to the same screen
For now, I can only open LIVE screen app with same params with this command :
npx uri-scheme open "app://LIVE/3a35ed925895A26" --android
I need when click on the example.com/m/3a35ed925895A26 app opened LIVE screen with 3a35ed925895A26 params

Well, I found the solution myself
1- I had to make changes in the code in order to be able to access the app both through app:// and through various link models (with http without http - with https without https - with www without www).
In AndroidManifest.xml file :
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
//for app://
<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:scheme="app" />
</intent-filter>
//for links
<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:scheme="https" android:host="www.example.com" />
<data android:scheme="http" android:host="www.example.com" />
<data android:scheme="https" android:host="example.com" />
<data android:scheme="http" android:host="example.com" />
</intent-filter>
2- And deep linking prefixes :
prefixes: [
'https://www.example.com',
'http://www.example.com',
'https://*.example.com',
'http://example.com',
'https://example.com',
'app://'
]
3- Now for example my link is something like this : www.example.com/m/876c875dDfV3, In order to be able to access the route /m through deep link, I need to define its route in screens as m/:uuid.
/m is route in my links, And :uuid is my params to this route, You can use your params or you're link structure.
config: {
initialRouteName:'home',
screens: {
HOME: 'home',
LIVE: 'm/:uuid',
TAGList: 'tag/:enVal'
}
}

Related

How to receive a PDF file after sharing with the intent of vue native

PDF file is being shared intent in Android app.
I want to save the shared PDF file one by one to the place I want in my app.
AndroidManifest.xml is as follows, and I don't know how to get it.
AndroidManifest.xml
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!--TODO: Add this filter, if you want to support sharing any type of files-->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>

React Native firebase dynamic link, deep linking [Android]

I am using dynamic link in React Native, I have all the steps required for IOS and android setup. (dynamic link opens the app on both platform) but when I have deep link attached to it, on Android app is opened but deep link parameters are not passed.
IOS works fine, deep link works correctly.
"react-native": "0.67.4",
"#react-native-firebase/app": "12.7.4",
"#react-native-firebase/dynamic-links": "12.7.4",
device: Xiaomi mi 9,
browser: Xiaomi browser,
deeplink: https://sweeftdigital.page.link/transfer_tip?userId=3
deep link debug version
video
Press to see video
In this video there are two browser: Mi browser and chrome browser,
Mi browser: when pressing dynamic link, it opens app directly without passing parameters.
chrome: when pressing dynamic link, it asks to open either in browser or open app, when you choose and app it passes parameters and deep link works.
AndroidManifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tipapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<application android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="false"
android:usesCleartextTraffic="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:exported='true'
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
</intent-filter>
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "https://www.sweeftdigital.page.link/” -->
<data android:scheme="https"
android:host="sweeftdigital.page.link" />
<!-- Accepts URIs that begin with "tipapp://” -->
<data android:scheme="tipapp" />
</intent-filter>
</activity>
</application>
</manifest>
deep link handling with react navigation
const config = {
screens: {
webView: {
path: '/transfer_tip',
parse: {
userId: (userId: any) => userId,
},
},
authLoading: '*',
},
};
const linking = {
prefixes: ['tipapp://', 'https://sweeftdigital.page.link'],
config: config,
};
<NavigationContainer
linking={linking}
...
Is there anything incorrect or is it firebase dynamic links normal behaviour?

Android intent filter - React Native 0.70

I am trying to launch a custom react native app from the Community Health Toolkit (CHT App Launcher). The goal is that a button is pressed in CHT and that the user is then forwarded directly to the custom app.
I am using the below code right now for my custom react native app in the AndroidManifest.xml file to launch it:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<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">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="string resource">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
</application>
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". -->
<data android:mimeType="*/*" />
</intent>
</queries>
However, I have difficulties launching the react native app from CHT even though both apps are installed on the emulator. CHT works in such a way that we can define an intent directly in the xlsx form. Currently, we use the following format in the xlsx default column to start the react native app “android.intent.action.VIEW”.
Unfortunately, the custom app does not appear when we press the button on CHT.
The preview window just prompts me to open other apps (e.g., Adobe Reader etc..).
If I define another intent in the xlsx form in CHT such as "android.media.action.image_capture", the standard camera app on the emulator opens successfully.
As a result, I believe I misdefined something in the AndroidManifest.xml file.
What am I missing?
Your intent-filter must be like
<intent-filter android:excludeFromRecents="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="app.applinking" />
</intent-filter>
The android:scheme must be your app linking URL.

How to get started with react-native-bootsplash

I want to make a splash screen using react-native-bootsplash. I have followed the instructions on npm and the library is installed properly but I am not able to understand how to use it. Can someone give me an example or a small code snippet that I can write in App.js and get started. A basic example would do fine.
Here is how I integrated with RN 0.62.2:
Step 1: Add the package to react-native project
yarn add react-native-bootsplash
Step 2: Generate assets for bootscreen.
yarn generate-bootsplash
...
yarn run v1.19.0
$ /Users/sresu/personal/startups/chill/code/chill-app-rn/node_modules/.bin/generate-bootsplash
✔ The path to the root of your React Native project … .
✔ The path to your static assets directory … assets
✔ Your original icon file … assets/bootsplash_logo_original.png
✔ The bootsplash background color (in hexadecimal) … #FFF
✔ The desired icon width (in dp - we recommend approximately ~100) … 100
✔ Are you sure? All the existing bootsplash images will be overwritten! … yes
👍 Looking good! Generating files…
✨ android/app/src/main/res/mipmap-mdpi/bootsplash_logo.png (100x100)
✨ android/app/src/main/res/mipmap-hdpi/bootsplash_logo.png (150x150)
✨ android/app/src/main/res/mipmap-xxhdpi/bootsplash_logo.png (300x300)
✨ ios/chill/Images.xcassets/BootSplashLogo.imageset/bootsplash_logo#2x.png (200x200)
✨ ios/chill/Images.xcassets/BootSplashLogo.imageset/bootsplash_logo#3x.png (300x300)
✨ assets/bootsplash_logo.png (100x100)
✨ assets/bootsplash_logo#1,5x.png (150x150)
✨ assets/bootsplash_logo#2x.png (200x200)
✨ assets/bootsplash_logo#3x.png (300x300)
✨ assets/bootsplash_logo#4x.png (400x400)
✨ android/app/src/main/res/mipmap-xxxhdpi/bootsplash_logo.png (400x400)
✨ ios/chill/Images.xcassets/BootSplashLogo.imageset/bootsplash_logo.png (100x100)
✨ android/app/src/main/res/mipmap-xhdpi/bootsplash_logo.png (200x200)
✨ ios/chill/BootSplash.storyboard
✨ android/app/src/main/res/drawable/bootsplash.xml
✨ android/app/src/main/res/values/colors.xml
✅ Done! Thanks for using react-native-bootsplash.
✨ Done in 10.86s.
Step 3: Update this file -> android/app/src/main/java/com/chill/MainActivity.java
import com.zoontek.rnbootsplash.RNBootSplash; //<- add this import statement
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
#Override
protected String getMainComponentName() {
return ....
}
// Add this for splash screen
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RNBootSplash.init(R.drawable.bootsplash, MainActivity.this); // <- display the generated bootsplash.xml drawable over our MainActivity
}
}
Step 4: Modify android/app/src/main/res/values/styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#000000</item>
</style>
<!-- Add the following lines -->
<!-- BootTheme should inherit from AppTheme -->
<style name="BootTheme" parent="AppTheme">
<!-- set the generated bootsplash.xml drawable as activity background -->
<item name="android:background">#drawable/bootsplash</item>
</style>
</resources>
Make sure you should have this file - android/app/src/main/res/drawable/bootsplash.xml, this is generated from Step 2.
Step 5: Modify android/app/src/main/AndroidManifest.xml
...
<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">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan"
android:exported="true">
<!-- android:windowSoftInputMode="adjustResize">-->
</activity>
<!-- add the following lines (use the theme you created at step 3) -->
<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>
<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:scheme="chill" />
</intent-filter>
<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="chill.com"
android:scheme="https" />
</intent-filter>
<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="chill.com"
android:scheme="http" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
...
Last step: Hide splash screen when app is ready
class App extends React.Component<Props, State> {
componentDidMount() {
RNBootSplash.hide({duration: 250}); // fade
...
Official docs: https://github.com/zoontek/react-native-bootsplash
🤗 Hope this helps.

can't detect notification when app closed

so I've been trying to do this app but for some reason, after I can't seem to be able to detect notification from the firebase consol when the app is closed (not in the background or frontground those work fine).
so here are some of the relevant files.
componentDidMount() {
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification: Notification) => {
// Process your notification as required
// ANDROID: Remote notifications do not contain the channel ID. You will have to specify this manually if you'd like to re-display the notification.
});
this.notificationListener = firebase.notifications().onNotification((notification: Notification) => {
// Process your notification as required
notification.android.setChannelId('test-channel')
console.log("I'm called haha", notification);
firebase.notifications().displayNotification(notification)
});
this.messageListener = firebase.messaging().onMessage((message) => {
bgMessaging(message)
})
}
componentWillUnmount() {
this.notificationDisplayedListener();
this.notificationListener();
}
android manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobalib">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
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>
<receiver android:name="io.invertase.firebase.notifications.RNFirebaseBackgroundNotificationActionReceiver"
android:exported="true">
<intent-filter>
<action android:name="io.invertase.firebase.notifications.BackgroundAction"/>
</intent-filter>
</receiver>
</service>
<service
android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<activity
android:launchMode="singleTop"
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<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>
</manifest>
index.js:
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => bgMessaging);
and finaly bgMesseging.js:
xport default (message: RemoteMessage) => {
// handle your message
const title = message.get
const notification = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle('My notification title')
.setBody('My notification body')
.setData({
key1: 'value1',
key2: 'value2',
});
notification
.android.setChannelId('test-channel')
firebase.notifications().displayNotification(notification)
console.log(message);
return Promise.resolve();
}
the TL/dr is that depending on what brand your phone is the notification can only be detected.
so Android not that great when it comes to this part of notification but it is so customisable on other thing that i do like it