Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9863] Android: Custom url doesn't open the app on 3.x+ devices

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionWon't Do
Resolution Date2020-02-19T13:48:14.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sn/a
ComponentsAndroid
Labelscore
ReporterAllen Yeung
AssigneeRene Pot
Created2012-07-02T17:14:14.000+0000
Updated2020-02-19T13:48:14.000+0000

Description

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

Comments

  1. Tamila Smolich 2012-08-07

    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
  2. Fokke Zandbergen 2013-08-23

    Changing the tiapp.xml code to point it to app.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 adding android:launchMode="singleTask" to <activity>. This does cause my app to crash every now and then and I have no idea why. Investigating...
           <android xmlns:android="http://schemas.android.com/apk/res/android">
               <activities>
                  <activity android:alwaysRetainTaskState="true" android:launchMode="singleTask" url="app.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>
       
  3. Tim Poulsen 2013-08-23

    (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:
       <activity
           android:configChanges="keyboardHidden|orientation"
           android:label="URLSchemes"
           android:name=".UrlschemesActivity" android:theme="@style/Theme.Titanium">
           <intent-filter>
               <action android:name="android.intent.action.MAIN"/>
               <category android:name="android.intent.category.LAUNCHER"/>
           </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:host="" android:scheme="urlschemes"/>
           </intent-filter>
       </activity>
       
    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 tag; it has to be written as shown to work.
  4. Fokke Zandbergen 2013-08-23

    (removed)
  5. Ingo Muschenetz 2014-05-01

    Unfortunately out of time for 3.3.0. Bumping to 3.3.1.
  6. Ingo Muschenetz 2014-08-14

    3.4.0 is moved forward, and 3.5.0 is taking its place in the calendar.

JSON Source