【问题标题】:Sharing Text File using ACTION_SEND使用 ACTION_SEND 共享文本文件
【发布时间】:2013-04-16 11:39:55
【问题描述】:

我们可以使用 ACTION_SEND 打开分享对话框来分享文字

     Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_TEXT, "Download Link: Android play store link");
                sendIntent.setType("text/plain");
                startActivity(Intent.createChooser(sendIntent, "Share This App"));

如何使用 ACTION_SEND 共享文本文件。

我阅读了http://developer.android.com/training/sharing/send.html,但不知道如何共享文本文件。

【问题讨论】:

    标签: android


    【解决方案1】:

    使用以下行。

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
        emailIntent.setType("*/*");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"me@gmail.com"}); 
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
        "Test Subject"); 
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
        "go on read the emails");     
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromfile(new File(yourtextfilepath));
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    

    确保您的文本文件路径应该来自外部存储卡。动作发送不会接受来自内部存储器的文件。

    希望这会对您有所帮助。

    【讨论】:

    • 这不适用于不同的配置文件。您应该与 ContentProvider 共享内容,而不是 developer.android.com/training/enterprise/…
    • ... Uri.fromfile( ... 语法错误,改成 Uri.fromFile(
    • 这是我在几个 attems 和其他示例之后发现的最干净和最简单的方法。我的情况:我的应用程序创建了一个 .csv 文件并将其存储在 DOWNLOAD 文件夹中,我希望在创建文件后共享它而不使用 FileProvider。
    • 但是,我们不能在不使用电子邮件路由的情况下将文本文件共享给其他应用程序吗?看起来它只会被邮件应用拦截。
    猜你喜欢
    • 2013-12-18
    • 1970-01-01
    • 2014-06-07
    • 2015-02-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多