0

インターネット速度のチェックで問題に直面しています。実際、携帯電話でインターネット速度をテストできる Android アプリを開発しています。速度と、ISP から入手した 7.3 Mbps などの書き込み速度をテストするサンプルを作成します。しかし、このテストでは以下のコードを使用しています。

長い startCon = System.currentTimeMillis(); Log.i("mymobilespeedtest", "start conn = " + startCon);

        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(imageURL);
        HttpResponse response = null;
        try {
            response = httpClient.execute(httpGet);
            Log.i("SketchEffect","Executing http connection to download selected image.");
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            Log.i("FBAlbum", e.toString());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            Log.i("FBAlbum", e.toString());
        }
        long endCon = System.currentTimeMillis();
        Log.i("mymobilespeedtest", "endCon = " + endCon);

ここで、ハンドラーを使用し、別の方法でファイルをダウンロードして、インターネット速度の進行状況を表示したいと考えています。

この方法では、以下のコードを使用しています

         String downloadFileUrl =    "http://www.gregbugaj.com/wp-content/uploads/2009/03/dummy.txt";
          URL    url1 = new URL(downloadFileUrl);
            URLConnection con1 = url1.openConnection();
            con1.setUseCaches(false); stream1 = con1.getInputStream();
            Message msgUpdateConnection = Message.obtain(mHandler,
                    MSG_UPDATE_CONNECTION_TIME);
            msgUpdateConnection.arg1 = (int) connectionLatency;
            mHandler.sendMessage(msgUpdateConnection);

            long start = System.currentTimeMillis();
            int currentByte = 0;
            long updateStart = System.currentTimeMillis();
            long updateDelta = 0;
            int bytesInThreshold = 0;
            int bytesIn = 0;
            while (true) {
                if ((currentByte = stream1.read()) == -1) {
                    break;
                } else {
                    bytesIn++;
                    bytesInThreshold++;
                    baf.append((byte) currentByte);
                    if (updateDelta >= UPDATE_THRESHOLD) {
                        int progress = (int) ((bytesIn / (double) EXPECTED_SIZE_IN_BYTES) * 100);
                        Message msg = Message.obtain(mHandler,
                                MSG_UPDATE_STATUS,
                                calculate(updateDelta, bytesInThreshold));
                        msg.arg1 = progress;
                        msg.arg2 = bytesIn;
                        mHandler.sendMessage(msg);
                        // Reset
                        updateStart = System.currentTimeMillis();
                        bytesInThreshold = 0;
                    }
                    updateDelta = System.currentTimeMillis() - updateStart;
                }

            } if (downloadTime == 0) {
                downloadTime = 1;
            }

            Message msg = Message.obtain(mHandler, MSG_COMPLETE_STATUS,
                    calculate(downloadTime, bytesIn));
            msg.arg1 = bytesIn;
            mHandler.sendMessage(msg);

上記のコードでは、.8 または 1.o Mbps の速度しか得られません (バイトではなくメガビット/秒)。

4

1 に答える 1