Skip to content

Instantly share code, notes, and snippets.

@cauboy
Last active August 29, 2015 14:17
Show Gist options
  • Save cauboy/c2985da8ab7fb5320713 to your computer and use it in GitHub Desktop.
Save cauboy/c2985da8ab7fb5320713 to your computer and use it in GitHub Desktop.
The goal is to receive a share intent (e.g. a website url by Chrome) and open a specific activity (save.js) based on that intent (not the default one).
<!-- That's the created AndroidManifest.xml when running titanium build --platform android -->
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.refind.app" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/appicon" android:label="MyOwn" android:name="MyOwnApplication" android:debuggable="false" android:theme="@style/Theme.AppCompat">
<activity android:name=".MyOwnActivity" android:label="@string/app_name" android:theme="@style/Theme.Titanium" android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="org.appcelerator.titanium.TiActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="org.appcelerator.titanium.TiTranslucentActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:theme="@style/Theme.AppCompat.Translucent"/>
<activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity" android:configChanges="screenSize"/>
<activity android:name="com.myown.app.SaveActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>
// Just for Testing
Ti.API.info('save.js');
var activity = Ti.Android.currentActivity;
var intentData = activity.getIntent().getData();
Ti.API.info('intentData', JSON.stringify(intentData));
<!-- … -->
<android xmlns:android="http://schemas.android.com/apk/res/android">
<activities>
<activity url="save.js"
android:label="@string/app_name"
android:theme="@style/Theme.Titanium"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter android:label="Save This to MyOwn App">
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="*/*"/>
</intent-filter>
</activity>
</activities>
</android>
<!-- … -->
@cauboy
Copy link
Author

cauboy commented Mar 15, 2015

I also tried to put everything within the <application> tag. But it doesn't work either, probably because no url attribute is allowed…

<!-- tiapp.xml -->
   <android xmlns:android="http://schemas.android.com/apk/res/android">
        <manifest>
            <application>
                <activity
                    android:configChanges="keyboardHidden|orientation|screenSize"
                    android:label="@string/app_name"
                    android:launchMode="singleTop"
                    android:name=".MyOwnActivity" android:theme="@style/Theme.Titanium">
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN"/>
                        <category android:name="android.intent.category.LAUNCHER"/>
                    </intent-filter>
                </activity>
                <!-- Save Activity -->
                <activity android:name=".SaveActivity" url="save.js">
                    <intent-filter android:label="+ Save to MyOwn App">
                        <action android:name="android.intent.action.SEND"/>
                        <category android:name="android.intent.category.DEFAULT"/>
                        <data android:mimeType="*/*"/>
                    </intent-filter>
                </activity>
            </application>
        </manifest>
    </android>

But the second registered activity is just ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment