为什么隐式意图有时会启动不正确的活动/意图?

时间:2019-01-21 16:54:33

标签: android android-intent react-native-android intentfilter

我在我的本机应用程序中添加了接收文件的可能性。例如,从电子邮件中打开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。

0 个答案:

没有答案
相关问题