Почему неявные намерения иногда запускают неправильные действия / намерения? - PullRequest
0 голосов
/ 21 января 2019

Я добавляю возможность получать файлы в моё приложение-приложение.Например, откройте файл PDF из электронного письма или отправьте изображение из галереи.Но иногда это не работает, и когда это не работает, кажется, что неверное действие было выбрано из неявного намерения, созданного этими приложениями.

Я добавил некоторые записи, чтобы увидеть, что происходит.

Нерабочий пример из logcat, используется намерение MainActivity:

01-21 17:20:34.232 11518 11577 I ReactNativeJS: Running application "PowerupShareEx" with appParams: {"rootTag":41}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
01-21 17:20:34.242 11518 11578 D ReactNativeJS activity: com.frenberg.powerup.MainActivity@159c271
01-21 17:20:34.242 11518 11578 D ReactNativeJS intent: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.frenberg.powerup.alfa/com.frenberg.powerup.MainActivity bnds=[726,316][1062,732] (has extras) }
01-21 17:20:34.243 11518 11578 D ReactNativeJS activity: com.frenberg.powerup.MainActivity@159c271
01-21 17:20:34.243 11518 11578 D ReactNativeJS intent: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.frenberg.powerup.alfa/com.frenberg.powerup.MainActivity bnds=[726,316][1062,732] (has extras) }

рабочий пример из logcat, используется намерение ShareActivity, содержащее правильные данные:

01-21 17:20:58.248 11518 11577 I ReactNativeJS: Running application "PowerupShareEx" with appParams: {"rootTag":51}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
01-21 17:20:58.261 11518 11578 D ReactNativeJS activity: com.frenberg.share.ShareActivity@86e955f
01-21 17:20:58.263 11518 11578 D ReactNativeJS intent: Intent { act=android.intent.action.VIEW dat=content://com.google.android.gm.sapi/appuser01@frenberg.com/message_attachment_external/#thread-f:1623272236728858938/#msg-f:1623272236728858938/0.1?account_type=com.google&mimeType=application/pdf&rendition=1 typ=application/pdf flg=0x13080001 cmp=com.frenberg.powerup.alfa/com.frenberg.share.ShareActivity }
01-21 17:20:58.288 11518 11578 D ReactNativeJS activity: com.frenberg.share.ShareActivity@86e955f
01-21 17:20:58.288 11518 11578 D ReactNativeJS intent: Intent { act=android.intent.action.VIEW dat=content://com.google.android.gm.sapi/appuser01@frenberg.com/message_attachment_external/#thread-f:1623272236728858938/#msg-f:1623272236728858938/0.1?account_type=com.google&mimeType=application/pdf&rendition=1 typ=application/pdf flg=0x13080001 cmp=com.frenberg.powerup.alfa/com.frenberg.share.ShareActivity }

Я новичок в разработке Android, но яЯ думаю, это как-то связано с моим AndroidManifest.xml-файлом.Если вам нужно что-то еще, просто спросите.

<application
    tools:replace="android:label"
    android:name=".MainApplication"
    android:allowBackup="false"
    android:label="${appName}"
    android:icon="@mipmap/ic_launcher"
    android:networkSecurityConfig="@xml/network_security_config"
    android:theme="@style/AppTheme">

    <activity
        android:name=".MainActivity"
        android:launchMode="singleTask"
        android:label="${appName}"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <action android:name="se.fortnox.powerup.action.OPEN_APP" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter android:label="${appName}">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <!-- Accepts URIs that begin with "powerup://documentcollection” -->
            <data android:scheme="powerup"
                android:host="documentcollection" />
        </intent-filter>
    </activity>

    .........

    <!--  for sharing photos and pdfs -->
    <activity
        android:noHistory="true"
        android:name="se.fortnox.share.ShareActivity"
        android:configChanges="orientation"
        android:label="${appName}"
        android:theme="@style/Theme.Share.Transparent" >
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/jpg" android:scheme="content" />
            <data android:mimeType="image/jpeg" android:scheme="content" />
            <data android:mimeType="image/tif" android:scheme="content" />
            <data android:mimeType="image/tiff" android:scheme="content" />
            <data android:mimeType="application/pdf" android:scheme="content" />
        </intent-filter>
    </activity>
...

Итак, я ожидаю, что ShareActivity всегда будет «выбрана», но, как вы можете заметить из вывода logcat выше, в «неработающем выводе» иногдавместо этого запускается MainActivity.

...