0
我很努力使一個簡單的應用程序來下載互聯網的文件繼承人我的代碼我從另一個問題編輯了一點,但我仍然沒有得到響應錯誤,每當我運行我的應用程序可以任何人顯示我的糾正,甚至一個不同的方式?努力使用Android Eclipse下載文件?
package com.example.downloading;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.util.ByteArrayBuffer;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.ResultReceiver;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.app.Activity;
import android.app.DownloadManager;
import android.app.IntentService;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
public class MainActivity extends Activity {
Button startBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startBtn = (Button)findViewById(R.id.download_button);
startBtn.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
String url = "my stuff";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("descrition");
request.setTitle("title");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "etc.mp3");
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
});
}
}
即時通訊設法使用你的代碼並實現它,但仍然沒有成功zny其他想法? – MikeyBoy 2013-03-02 14:10:35