我需要什么代码来修复Apache HTTP Client的删除?

时间:2015-12-24 21:09:53

标签: android apache email http

Android 6.0 Marshmallow版本23.0破坏了我的代码 运行Android Studio 1.5.1。

由Apache HTTP客户端删除引起

developer.android.com Android 6.0更改说使用HttpURLConnection类。

package ...

import org.apache.http.protocol.HTTP; // here is my error -- Cannot resolve symbol 'HTTP'

class ...   

    Intent emailIntent;

    void share() { // put the data in a blank gmail that the user can send -- they choose the recipients
        emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setType(HTTP.PLAIN_TEXT_TYPE); // here is my error -- Cannot resolve symbol 'HTTP'
        emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{""}); // recipients
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "ShareSubject");
        emailIntent.putExtra(Intent.EXTRA_TEXT, idList.getText() + "\n" + defList.getText() + "\n");
        startActivityForResult(emailIntent, 1);
    }

} // Class

以上代码适用于Android 5版本22.0 我用以下代码替换了import apache:

import java.net.HttpURLConnection; 但Android Studio显示此行未使用。

我在HttpURLConnection下搜索了android开发人员,没有在电子邮件或共享下找到任何内容。 我搜索了apache HTTP.PLAIN_TEXT_TYPE并被弃用(我很痛苦地知道)。 我看到代码"如何向服务器发出HTTP POST请求"但不是如何填充电子邮件。 我怀疑我必须发布到gmail" Server"但我不知道怎么做。 我评论了错误的行:emailIntent.setType(HTTP.PLAIN_TEXT_TYPE); 并得到以下错误:

  

android.content.ActivityNotFoundException:找不到处理Intent的活动{act = android.intent.action.SEND flg = 0x1(有剪辑)(有额外内容)

此电子邮件共享与您在手机上查看某些代码并想要共享时使用的功能相同。 您点击菜单然后"分享"它会填充您可以发送的gmail(通常是回到桌面上)。 你能否分享一下我在Android 6下运行的代码?

1 个答案:

答案 0 :(得分:2)

我理解你的问题需要一点时间。我检查了SDK的完整源代码,确实没有其他常量可以使用。但是,您要搜索的字符串为CreateCrystal();。你可以直接插入它。

但我建议使用其他代码:

"text/plain"

此意图只会打开真正的邮件客户端。