简体   繁体   中英

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. What value should I supply at the setType() method below, the current value does not bring Office Mobile among options. It just brings twitter, facebook, etc.

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? https://developer.android.com/guide/components/intents-filters.html

Hope it works! Good Luck! Happy Coding!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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