简体   繁体   English

java.lang.SecurityException:权限被拒绝

[英]java.lang.SecurityException: Permission denied

Downloading content from a URL in Android but get a crash. 从Android中的URL下载内容,但会崩溃。 Any idea what is going on? 知道发生了什么吗?

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) {
        }

    }
});

Make sure you have proper permission for your application. 确保您对您的应用程序具有适当的权限。 If you are using internet, attach following line to Manifest file: 如果您使用的是互联网,请将以下行附加到清单文件中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.SecurityException:探戈权限被拒绝。 没有ADF许可 - java.lang.SecurityException: Tango Permission Denied. No ADF permission java.lang.SecurityException:权限被拒绝(缺少INTERNET权限?),即使在android清单中添加了此权限 - java.lang.SecurityException: Permission denied (missing INTERNET permission?) even with adding this permission in android manifest Java.lang.SecurityException:Android中的安全权限? - Java.lang.SecurityException:SECURE PERMISSION in android? java.lang.SecurityException:权限拒绝错误 - java.lang.SecurityException: Permission Denial ERROR 捕获的异常:java.lang.SecurityException:权限被拒绝(缺少INTERNET权限?) - Caught exception: java.lang.SecurityException: Permission denied (missing INTERNET permission?) NetworkDispatcher.run:未处理的异常java.lang.SecurityException:权限被拒绝(缺少INTERNET权限?) - NetworkDispatcher.run: Unhandled exception java.lang.SecurityException: Permission denied (missing INTERNET permission?) java.lang.SecurityException: - java.lang.SecurityException: Java.lang.securityException - Java.lang.securityException 应用程序崩溃,并出现java.lang.SecurityException:权限被拒绝 - App crashes with java.lang.SecurityException: Permission Denial java.lang.SecurityException:试图未经许可读取 gservices - java.lang.SecurityException: attempting to read gservices without permission
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM