How can I get data from a Toast notification when my app is opened by tapping the Toast notification? - windows-phone

If a user clicks a Toast notification to open my app, is it possible to
know the app was opened from a Toast notification?
identify data from the Toast notification?
If so, how?

As outlined here: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868212.aspx
Create toast so that it has launch parameters:
((XmlElement)toastNode).SetAttribute("launch", "{\"type\":\"toast\",\"param1\":\"12345\",\"param2\":\"67890\"}");
The toast XML will appear as
<toast launch="{"type":"toast":"param1":"12345":"param2":"67890"}">
<visual>
<binding template="ToastImageAndText01">
<image id="1" src="ms-appx:///images/redWide.png" alt="red graphic"/>
<text id="1">Hello World!</text>
</binding>
</visual>
</toast>
then in the app's OnLaunched method:
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
string launchString = args.Arguments
....
}

Related

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>

React Native Webview push new page on <a> clicked

I'm trying to create a hybrid react native app to host my website's content in webviews. Something like this: Supreme App
One thing I want to achieve is: when a <a href> link is clicked on my website, instead of webview just show the new link's content, I want the app to push a new page and show the new link content in the new page, so that I can maintain a good page backstack and it feels more like native app (for each navigation, there's a new page for it).
I'm wondering how I can detect link click, push a new page instead of let the webview do default link navigation. Thanks!
You can use WebView prop onNavigationStateChange to detect the change in url.
On clicking <a> the webview will redirect, the onNavigationStateChange will fire. You can use this callback to push a new screen in the app.
Eg.
<WebView
ref={r => this.webview = r}
style = {{marginTop : 0}}
onNavigationStateChange={this._onNavigationStateChange}
source = {{uri: 'https://www.your-url.com' }}
/>
_onNavigationStateChange=(webViewState)=>{
let newUrl = webViewState.url
/*Your navigation logic*/
}
Reference

Share to 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

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!