2013-04-23 73 views
0

親愛的StackOverflow成員最近我已經開始了一個名爲「RootBox」的新項目,這是一個需要「蘇」燙髮的應用程序,我已經成功地允許應用程序使用「su」或「根」訪問和IM嘗試下載並替換「/系統/媒體系統文件,我已經安裝我的下載,但下載進度對話框彈出和關閉其即時猜測是不能夠寫入的文件的結果到系統目錄,我已經重新安裝系統爲rw開始下載之前我已經搜索了所有的互聯網,無法找到幫助,這就是爲什麼我來到這裏。的Android編程(嘗試下載文件到系統目錄)

這是執行下載

public static final int DIALOG_DOWNLOAD_PROGRESS = 0; 
private Button startBtn; 
private ProgressDialog mProgressDialog; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.bootmation); 
    startBtn = (Button)findViewById(R.id.startBtn); 
    startBtn.setOnClickListener(new OnClickListener(){ 
     public void onClick(View v) { 
      startDownload(); 
      RootTools.remount("/system/", "rw"); 
     } 
    }); 
} 

private void startDownload() { 
    String url = "http://www.filehosting.org/file/details/430746/bootanimation.zip"; 
    new DownloadFileAsync().execute(url); 
} 
@Override 
protected Dialog onCreateDialog(int id) { 
    switch (id) { 
    case DIALOG_DOWNLOAD_PROGRESS: 
     mProgressDialog = new ProgressDialog(this); 
     mProgressDialog.setMessage("Downloading file.."); 
     mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
     mProgressDialog.setCancelable(false); 
     mProgressDialog.show(); 
     return mProgressDialog; 
    default: 
     return null; 
    } 
} 

類DownloadFileAsync擴展的AsyncTask {

@Override 
protected void onPreExecute() { 
    super.onPreExecute(); 
    showDialog(DIALOG_DOWNLOAD_PROGRESS); 
} 

@Override 
protected String doInBackground(String... aurl) { 
    int count; 

try { 

URL url = new URL(aurl[0]); 
URLConnection conexion = url.openConnection(); 
conexion.connect(); 

int lenghtOfFile = conexion.getContentLength(); 
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile); 

InputStream input = new BufferedInputStream(url.openStream()); 
OutputStream output = new FileOutputStream("/system/media/bootanimation.zip"); 

byte data[] = new byte[1024]; 

long total = 0; 

    while ((count = input.read(data)) != -1) { 
     total += count; 
     publishProgress(""+(int)((total*100)/lenghtOfFile)); 
     output.write(data, 0, count); 
    } 

    output.flush(); 
    output.close(); 
    input.close(); 
} catch (Exception e) {} 
return null; 

} 
protected void onProgressUpdate(String... progress) { 
    Log.d("ANDRO_ASYNC",progress[0]); 
    mProgressDialog.setProgress(Integer.parseInt(progress[0])); 
} 

@Override 
protected void onPostExecute(String unused) { 
    dismissDialog(DIALOG_DOWNLOAD_PROGRESS); 
} 

} }

回答

1
URL u = new URL(fUrls[i]); 
HttpURLConnection c = (HttpURLConnection) u.openConnection(); 
c.setRequestMethod("GET"); 
c.setDoOutput(true); 
          c.connect(); 
+0

美國可以採取的InputStream輸入= c.getInputStream();並寫inputteram到目標文件夾它可能會解決您的問題.... – 2013-04-23 11:00:07

3

這個u必須允許清單許可寫爲

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
+0

確定虐待嘗試現在 – Shayden117 2013-04-23 10:30:17

+0

沒有工作,但現在它實際上掛載系統爲rw – Shayden117 2013-04-23 10:36:39

+0

是啊,我加入互聯網燙髮,但它將使一個differnce如果目標文件已經存在 – Shayden117 2013-04-23 10:41:20