Share to React-Native - react-native

I am trying to have apps on the android device to share to my react-native app. However, I can't find any documentation which can help me so I was wondering if there any way to share content from other apps to my app?
Clarification:
I am trying to add my app to this list

You need Allowing Other Apps to Start Your Activity. reference here.
<intent-filter android:label="Share here!">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
As you may notice, This Witchcraft will show your app on the Sharing list.
In order to handle the burden, place the next snippet in your component. Any component.
componentDidMount() {
Linking.getInitialURL().then((url) => {
console.log('Initial url is: ' + url);
}).catch(err => console.error('An error occurred', err));
}
This charm is called Linking. Documentation found here

Related

React native background actions intent app

I am using react native background actions but as i am getting a notification when i click on the notification. I is opening gallery in the app by default. I want to open my app. Not able to get how can i open app on click on the notification.
const options = {
taskName: 'Downloading',
taskTitle: 'ExampleTask title',
taskDesc: 'ExampleTask description',
taskIcon: {
name: 'ic_launcher',
type: 'mipmap',
},
color: '#ff00ff',
linkingURI: 'yourSchemeHere://chat/jane', // See Deep Linking for more info
parameters: {
delay: 15000,
},
};
Not getting how to use linking to open my app instead of the gallery using intent filter or something else.
In order to open the respective app when the user clicks on the notification of react native background action service.
Take these two steps -
Add intent filter on AndroidManifest.xml located at android/app/src/main. Under application activity tag.
Also, verify this line "android:launchMode="singleTask"" should be
there in activity tag. if not then please add it
<intent-filter android:label="filter_react_native">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="technomizeEMS" /> // Your custom scheme name then in second step we'll add this on linkingURI
</intent-filter>
Add linkingUri in the configuration option of the start method. (The important takeaway for linkingURI is to add the same name as added on intent-filter
in data tag android:scheme in AndroidManifest.xml and also append :// )
const options = {
taskName: 'Task Name',
taskTitle: 'Task Title',
taskDesc: 'Task Description',
taskIcon: {
name: 'ic_launcher',
type: 'mipmap',
},
color: '#ff00ff',
// The important take away for linkingURI is to add same name as added on intent-filter
// in data tag android:scheme in AndroidManifest.xml and also append ://
linkingURI: 'technomizeEMS://', // See Deep Linking for more info
parameters: {
delay: 1000,
},
};
await BackgroundService.start(this.veryIntensiveTask, options);
For more detail you can refer here
https://github.com/Rapsssito/react-native-background-actions#deep-linking
Hope it will help you or somebody else. Thanks!
Happy Coding :-)

Notification revived but not displayed airship React Native

I've been trying to get notifications by airship for my app. It worked with the iOS fine, but with Android, there are some issues.
In the first I was getting a warning whenever I send a notification saying:
No task registered for key ReactNativeFirebaseMessagingHeadlessTask
I searched for some answer and finally I added these lines to my code:
messaging()
.setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Message handled in the background!', remoteMessage);
});
It kind of works now but displaying the notification still doesn't work. Now when I receive the notification I get this log from the above function:
Message handled in the background!,
{
"data": {
"com.urbanairship.metadata": "eyJ2ZXJzaW9uX2lkIjoxLCJ0aW1lIjoxNjM2NDcxNzk3MjgyLCJwdXNoX2lkIjoiZDczN2QxZWMtNTExNC00NWI3LThhNGYtYjI1NWNmYWZiZDcxIiwiY2FtcGFpZ25zIjp7ImNhdGVnb3JpZXMiOltdfX0=",
"com.urbanairship.push.ALERT": "Congratulations! You've successfully configured Android Push.",
"com.urbanairship.push.APID": "26e8cdec-3e61-437c-940d-cd9e75c3a7df",
"com.urbanairship.push.CANONICAL_PUSH_ID": "d737d1ec-5114-45b7-8a4f-b255cfafbd71",
"com.urbanairship.push.PUSH_ID": "e51fd020-4171-11ec-a035-02423b27e6fe"
},
"from": "827761845713",
"messageId": "0:1636471797306222%14a7377ff9fd7ecd",
"sentTime": 1636471797292,
"ttl": 2419200
}
It's clearly received the notification without any error from the phone or the platform (it says sent successfully), but it still won't show up in the phone.
The problem is located in the AndroidManifest.xml file.
I removed this and everything works now.
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

Error: 400: Your project does not own Dynamic Links domain

