Search code examples
androidintentfilter

intent-filter does not go to the Android system


I want to register my app to be associated with some file extension. AndoidManifest.xml contains:

    <application
        android:icon="@drawable/ic_launcher"
                android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
                    android:name=".IntentTestActivity" >
            <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" />
                            <data android:scheme="file" />
                            <data android:host="*" />
                            <data android:pathPattern=".*\\.XXX" />
            </intent-filter>
        </activity>
    </application>

but I don't even see my app in list of VIEW actions. Even inside my app this code shows anything but my app:

    final PackageManager packageManager = getPackageManager();
    final Intent intent = new Intent("android.intent.action.VIEW");
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo r : list) {
        Log.d("XXX", "" + r);
    }

What is wrong or how else should I associate file extension with particular action?


Solution

  • this resolved the problem for me: it seems that dropbax, google drive and other apps have dots '.' in their full path, and that the android regex '.' is not greedy...

    <data android:pathPattern=".*\\.XXX" />
    <data android:pathPattern=".*\\..*\\.XXX" />
    <data android:pathPattern=".*\\..*\\..*\\.XXX" />
    <data android:pathPattern=".*\\..*\\..*\\..*\\.XXX" />
    <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.XXX" />