このAndroidアプリはAndroidスタジオを使用しています。ビーコン/エッジトーンからのデータをスキャンして表示する機能です。アプリはすでに機能しており、スキャンが停止した後、データはローカルファイルに保存されます。しかし、私の問題は、スキャンデータをサーバーに転送する必要があるときです。バックエンドサーバーにスキャンデータを転送する必要があります。しかし、私は初心者なので、何が最善の方法であるかは本当にわかりませんでした。ここで アンドロイドスタジオを使用してアンドロイドアプリからサーバーにデータを投稿する方法
は、データをローカルデータに転送するコードです:private void stopScanning(Button scanButton) {
try {
beaconManager.stopRangingBeaconsInRegion(region);
} catch (RemoteException e) {
// TODO - OK, what now then?
}
String scanData = logString.toString();
if (scanData.length() > 0)
{
// Write file
fileHelper.createFile(scanData);
// Display file created message.
Toast.makeText(getBaseContext(),
"File saved to:" + getFilesDir().getAbsolutePath(),
Toast.LENGTH_SHORT).show();
scanButton.setText(MODE_STOPPED);
} else {
// We didn't get any data, so there's no point writing an empty file.
Toast.makeText(getBaseContext(),
"No data captured during scan, output file will not be created.",
Toast.LENGTH_SHORT).show();
scanButton.setText(MODE_STOPPED);
}
}
サーバーへの接続、サーバーへのデータの送信、サーバーからのデータの取得には、volleyライブラリまたはretrofitライブラリを使用してください。http://inthecheesefactory.com/blog/retrofit-2.0/ja http://developer.android.com/intl/zh -cn/training/volley/index.html – Arshad
レトロフィット(rxandroidでも可能ですが、これはオプションです)http://square.github.io/retrofit/ – hehe
どのようにしてサーバーのデータを受信しますか? JSON、XML、クエリパラメータとしてファイルをアップロードしますか? – leonziyo