簡體   English   中英

Android意向在新文檔中使用意向文本打開Word

[英]Android intent to open Word with intent's text in a new document

我想將數據從我的Android應用程序發送到Office Mobile(尤其是Word Document)Android應用程序。 我應該在下面的setType()方法中提供什么值,當前值不會使Office Mobile出現在選項中。 它只會帶來Twitter,Facebook等。

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

嘗試這個:

public static void openFile(Context context, File url) throws IOException {
    // Create URI
    File file=url;
    Uri uri = Uri.fromFile(file);

    Intent intent = new Intent(Intent.ACTION_VIEW);

    if(url.toString().contains(".docx")) {
        // Text file
        intent.setDataAndType(uri, "text/plain");
}

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        context.startActivity(intent);

其他一些鏈接,以防萬一這不起作用: Android如何打開.doc擴展名文件? https://developer.android.com/guide/components/intents-filters.html

希望它能起作用! 祝好運! 編碼愉快!

暫無
暫無

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

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