Android:HTTPClient

我正在从svn.apache.org尝试http-cleint教程.在运行应用程序时,我在控制台中收到以下错误.
[2010-04-30 09:26:36 - HalloAndroid] ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.org.example/.HalloAndroid } from null (pid=-1,uid=-1) requires android.permission.INTERNET

我在AndroidManifest.xml中添加了android.permission.INTERNET.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.org.example"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HalloAndroid"
                  android:label="@string/app_name" android:permission="android.permission.INTERNET">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

</manifest>

HalloAndroid.java中的java代码如下

HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget2 = new HttpGet("http://google.com/");
        HttpResponse response2 = null;
        try {
            response2 = httpclient.execute(httpget2);
        } catch (ClientProtocolException e1) {
            // Todo Auto-generated catch block
            e1.printstacktrace();
        } catch (IOException e1) {
            // Todo Auto-generated catch block
            e1.printstacktrace();
        }
    httpentity entity = response2.getEntity();
    if (entity != null) {
        long len = entity.getContentLength();
        if (len != -1 && len < 2048) {
            try {
                    Log.d(TAG,EntityUtils.toString(entity));
                } catch (ParseException e) {
                    // Todo Auto-generated catch block
                    e.printstacktrace();
                } catch (IOException e) {
                    // Todo Auto-generated catch block
                    e.printstacktrace();
                }
        } else {
            // Stream content out
        }

任何帮助深表感谢.

解决方法

问题解决了. AndroidManifest.xml文件中的这一行导致了麻烦.
android:permission="android.permission.INTERNET"

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...