簡體   English   中英

設置標題以選擇應用程序以從瀏覽器打開 pdf

[英]Set header to choose app to open pdf from browser

在我的網絡應用程序中,用戶可以下載 pdf 文件。

在PC上沒有問題,在瀏覽器上打開pdf文件,然后您可以選擇一些操作,下載或打印等。

所以我正在嘗試使用平板電腦,我希望當我點擊下載時會出現菜單來選擇使用哪個應用程序打開 pdf 文件,或者如果有默認應用程序。

這是我下載文件的方法,我在其中設置了標題:

public static HttpEntity<byte[]> downloadPdfFile(final String fileName, final byte[] item){

        HttpHeaders header = new HttpHeaders();
        header.setContentType(MediaType.valueOf("application/pdf"));
        header.setContentLength(item.length);

        return new HttpEntity<byte[]>(item, header);
    }

更新如果在我的 URL 中添加例如fileName.pdf之前下載它的菜單來選擇哪個應用程序使用出現..

所以我在我的應用程序中添加了這個intent filter以將它顯示到菜單中:

<intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:scheme="file" android:pathPattern=".*\\.pdf"/>
            </intent-filter>
              
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="application/pdf"/>
            </intent-filter>

但我的應用程序不在菜單中。

你有什么想法嗎?

我解決了,2天后它起作用了!

這是我的解決方案:將fileName.pdf傳遞到 url 以下載它並使用這些意圖過濾器:

  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http" />
    <data android:host="*" />
    <data android:pathPattern=".*\\.pdf" />
  </intent-filter>
  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http" />
    <data android:host="*" />
    <data android:mimeType="application/pdf" />
  </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=".*\\.pdf" />
  </intent-filter>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM