-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApplicationUpdate.java
149 lines (129 loc) · 4.93 KB
/
ApplicationUpdate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.[YOUR-DOMAIN-NAME].android;
import com.[YOUR-DOMAIN-NAME].android.DownloadManager;
import java.io.InputStream;
import java.security.Signature;
import android.app.Activity;
import android.app.AlertDialog;
import android.net.Uri;
import android.os.Bundle;
//foo: added
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.util.ByteArrayBuffer;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
//foo: added-end
import org.apache.http.util.ByteArrayBuffer;
import android.util.Log;
public class ApplicationUpdate extends Activity implements OnClickListener {
ProgressDialog dialog;
int increment;
int val;
private final static String PATH = "/data/data/com.[YOUR-DOMAIN-NAME].android/";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.application_update);
Button startbtn = (Button) findViewById(R.id.startbtn);
startbtn.setOnClickListener(this);
Log.i("sys","system property:"+System.getProperties() );
Log.i("","STORAGE DIRECTORY: "+ Environment.getExternalStorageDirectory() );
Log.i("CREATE","initialize everything.....");
}
public void onClick(View view) {
dialog = new ProgressDialog(this);
dialog.setCancelable(true);
dialog.setMessage("Downloading Updates...");
Log.i("ONLCLICK","start downloading...");
// set the progress to be horizontal
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// reset the bar to the default value of 0
dialog.setProgress(0);
DownloadManager.DownloadFromUrl("http://www.webdunnit.com/", "home_page.jpg");
val = DownloadManager.M_statusProgress;
dialog.setMax(val);
Log.i("ONLCLICK","update the progress bar..");
//end test
//dialog.setMax(maximum);
// display the progressbar
dialog.show();
// create a thread for updating the progress bar
Thread background = new Thread (new Runnable() {
public void run() {
try {
// enter the code to be run while displaying the progressbar.
//
// increment the progress bar:
// So keep running until the progress value reaches maximum value
// ImageManager.DownloadFromUrl("http://www.webdunnit.com/", "bhome.jpg");
while(dialog.getProgress() <= DownloadManager.M_statusProgress) {
// while (dialog.getProgress() <= dialog.getMax()) {
// wait 500ms between each update
Thread.sleep(500);
// active the update handler
progressHandler.sendMessage(progressHandler.obtainMessage());
}
} catch (java.lang.InterruptedException e) {
// if something fails do something smart
Log.i("THREAD:","Something wrong has happened....");
}
}
});
// start the background thread
background.start();
}
// handler for the background updating
Handler progressHandler = new Handler() {
public void handleMessage(Message msg) {
dialog.incrementProgressBy(val);
if(dialog.getProgress() == dialog.getMax())
{
dialog.dismiss();
// alertbox("Install Update","This will install updates on your device.");
}
/*
if(dialog.getProgress() >= 100) {
dialog.dismiss();
}else {
dialog.incrementProgressBy(increment);
}*/
}
};
protected void alertbox(String title, String mymessage)
{
try {
new AlertDialog.Builder(this)
.setMessage(mymessage)
.setTitle(title)
.setCancelable(true)
.setNeutralButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
String fileName = "/data/data/com.[YOUR-DOMAIN-NAME].android/xmas.jpg";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
}
})
.show();
}catch(Exception e ){
e.printStackTrace();
}
}