Connection problem with Database

Asked

Viewed 42 times

0

I made a program to try to connect to a hosted database. However 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?)

Part of the connection :

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>

  • The app is to run on Android 6? Or better the targetVersion is API23 or higher?

  • On any Android 4.1.1 +

  • But the targetSdkVersion is API23 or higher?

  • If that’s what I’m thinking of in API 24, in my program, I’m kind of a beginner in the subject..

  • I reversed your edit so my answer wouldn’t be meaningless.

1 answer

0

Error due to lack of permissions.

They have to be declared in the file Androidmanifest.xml within the tag <manifest>, but you’re putting them inside the tag <application>.

Change the Androidmanifest.xml thus:

<?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 the targetSdkVersion is 23 or higher, you must obtain these permissions at runtime.

Look at this reply how to do it.

If you don’t want to deal with runtime permissions change the targetSdkVersion to 22. The app will still be able to run on Android 6 devices or higher, however in compatibility mode.

  • I changed the target to 21, and I put the code you mentioned, and it’s still the same.. I edited the question so you can see if I did it right..

  • Keep making the same mistake?

  • Yes, the same mistake...

  • Changed targetSdkVersion for 21 I see no reason to continue to make mistakes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.