共享文件时,Android应用会在旧应用中打开

时间:2015-06-30 13:10:30

标签: android

我有一个奇怪的问题。我已将我的应用程序设置为清单中打开文件的默认启动器,如下面的代码示例所示。

例如,如果我选择从默认的android下载应用程序打开文件,它看起来像这样:

enter image description here

有没有办法让它在新的应用程序/窗口中打开,以便下载应用程序和我的应用程序看起来像是两个不同的应用程序?

预告文件

    <activity
        android:name=".SplashActivity"
        android:label="@string/app_name"
        android:noHistory="true"
        android:screenOrientation="sensorPortrait">
        <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" />
            <action android:name="android.intent.action.SEND" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="application/pdf" />
            <data android:mimeType="text/plain" />
            <data android:mimeType="application/rtf" />
            <data android:mimeType="image/jpeg" />
            <data android:mimeType="image/png" />
            <data android:mimeType="image/tiff" />
            <data android:mimeType="image/bmp" />
            <data android:mimeType="image/gif" />
            <data android:mimeType="application/postscript" />
            <data android:mimeType="application/msword" />
            <data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
            <data android:mimeType="application/vnd.ms-powerpoint" />
            <data android:mimeType="application/vnd.ms-excel" />
            <data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document" />
        </intent-filter>

    </activity>

完整清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="princh.princh">

    <uses-permission android:name="android.permission.INTERNET" />
                   //Allows the app to use the internet connection
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
       //Allows the app to check the connection status in order to determine whether data can be downloaded.
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     //Allows the app to cache map tile data in the device's external storage area.
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
     //Allows the app to use WiFi or mobile cell data (or both) to determine the device's location.
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
       //Allows the app to use the Global Positioning System (GPS) to determine the device's location to within a very small area.
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/princh_launcher_icon"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="AIzaSyD1e3EbexMClXfkyULNViJlOPgeubzZdfI" />

        <service
            android:name=".network.NetworkManager"
            android:exported="false" >
            </service>


    <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="sensorPortrait" >
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".PrintJobActivity"
            android:label="@string/app_name"
            android:screenOrientation="sensorPortrait" >
        </activity>
        <activity
            android:name=".SelectPrinterOptionsActivity"
            android:label="@string/title_activity_select_printer_options"
            android:launchMode="singleTop"
            android:parentActivityName=".PrintJobActivity"
            android:screenOrientation="sensorPortrait">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".PrintJobActivity" />
        </activity>
        <activity
            android:name=".PrintRangeActivity"
            android:label="@string/title_activity_print_range"
            android:parentActivityName=".PrintJobActivity"
            android:screenOrientation="sensorPortrait">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".PrintJobActivity" />
        </activity>
        <activity
            android:name=".ShowPrinterMapActivity"
            android:label="@string/title_activity_select_printer_map"
            android:parentActivityName=".SelectPrinterOptionsActivity"
            android:screenOrientation="sensorPortrait">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".SelectPrinterOptionsActivity" />
        </activity>
        <activity
            android:name=".PrintPreviewActivity"
            android:label="@string/title_activity_print_preview"
            android:parentActivityName=".SelectPrinterOptionsActivity"
            android:screenOrientation="sensorPortrait">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".SelectPrinterOptionsActivity" />
        </activity>

        <activity
            android:name=".OrderInfoActivity"
            android:label="@string/title_activity_order_info_activitty"
            android:screenOrientation="sensorPortrait">
        </activity>
        <activity
            android:name=".PaymentActivity"
            android:label="@string/title_activity_payment"
            android:screenOrientation="sensorPortrait"
            android:windowSoftInputMode="adjustNothing">
        </activity>
        <activity
            android:name=".OrderDetailsActivity"
            android:label="@string/title_activity_order_details"
            android:screenOrientation="sensorPortrait">
        </activity>
        <activity android:name="sdt.brc.android.BarcodeScanActivity"
            android:label="@string/app_name">
            <intent-filter>
                <category android:name="android.intent.category.EMBED" />
            </intent-filter>
        </activity>
        <activity
            android:name=".TermsAndConditionsActivity"
            android:label="@string/title_activity_terms_and_conditions"
            android:screenOrientation="sensorPortrait">
        </activity>
        <activity
            android:name=".SplashActivity"
            android:label="@string/app_name"
            android:noHistory="true"
            android:screenOrientation="sensorPortrait"
            android:process=":PrinchProcess">
            <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" />
                <action android:name="android.intent.action.SEND" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="application/pdf" />
                <data android:mimeType="text/plain" />
                <data android:mimeType="application/rtf" />
                <data android:mimeType="image/jpeg" />
                <data android:mimeType="image/png" />
                <data android:mimeType="image/tiff" />
                <data android:mimeType="image/bmp" />
                <data android:mimeType="image/gif" />
                <data android:mimeType="application/postscript" />
                <data android:mimeType="application/msword" />
                <data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
                <data android:mimeType="application/vnd.ms-powerpoint" />
                <data android:mimeType="application/vnd.ms-excel" />
                <data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document" />
            </intent-filter>

        </activity>
        <activity
            android:name=".JobStatusActivity"
            android:label="@string/title_activity_job_status"
            android:screenOrientation="sensorPortrait">
        </activity>
        <activity
            android:name=".ShowReceiptActivity"
            android:label="@string/title_activity_show_receipt"
            android:screenOrientation="sensorPortrait">
        </activity>
        <activity
            android:name=".QRCodeReaderActivity"
            android:label="@string/title_activity_qrcode_reader"
            android:screenOrientation="sensorPortrait">
        </activity>
        <activity
            android:name=".PrintjobHistoryActivity"
            android:label="@string/title_activity_printjob_history"
            android:screenOrientation="sensorPortrait">
        </activity>
    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

documentLaunchMode属性添加到您的清单中。默认值为none,您可能希望使用intoExistingalways

您还可以查看allowTaskReparentingtaskAffinity,了解对任务和堆栈的精细控制。