gpt4 book ai didi

java - Android编程(尝试下载文件到系统目录)

转载 作者:行者123 更新时间:2023-12-01 18:50:06 24 4
gpt4 key购买 nike

亲爱的 stackOverflow 成员,我最近启动了一个名为“RootBox”的新项目,它是一个需要“su”权限的应用程序,我已成功允许应用程序“su”或“root”访问,我正在尝试下载和替换“/system/media 中的系统文件,我已经设置了下载器,但下载进度对话框弹出并关闭,我猜测这是文件无法写入系统目录的结果,并且我已经重新安装了系统在开始下载之前,我已经在互联网上进行了搜索,但无法找到帮助,这就是我来这里的原因。

这是执行下载的 Activity

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);
}

}}

最佳答案

为此,您必须在 list 中允许写入为

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

关于java - Android编程(尝试下载文件到系统目录),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16166928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com