【问题标题】:Android intent to open Word with intent's text in a new documentAndroid意图在新文档中打开带有意图文本的Word
【发布时间】:2016-08-26 12:43:55
【问题描述】:

我想将数据从我的 android 应用程序发送到 Office Mobile(尤其是 Word 文档)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);

【问题讨论】:

标签: android android-intent


【解决方案1】:

试试这个:

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 how to open a .doc extension file? https://developer.android.com/guide/components/intents-filters.html

希望它有效!祝你好运!快乐编码!

【讨论】:

    猜你喜欢
    • 2019-07-17
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多