0
你好,我試圖從網絡服務器下載apk文件到我的Android應用程序(/下載)目錄。 問題是:在AVD上工作正常,但在我的真實手機S2不下載這個apk文件。 請HELLP :)下載apk文件。在AVD上工作正常,但在真實的手機上達不到
代碼:`
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());
}
}`
電話可以訪問該地址。當我在瀏覽器手機中寫入地址時,開始下載文件 – user1309635