こんにちは、Web サーバーから Android アプリケーション (/download) ディレクトリに apk ファイルをダウンロードしようとしています。問題は次のとおりです。AVD では正常に動作していますが、実際の電話 S2 ではこの apk ファイルをダウンロードしません。助けてください:)
コード:`
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_apk);
BroadcastReceiver receiver = new BroadcastReceiver() {
@SuppressLint("NewApi")
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
// openFile();
}
}
};
registerReceiver(receiver, new IntentFilter(
DownloadManager.ACTION_DOWNLOAD_COMPLETE));
/*
//del old file
File fileUpdate = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/"+fileName);
if(fileUpdate != null){
fileUpdate.delete();
}*/
startDownload();
}
@SuppressLint("NewApi")
public void startDownload() {
try{
dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(
Uri.parse("http://10.10.10.10/andr_test/download_new_version/appUpdate.apk"));
enqueue = dm.enqueue(request);
} catch (Exception e) {
Log.e("Can't download file", "Can't download file-" + e.getMessage());
}
}`