我需要什么代码来修复Apache HTTP Client的删除? [英] What code do I need to fix Apache HTTP Client removal?

查看:89
本文介绍了我需要什么代码来修复Apache HTTP Client的删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 6.0棉花糖23.0版破坏了我的代码 运行Android Studio 1.5.1.

Android 6.0 Marshmallow Version 23.0 broke my code Running Android Studio 1.5.1.

由Apache HTTP客户端删除引起的

Caused by Apache HTTP Client removal

developer.android.com Android 6.0更改表示请改用HttpURLConnection类.

developer.android.com Android 6.0 Changes says use HttpURLConnection class instead.

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替换为:

The above code was working on Android 5 Version 22.0 I replaced import apache with:

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

import java.net.HttpURLConnection; but Android Studio shows this line is unused.

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

I searched android developer under HttpURLConnection and found nothing under email or share. I searched apache for HTTP.PLAIN_TEXT_TYPE and got deprecated (which I am painfully aware of). I see code "How To Make HTTP POST Request To Server" but not how to populate an email. I suspect I have to post to the gmail "Server" but I don't know how. I comment out the errant line: emailIntent.setType(HTTP.PLAIN_TEXT_TYPE); And get the following error:

android.content.ActivityNotFoundException:找不到用于处理Intent的活动{act = android.intent.action.SEND flg = 0x1(具有剪辑)(具有附加功能)

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND flg=0x1 (has clip) (has extras)

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

This email share is the same function you use when you are viewing some code on your phone and want to share it. You click the menu then "share" and it populates a gmail that you can send (typically to yourself back on the desktop). Could you please share the code I am missing that will run under Android 6?

推荐答案

直到我了解您的问题为止,花了一点时间.我检查了SDK的完整源代码,的确没有其他常量可以使用.但是,您要搜索的字符串是"text/plain".您可以直接将其插入.

It took a little until I understood your problem. I checked the full source code of the SDK, it is true there is no other constant you could use. However the string you are searching for is "text/plain". You can insert it directly.

但是我建议使用其他代码:

However I would suggest to use another code:

Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                                Uri.fromParts("mailto", "you@example.com", null));
emailIntent.putExtra(Intent.EXTRA_EMAIL, /*...*/);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, /*...*/);
emailIntent.putExtra(Intent.EXTRA_TEXT, /*...*/);
startActivityForResult(emailIntent, 1);

此意图只会打开真实的邮件客户端.

This intent will just open real mail clients.

这篇关于我需要什么代码来修复Apache HTTP Client的删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