Reputation: 544
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.
Upvotes: 1
Views: 2220
Reputation: 11552
There are some issues with your example code:
myapp://
from the browser or other apps)handleurl
event that is available in Titanium SDK 5.5.0.GA and lateropen
/ focus
eventIf you follow that rules, you should be able to receive and handle URL's regarding your app, thanks!
Upvotes: 0
Reputation: 829
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/
Upvotes: 1
Reputation: 23632
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.
Upvotes: 0