0
votes

EDIT: message about uses-permission is not allowed here no longer appears.

I'm using Volley to access google books, api is icecreamsandwich. Even including permissions to the manifest file I still get exception about permissions. I've already read some answered questions (this, this). When pointing to the uses-permission by cursor, it says that the tag is not allowed here. How can I solve the problem?

manifest file:

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

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

    <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>
    </application>


</manifest>

Function where I use the Volley

private void onSearchClicked() {
        String bookName = editText.getText().toString();
        String url = "https://www.googleapis.com/books/v1/volumes?q=" + bookName;

        RequestQueue queue = Volley.newRequestQueue(this);
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Log.d(TAG, response.toString());
            }
        }, new Response.ErrorListener()
        {
            @Override
            public void onErrorResponse(VolleyError err)
            {
                Log.e(TAG, err.getMessage());
            }
        }
        );

        queue.add(request);
    }

editText is properly initialized by finding the view.

Logcat:

06-09 04:43:58.895 9190-9364/com.example.alone.findgooglebook E/Volley: [114] NetworkDispatcher.run: Unhandled exception java.lang.SecurityException: Permission denied (missing INTERNET permission?) java.lang.SecurityException: Permission denied (missing INTERNET permission?) at java.net.InetAddress.lookupHostByName(InetAddress.java:418) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) at java.net.InetAddress.getAllByName(InetAddress.java:214) at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28) at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216) at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292) at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206) at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345) at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296) at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503) at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:136) at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:110) at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96) at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112) Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname) at libcore.io.Posix.getaddrinfo(Native Method) at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61) at java.net.InetAddress.lookupHostByName(InetAddress.java:405) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)  at java.net.InetAddress.getAllByName(InetAddress.java:214)  at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28)  at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216)  at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122)  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292)  at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)  at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)  at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)  at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503)  at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:136)  at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:110)  at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)  at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)  Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied) at libcore.io.Posix.getaddrinfo(Native Method)  at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61)  at java.net.InetAddress.lookupHostByName(InetAddress.java:405)  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)  at java.net.InetAddress.getAllByName(InetAddress.java:214)  at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28)  at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216)  at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122)  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292)  at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)  at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)  at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)  at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503)  at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:136)  at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:110)  at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)  at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)  06-09 04:43:58.903 9190-9190/com.example.alone.findgooglebook E/MainActivity: java.lang.SecurityException: Permission denied (missing INTERNET permission?)

2
what is your app compileSdkVersion?Manish Jain
it's icecreamsandwich, can't recall the number. I'll edit the postIncomputable
It's <uses-permission>, not <user-permission>. uses, not user.Mike M.
@MikeM., worked! Thank you. Last question: should I leave the post or delete it, since it's somewhere around typo?Incomputable
@MikeM. I've flagged it myself, waiting for moderator interventionIncomputable

2 Answers

0
votes

I assume your targetSdk is set to 23 so you have to ask the user for permissions. A quickfix would be to set the targetSdk=22 and all should work then.

0
votes

Try adding

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

and add your activity name with package like

 <activity android:name="com.example.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

Let me know if it works