저는 Android 개발에 처음으로 익숙해 졌으므로 기본 응용 프로그램으로 시작할 것이라고 생각했습니다. 버튼을 누르면 코드에 기록 된 위치로 파일을 복사합니다 (아래 코드 참조). 설치 버튼을 누르면 파일이 그 위치에 복사 될 때 "파일을 복사하는 동안 성공적으로 설치되었거나 오류가 발생했습니다"라는 토스트 메시지가 나타납니다. 어떻게 구현할 수 있습니까?파일 복사 후 성공 메시지 표시
public class TrialActivity extends Activity {
private ProgressDialog progressDialog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
runDialog(5);
}
private void runDialog(final int seconds)
{
progressDialog = ProgressDialog.show(this, "Please Wait...", "unpacking patch in progress");
new Thread(new Runnable(){
public void run(){
try {
Thread.sleep(seconds * 1000);
progressDialog.dismiss();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
((Button)findViewById(R.id.button1)).setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramView)
{
}
{
InputStream in = null;
OutputStream out = null;
String filename="savegame.bin";
try {
in = getResources().openRawResource(R.raw.savegame);
out = new FileOutputStream("/sdcard/Android/data/files/" + filename);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(Exception e) {
Log.e("tag", e.getMessage());
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
}
);
}
}
이 링크 ... HTTP를 참조하십시오 //stackoverflow.com/questions/12406106/display-android-toast-success-unsuccessful-message/12406455#12406455 –
You 당신의 괄호'{}'를 완전히 잃어 버렸습니다 ... 당신은'OnClickListener' 안에있는 두 개의 copy 메소드를 가지고 있지만'onClick()'메소드의 일부는 아닙니다 ... 어쨌든, 여러분이 복사 한 파일을 복사하면 원래 크기와 복사 된 파일의 크기를 비교할 수 있습니다. – Sam