我正在编写一个小应用程序,只有我会使用,我想在root的android 4.5设备上实际启用/禁用我的移动数据(我正在为Nexus 4运行自定义Android L).
我已经找了一会儿,我找到了反射的方法,直到android 4.3.我也看过这个帖子中的方法在Android 4.4.2上以编程方式切换移动数据,但这需要cyanogenmod.
从我在互联网上找到的内容来看,这对于非root应用来说是不可能的,但我的问题是:
有什么我可以用我的root权限来完成这个吗?
所以我使用apache HttpComponents来处理java中的http请求.现在我想重用一下DefaultHttpClient,应该对这个例子有什么看法:http://wiki.apache.org/HttpComponents/QuickStart .示例本身给出了一个ssl错误,因此我进行了修改并简化了一点.现在我总是得到一个org.apache.http.client.ClientProtocolException
这是我的示例程序,基本上我只是使用相同的请求2个网页DefaultHttpClient.
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
public class ClientFormLogin {
public static void main(String[] args) throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
//Handle first request.
HttpGet httpget = new HttpGet("http://tweakers.net/nieuws/82969/amazon-nederland-opent-digitale-deuren-in-september.html");
HttpResponse response = httpclient.execute(httpget);
System.out.println("Execute finished");
HttpEntity entity = response.getEntity();
String page = readInput(entity.getContent());
System.out.println("Request one finished without problems!");
//Handle second request
HttpGet httpost = new HttpGet("http://gathering.tweakers.net/forum/list_messages/1506977/last");
response = httpclient.execute(httpost); …Run Code Online (Sandbox Code Playgroud)