我在问这个,因为我已经尝试过....一些代码并创建了我自己的代码来访问互联网上存在的文件,我想读取该文件但我的代码不起作用所以我问这个问题是因为在SD_CARD 情况下,我们必须向我们的 android 应用程序提供权限,以便您可以访问它....因此,每次我的应用程序终止时,我的代码都是:-
try
{
url = new URL ("http://sites.google.com/site/androidersite/text.txt");
}
catch (MalformedURLException e)
{
Toast.makeText( this , "url String mein hi error aa raha hai .. oo" , Toast.LENGTH_LONG ).show();
}
HttpURLConnection urlConnection = null ;
try
{
urlConnection = (HttpURLConnection) url.openConnection();
}
catch (IOException e)
{
Toast.makeText( this , "HTTP url connection mein error" , Toast.LENGTH_SHORT ).show();
}
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected())
{
Toast.makeText( this , "connect hua" , Toast.LENGTH_SHORT ).show();
}
else
{
Toast.makeText( this , "nahi hua connect" , Toast.LENGTH_SHORT ).show();
}
try
{
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(url.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null)
{
stringText += StringBuffer;
}
bufferReader.close();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
&对于我提供的权限,它。
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>