[英]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.