java.lang.SecurityException:权限被拒绝

时间:2016-06-14 11:36:53

标签: java android

从Android中的网址下载内容但遭遇崩溃。知道发生了什么事吗?

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

editText.addTextChangedListener(new TextWatcher() {

    public void afterTextChanged(Editable s) {

    }

    public void beforeTextChanged(CharSequence s, int start, int count, int after)  {

    }

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        Log.i("TAG","text = "+editText.getText().toString());

        try {
            // Create a URL for the desired page
            URL url = new URL("http://www.omdbapi.com/?t=\" + editText.getText().toString() + \"&y=&plot=short&r=json");

            // Read all the text returned by the server
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while ((str = in.readLine()) != null) {
                // str is one line of text; readLine() strips the newline character(s)
            }

            Log.d("alma", str);

            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }

    }
});

1 个答案:

答案 0 :(得分:0)

确保您拥有适用于您的应用程序的权限。如果您使用的是互联网,请将以下行附加到清单文件:

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