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
PR Ready: https://github.com/appcelerator/titanium_mobile/pull/2492 For testing we will need to use a local web server. For some cases, the browser does not resolve "http://www.appcelerator.com" correctly if you type it directly into the url box. If you click on a link that is directly to 'http://appcelerator.com' then it always works correctly. This is native android behavior and we don't do anything on the titanium end: 1. Run an app with the code sample above 2. On a Mac: create a test.html file under ~/Sites/test.html 3. Add the following in test.html:
4. Under system preferences > sharing, check off "web sharing" 5. Once you have done this, there should a url for your site, something like: http://192.168.1.104/~your_username/ 6. On your phone, connect to the same wifi network as your laptop, and type http://192.168.1.104/~your_username/test 7. Click on the "click me" link 8. It should prompt you to open either a browser or your app. Choose to open with your app. Expected Result: Your app should open with a button with the success message Actual Result: Currently, the app will open with a runtime error
Thanks! Tested this on my environment and worked fine! Best, Mauro
Environment used for verification - Tested with Titanium SDK: 2.1.1.v20120716180600 Tested with Titanium Studio: 2.1.1.201207161421 Device - Android 2.2.2 LG-P970 Machine OS - MAC 10.7.3