有誰知道缺少的權限是如何運作的以及它何時顯示在logcat中?權限被拒絕(缺少INTERNET權限?)未出現在logcat中
我試圖有意刪除INTERNET權限以觸發此異常,但在下面的httpsURLConnection.connect()期間並沒有被觸發 - 發生的是它直接進入finally塊。
最初我以爲這是因爲之前授予權限,應用程序/測試設備會記住它,所以我卸載了應用程序然後重新安裝了它,但同樣的事情發生。
有誰知道是什麼觸發了這種行爲?謝謝!
編輯:我有另一個應用程序(來自Udacity課程的Sunshine應用程序),我複製了這段代碼,並且顯示了權限錯誤。從我的類
摘譯 - 在httpsURLConnection.connect()行
public class MovieDBAPI extends AsyncTask<String, Object, List<Movie>> {
final String TAG = getClass().getSimpleName();
protected List<Movie> doInBackground(String... params) {
BufferedReader bufferedReader = null;
HttpsURLConnection httpsURLConnection = null;
StringBuffer stringBuffer = null;
try {
//create a URL
URL url = new URL(buildURL(params[0]));
Log.v(TAG, url.toString());
httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setRequestMethod("GET");
httpsURLConnection.connect();
//get string input
InputStream inputStream = httpsURLConnection.getInputStream();
if (inputStream == null) {
//no input stream, nothing to do
return null;
}
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line;
stringBuffer = new StringBuffer();
while((line = bufferedReader.readLine()) != null) {
// Since it's JSON, adding a newline isn't necessary (it won't affect parsing)
// But it does make debugging a *lot* easier if you print out the completed
// buffer for debugging.
stringBuffer.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
//if stringBuffer is not null, then prepare the result
if (stringBuffer != null) {
return getMovieDataFromJSON(stringBuffer.toString());
}
if (httpsURLConnection != null) {
httpsURLConnection.disconnect();
}
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}
}
以任何機會,你在棉花糖運行此代碼以上? –
@TheAbsurd其實牛軋糖。 7.0 –