您好我正在尝试从网络服务器下载apk文件到我的Android应用程序(/ download)目录。 问题是:在AVD上工作正常,但在我的真实手机S2上不下载这个apk文件。 请hellp :)
代码:`
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());
}
}`
答案 0 :(得分:0)
主持人:10.10.10.10是您真正的手机网络可以访问的真实主机吗?或者只是只能通过桌面访问测试主机。