Android应用程序无法在某些设备上连接到interenet,但在其他设备上无法连接

Android应用程序无法在某些设备上连接到interenet,但在其他设备上无法连接,android,Android,我正在编写一个应用程序,它有几个功能,使用HTTPConnection连接到internet并下载数据。我已经在多台设备上进行了测试,但应用程序内部的连接似乎在不同的设备上命中或未命中。我是;我相信这个连接在三星设备上不起作用。我认为,因为它还不是一个“官方”许可的应用程序,所以连接失败了。这可能是某种操作系统的不同吗 下面的代码应该连接到internet并将单词下载到文件中。它在某些设备上工作,但在其他设备上,它最终创建一个空白文件并引发异常 try{ URL url =

我正在编写一个应用程序,它有几个功能,使用HTTPConnection连接到internet并下载数据。我已经在多台设备上进行了测试,但应用程序内部的连接似乎在不同的设备上命中或未命中。我是;我相信这个连接在三星设备上不起作用。我认为,因为它还不是一个“官方”许可的应用程序,所以连接失败了。这可能是某种操作系统的不同吗

下面的代码应该连接到internet并将单词下载到文件中。它在某些设备上工作,但在其他设备上,它最终创建一个空白文件并引发异常

 try{ 
         URL url = new URL("*" + currQuickList + ".txt");
           URLConnection urlConnection = url.openConnection();
           urlConnection.setUseCaches(false);
           int i = 0;  

               // Read all the text returned by the server
       BufferedReader in = new BufferedReader(new InputStreamReader(
                urlConnection.getInputStream()));
        String str;
        int count = Integer.parseInt(in.readLine());
        int[] a = createOrderedList(count,quickListLen);
        int d = 0;
        int g = 0;
        while ((str = in.readLine()) != null && d < a.length) {
            // str is one line of text; readLine() strips the newline
            // character(s)

            if(a[d] == g)
            {words.add(str);
            d++;
            }
            g++;

        }

             in.close();


                OutputStream fo = new FileOutputStream(dir);  
                 PrintWriter p = new PrintWriter(fo);
                 p.print(packageWords2(words) +"\n");

                 p.close();
                 fo.close();

                 System.out.println("file created: "+dir);
                 //files.add(wordText);

                }
                catch(Exception e){
                    e.printStackTrace();
                    errorDialog(e);
                }
试试{
URL=新URL(“*”+currQuickList+“.txt”);
URLConnection URLConnection=url.openConnection();
urlConnection.setUseCaches(false);
int i=0;
//读取服务器返回的所有文本
BufferedReader in=新的BufferedReader(新的InputStreamReader(
urlConnection.getInputStream());
字符串str;
int count=Integer.parseInt(in.readLine());
int[]a=createOrderedList(计数,quickListLen);
int d=0;
int g=0;
while((str=in.readLine())!=null&&d
下载或使用internet之前,请检查您的internet连接。您可以尝试此操作

public static boolean isConnectingToInternet(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null)
            for (int i = 0; i < info.length; i++)
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }

    }
    return false;
}
公共静态布尔值连接到Internet(上下文){
ConnectionManager连接=(ConnectionManager)上下文
.getSystemService(Context.CONNECTIVITY\u服务);
if(连接性!=null){
NetworkInfo[]info=connectivity.getAllNetworkInfo();
如果(信息!=null)
对于(int i=0;i
您的代码可能有错误,但如果没有错误,我们将无法告诉您任何事情。我同意@fonZ的说法,您可以提供您的代码吗?您需要更具体一些,例如从非工作设备捕获logcat日志。作为一个完全随机的猜测,如果你不能在后台线程上进行联网,它可能会在较新的设备上失败,但(至少在简单的情况下)在较旧的设备上可以正常工作。我提供了一些代码。见上文。