I'm using react-native-firebase to create dynamic links, when I create standard link everything works fine, but when I'm creating short link, it gives an error: "Error: 400: Your project does not own Dynamic Links domain". Any ideas how is possible to fix that?
UPDATE: problem occurs only in Android, in IOS works fine
Code for the creating short dynamic link:
onClickShare= () => {
const link =
new firebase.links.DynamicLink(redirectLink , Config.FIREBASE_CONFIG.dynamicLink)
.android.setPackageName(Config.ANDROID_PACKAGE_NAME)
.ios.setBundleId(Config.IOS_BUNDLE_ID)
.ios.setAppStoreId(Config.IOS_APP_STORE_ID)
.social.setDescriptionText(description)
.social.setTitle(this.props.event.title)
firebase.links()
.createShortDynamicLink(link, 'SHORT')
.then((url) => {
Share.share({
message: _('shareLinkMessage') + " " + url,
title: _('shareLinkTitle'),
}, {
// Android only:
dialogTitle: _('shareLinkAndroid'),
})
})
If you get such error, update your google-services.json file!
In my case (using Flutter), I was getting this error because of incorrect "uriPrefix" parameter while in DynamicLinkParameters object params:
final DynamicLinkParameters parameters = DynamicLinkParameters(
uriPrefix: your_page_link, //<-- this should be same as in your Firebase project
link: Uri.parse(....),
androidParameters: AndroidParameters(
....
),
iosParameters: IOSParameters(
....
),
);
Please make sure if you have uriPrefix value set properly.
when you get this error that means you did not add the dynamic link domain as a formate of the firebase link.
you must follow this formate:
<app_name.page.link>
In android/app/src/main/AndroidManifest.xml add within the activity:
<!-- Deep linking -->
<meta-data android:name='flutter _deeplinking_enabled'
android:value="true" />
<intent-filter android:autoVerify="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="http" android:host="<app_name.page.link>" />
<data android:scheme="https" />
</intent-filter>
and added at the same with that formate <app_name.page.link> in dynamic link code.
Try this method,
import dynamicLinks from '#react-native-firebase/dynamic-links';
async function generateLink() {
const link = await dynamicLinks().buildLink({
link: 'valid domain url',
domainUriPrefix: 'valid domain url',
analytics: {
content: 'your data',
},
});
console.log(link)
}
You might not have done npm install if your google-services.json is already updated

App doesn't run correctly from ToastNotification action

I'm trying to make a very simple demo to show how to work with Background Tasks and Toast Notifications in UWP. I've a simple task, which is triggered on network connection change and his work is to show a simple notification. It's of course registered in OS, selected in manifest and this task works well.
I've created a package and installed the app in my laptop to try if it run even in the moment when the app isn't launched. Task works as well.
The only problem is, that when I click on "Run app" button in notification, I want to launch app running in foreground. It starts app, but the only thing I can see is splash screen of my app and nothing else happened. I saw MSDN tutorial to this notification and my XML is almost the same.
My XML notification's content:
<toast launch="app-defined-string">
<visual>
<binding template="ToastGeneric">
<text>Test notification</text>
<text>This is a simple toast notification</text>
<image placement="AppLogoOverride" src="../Assets/icon.png"/>
</binding>
</visual>
<actions>
<action activationType="foreground" content="Run App" arguments="check" />
</actions>
<audio src="ms-winsoundevent:Notification.SMS" />
</toast>
UPDATE
The only modified part in App.xaml.cs:
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.ToastNotification)
{
var toastArgs = (ToastNotificationActivatedEventArgs)args;
ToastArg = toastArgs.Argument;
}
}
You need to invoke the initialization of your app (things inside OnLaunch method) from OnActivated. Remember to check if your app is running or not when initialization.

Titanium Appcelerator: How to set focus to the application window?

What is the Titanium method that shifts application focus to the Titanium app when an event occurs? For example, my application is constantly running in the background, and I want a window to open when email arrives.
You would like the Ti App to open when you receive an email on the device?
As far as I know, this won't happen automatically (as I could see many developers abusing this).
However, what I suggest is, add a URI Scheme (a url link or button) in the Email something like:
yourApp://view?id=abc which the user can click on, and it will open your app, and open the window/view/controller within your App. To do so, you will need to add URI schemes to your App, and handle the url, parse it, and so something useful with it in your App... here's how:
In the App's tiapp.xml, add this for iOS:
<dict>
<key>CFBundleURLName</key>
<!-- same as ti:app/id -->
<string>your.app.id</string>
<key>CFBundleURLSchemes</key>
<array>
<!-- your custom scheme -->
<string>yourApp</string>
</array>
</dict>
On Android in tiapp.xml in manifest node:
<application>
<activity android:configChanges="keyboardHidden|orientation" android:label="Your App"
android:name=".MyAppActivity" android:theme="#style/Theme.Titanium"
android:launchMode="singleTask" >
<!-- add the above launchMode attribute -->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- add the below additional 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="yourApp" />
</intent-filter>
</activity>
</application>
In Alloy.js:
if (OS_ANDROID) {
// Somehow, only in alloy.js we can get the data (URL) that opened the app
Alloy.Globals.url = Ti.Android.currentActivity.intent.data;
}
In your Main app.js or index.js:
// We don't want our URL to do anything before our main window is open
$.index.addEventListener('open', function (e) {
if (OS_IOS) {
// Handle the URL in case it opened the app
handleURL(Ti.App.getArguments().url);
// Handle the URL in case it resumed the app
Ti.App.addEventListener('resumed', function () {
handleURL(Ti.App.getArguments().url);
});
} else if (OS_ANDROID) {
// On Android, somehow the app always opens as new
handleURL(Alloy.globals.url);
}
});
var XCallbackURL = require('XCallbackURL');
function handleUrl(url) {
var URL = XCallbackURL.parse(url),
controller = URL.action(),
args = URL.params();
// Add some better logic here ;)
Alloy.createController(controller, args || {}).getView().open();
}
You can also learn more in much more details here: http://fokkezb.nl/2013/08/26/url-schemes-for-ios-and-android-1/
win.addEventListener('focus',function() {
// your code here
}
you can use setTimeOut() of javascript which will start another activity once your email popup or view or window does show up.
There are some issues with your example code:
You cannot handle incoming emails with your application (at least not in iOS). It is restricted by the iOS in order to ensure user privacy
The URL-schemes are used to handle links to your app (e.g. myapp:// from the browser or other apps)
In order to handle URL-schemes, use the handleurl event that is available in Titanium SDK 5.5.0.GA and later
Ensure that you remove event-listeners after leaving the current context, especially when you add event listeners in the open / focus event
If you follow that rules, you should be able to receive and handle URL's regarding your app, thanks!