简体   繁体   English

Android意向在新文档中使用意向文本打开Word

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

I want to send data from my android app to Office Mobile (particularly Word Document) android app. 我想将数据从我的Android应用程序发送到Office Mobile(尤其是Word Document)Android应用程序。 What value should I supply at the setType() method below, the current value does not bring Office Mobile among options. 我应该在下面的setType()方法中提供什么值,当前值不会使Office Mobile出现在选项中。 It just brings twitter, facebook, etc. 它只会带来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);

Try this: 尝试这个:

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);

Some other links in case this doesn't work: Android how to open a .doc extension file? 其他一些链接,以防万一这不起作用: Android如何打开.doc扩展名文件? https://developer.android.com/guide/components/intents-filters.html https://developer.android.com/guide/components/intents-filters.html

Hope it works! 希望它能起作用! Good Luck! 祝好运! Happy Coding! 编码愉快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM