If I try to register a file associaton the app han

2019-08-30 08:11发布

I have tried to register a new file association using the suggestions answered in this question

I want to open the main Activity of the app if the user try to open the registered file type

According the accepted answer in the Manifest I have tried this code

<activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <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:scheme="http" android:host="*"
                    android:pathPattern=".*\\.myfilextension" />
                <data android:scheme="https" android:host="*"
                    android:pathPattern=".*\\.myfilextension" />
                <data android:scheme="content" android:host="*"
                    android:pathPattern=".*\\.myfilextension" />
                <data android:scheme="file" android:host="*"
                    android:pathPattern=".*\\.myfilextension" />
            </intent-filter>
        </activity>

but the .myfilextension seems not correctly associated, since if I try to open a file sample.myfilextension nothing happens.

So I have tried

<activity
            android:name=".MainActivity"
            android:label="@string/app_name">
        <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:scheme="http" />
            <data android:scheme="https" />
            <data android:scheme="ftp" />
            <data android:scheme="file" />
            <data android:host="*" />
            <data android:mimeType="*/*" />
            <data android:pathPattern=".*\\.myfilextension" />
       </intent-filter>
</activity>

With this code, if I try to open a file .myfilextension and the App has been launched and is running in background everything works fine, but if the app is closed when I try to open the file, the app try to start but hangs, in the emulator hangs on "wait for debugger" soI cannot understand the cause of the issue.

How could I fix this?

1条回答
叼着烟拽天下
2楼-- · 2019-08-30 08:49

The second sample code should work.

in the emulator hangs on "wait for debugger"

The problem seems related to the Emulator that cannot attach the debugger.

Try to follow these steps:

-Close the Emulator

-Go to AVD manager and recreate the emulator again

-Start the emulator and try to run the app

Alternatively try to run the app on a real device.

查看更多
登录 后发表回答