Connection problem with database [duplicate]

0

I made a program to try to connect to a hosted database. But an error is occurring:

  

08-30 10: 42: 13.088 1710-1710 / genus.qrcodefinal E / log_tag: Error in http connection java.lang.SecurityException: Permission denied (missing INTERNET permission?)

Connection part:

Button botaoconecta = (Button) findViewById(R.id.botaoconecta);
    botaoconecta.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {
                HttpClient httpclient = new DefaultHttpClient();

                HttpPost httppost = new HttpPost("linkdosite**");


                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                InputStream is = entity.getContent();
            } catch (Exception e) {
                Log.e("log_tag", "Error in http connection " + e.toString());
            }
        }
    });

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="genus.qrcodefinal">



<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

</application>

    
asked by anonymous 30.08.2016 / 12:50

1 answer

0

The error is due to lack of permissions.

They have to be declared in the AndroidManifest.xml file within the <manifest> tag, but you are placing them within the <application> tag.

Change AndroidManifest.xml like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="genus.qrcodefinal">

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

    </application>
</manifest>

If targetSdkVersion is 23 or higher, you must obtain these permissions at run time.

See this answer how to do it.

If you do not want to handle permissions at run time change the targetSdkVersion to 22. The application will still be able to run on devices running Android 6 or higher, however in compatibility mode.

    
30.08.2016 / 13:22