package com.cydeon.plasmamodz;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import com.cydeon.plasmamodz.R;
import android.app.ActionBar;
import android.app.Activity;
import android.app.DownloadManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
//Class for Boot Animation Blue Kindle
public class Boots extends Activity {
public static String TAG = "Boots";
Process process;
private class DownloadFile extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... sURL) {
try{
URL url = new URL(sURL[0]);
URLConnection connection = url.openConnection();
connection.connect();
//Shows 0-100% progress bar
int fileLength = connection.getContentLength();
//Download the file
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream("/sdcard/TWRP-Blaze-2.4.3.0-1.zip");
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
total += count;
//Publish the Progress
publishProgress((int) (total * 100/fileLength));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
}
return null;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog.show();
}
@Override
protected void onProgressUpdate(Integer... progress){
super.onProgressUpdate(progress);
mProgressDialog.setProgress(progress[0]);
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
mProgressDialog.dismiss();
Context context = getApplicationContext();
CharSequence text = "Installing. Please Wait";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("su");
proc = rt.exec("sh /sdcard/boots.sh");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null){
System.out.println(line);
}
}catch (Throwable t){
t.printStackTrace();
}
}
}
ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.boots);
ActionBar actionBar = getActionBar();
actionBar.hide();
ImageView img = (ImageView) findViewById(R.id.iv2);
img.setImageResource(R.drawable.boot1);
Button install = (Button) findViewById(R.id.bAInstall);
Button rtrn = (Button) findViewById(R.id.bAReturn);
mProgressDialog = new ProgressDialog(Boots.this);
mProgressDialog.setMessage("Downloading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.setMax(100);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
install.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
DownloadFile downloadFile = new DownloadFile();
downloadFile.execute("https://dl.dropbox.com/s/t16a0cq0qcon2ux/TWRP-Blaze-2.4.3.0-1.zip");
}
}
);
rtrn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
}
});
}
}
죄송 합니다만 충분히 검색하지 못했습니다. 나는 내 코드를 가지고 있으므로 게시 할 것이다. 또한, 아마 볼 수 있듯이, 내 애플 리케이션에 스크립트를 포함하고 그것을 실행하는 방법에 대해 잘 모르겠습니다. 새 폴더를 만들고 스크립트를 넣으려고했지만 작동하지 않습니다. 그것에 대한 도움은 너무 감사 할 것입니다 ...스크립트를 실행하기 전에 AsyncTask가 완료 될 때까지 대기하십시오.
편집 : 나는 일할 첫 번째 부분을 얻었다. 이제 스크립트를 실행할 수 없습니다. su가 실행되지만 내 스크립트는 실행되지 않습니다. 또한 내 스크립트를 내 앱에 넣을 위치를 알고 스크립트를 실행해야합니다. 앱을 설치할 때 스크립트가 어디에 있는지 확실하지 않습니다. 그리고 스크립트를 어디에 넣어야할지 모르겠습니다. 그래서 도움을 주시면 감사하겠습니다. 아래 (지금은 추측. 롤)는 업데이트 된 코드입니다.
Ok. 보시다시피 스크립트 실행을 OnClickListener에 넣었습니다. 그럼 내가 그걸 onPostExecute로 옮긴다 고? – user2128299
예,'Runtime' 명령어를'onPostExecute'로 옮기면'doInBackground'가 완료된 직후에 실행될 것입니다. –
감사합니다. 내 스크립트에 대해서는 왜 실행되지 않을지 알고 있습니까? – user2128299