Problem Description
Customer wants to registrate his own url in android, so he can open the app with something like this://is.sparta from the browser in android. We got a really nice recipe on this, but it's not working anymore.
Actual Results
The custom url is not registered.
Expected Results
The custom url should work nice.
Test case:
1. Create mobile project.
2. Add this to the app.js:
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
win.add(Ti.UI.createLabel({ text: 'Type http://www.appcelerator.com in a browser, and this app will get launched. Try it!' }));
win.open();
3. Add this to launchFromURL.js:
var activity = Ti.Android.currentActivity;
var win = Ti.UI.currentWindow;
activity.addEventListener("create", function(e) {
win.add(Ti.UI.createButton({title: 'Our app was launched when you typed http://www.appcelerator.com!'}));
});
4. Add this to the tiapp.xml
<android xmlns:android="http://schemas.android.com/apk/res/android">
<activities>
<activity url="launchFromURL.js">
<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="http" android:host="www.appcelerator.com"/>
</intent-filter>
</activity>
</activities>
</android>
Extra info
Part of our research was:
Generic for Android:
http://stackoverflow.com/questions/3469908/make-a-link-in-the-android-browser-start-up-my-app/3472228
From Dawson:
https://gist.github.com/840600
The same behavior exists on Android versions 3.X and 4.X, but works well on 2.X. Tested on: Titanium Studio, build: 2.1.1.201207271312 Titanium SDK, build: 2.0.3.v20120806151610 Devices: Nexus 7 (4.1), Sony Tablet S (3.2) Host OS: Mac OS X Mountain Lion 10.8; Mac OS X Lion 10.7.3
Changing the
tiapp.xml
code to point it toapp.js
instead of a separate file works, but has the nasty side-effect of launching the intent in the context of the browser where you click the link. This can be fixed by addingandroid:launchMode="singleTask"
to<activity>
. This does cause my app to crash every now and then and I have no idea why. Investigating...(admittedly a slightly different use case) The following works to define a custom URL scheme instead of overriding http. It's from the training lab example:
See https://github.com/appcelerator-training/tce_training/tree/master/labcode/Finished_code/URLSchemes In my testing, the app would not launch if I used a single
(removed)
Unfortunately out of time for 3.3.0. Bumping to 3.3.1.
3.4.0 is moved forward, and 3.5.0 is taking its place in the calendar.