您好,我正在尝试将 apk 文件从 Web 服务器下载到我的 android 应用程序 (/download) 目录。问题是:在 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());
}
}`