Advertisement
playfulgod

Untitled

Sep 10th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.92 KB | None | 0 0
  1. package com.techygeek.installer;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.view.Menu;
  8. import android.view.MenuInflater;
  9. import android.view.MenuItem;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.Toast;
  13.  
  14. import java.io.IOException;
  15. import java.io.OutputStreamWriter;
  16.  
  17. public class MainActivity extends Activity {
  18.  
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.activity_main);
  23.  
  24. // Backup button
  25. final Button button_backup = (Button) findViewById(R.id.button_backup);
  26. button_backup.setOnClickListener(new View.OnClickListener() {
  27.  
  28. /* Checks if external storage is available for read and write /
  29. public boolean isExternalStorageWritable() {
  30. String state = Environment.getExternalStorageState();
  31. if (Environment.MEDIA_MOUNTED.equals(state)) {
  32. return true;
  33. }
  34. return false;
  35. }*/
  36.  
  37. @Override
  38. public void onClick(View v) {
  39. Runtime runtime = Runtime.getRuntime();
  40. Process proc = null;
  41. OutputStreamWriter osw = null;
  42.  
  43. String command = "tar -cf /external_sd/MyDataBackup/data.tar /data";
  44.  
  45. try { // Run Script
  46.  
  47. proc = runtime.exec("su");
  48. osw = new OutputStreamWriter(proc.getOutputStream());
  49. osw.write(command);
  50. osw.flush();
  51. osw.close();
  52.  
  53. Context context = getApplicationContext();
  54. CharSequence text = "Backing Data up!";
  55. int duration = Toast.LENGTH_LONG;
  56.  
  57. Toast toast = Toast.makeText(context, text, duration);
  58. toast.show();
  59.  
  60. } catch (IOException e) {
  61. // TODO Auto-generated catch block
  62. e.printStackTrace();
  63. }
  64. }
  65. });
  66.  
  67. // Restore button
  68. final Button button_restore = (Button) findViewById(R.id.button_restore);
  69. button_restore.setOnClickListener(new View.OnClickListener() {
  70.  
  71. @Override
  72. public void onClick(View v) {
  73. Runtime runtime = Runtime.getRuntime();
  74. Process proc = null;
  75. OutputStreamWriter osw = null;
  76.  
  77. String command ="tar -xf /external_sd/MyDataBackup/data.tar -C /";
  78.  
  79. try { // Run Script
  80.  
  81. proc = runtime.exec("su");
  82. osw = new OutputStreamWriter(proc.getOutputStream());
  83. osw.write(command);
  84. osw.flush();
  85. osw.close();
  86.  
  87. Context context = getApplicationContext();
  88. CharSequence text = "Restoring Data!";
  89. int duration = Toast.LENGTH_LONG;
  90.  
  91. Toast toast = Toast.makeText(context, text, duration);
  92. toast.show();
  93.  
  94. } catch (IOException e) {
  95. // TODO Auto-generated catch block
  96. e.printStackTrace();
  97. }
  98. }
  99. });
  100.  
  101. // Install Recovery Button
  102. final Button button_installrec = (Button) findViewById(R.id.button_installrec);
  103. button_installrec.setOnClickListener(new View.OnClickListener() {
  104.  
  105. @Override
  106. public void onClick(View v) {
  107. Runtime runtime = Runtime.getRuntime();
  108. Process proc = null;
  109. OutputStreamWriter osw = null;
  110.  
  111. String command = "wget -P /data/local/tmp/ http://unleashedprepaids.com/upload/devs/playfulgod/phones/LG/MS770/l0-cwm.lok && dd if=/data/local/tmp/l0-cwm.lok of=/dev/block/platform/msm_sdcc.1/by-name/recovery && rm /data/local/tmp/l0-cwm.lok";
  112.  
  113. try { // Run Script
  114.  
  115. proc = runtime.exec("su");
  116. osw = new OutputStreamWriter(proc.getOutputStream());
  117. osw.write(command);
  118. osw.flush();
  119. osw.close();
  120.  
  121. Context context = getApplicationContext();
  122. CharSequence text = "Downloading and Installing Recovery";
  123. int duration = Toast.LENGTH_SHORT;
  124.  
  125. Toast toast = Toast.makeText(context, text, duration);
  126. toast.show();
  127.  
  128. } catch (IOException ex) {
  129. // TODO Auto-generated catch block
  130. ex.printStackTrace();
  131. }
  132. }
  133. });
  134.  
  135. // Reboot to Recovery Button
  136. final Button button_rebootrec = (Button) findViewById(R.id.button_rebootrec);
  137. button_rebootrec.setOnClickListener(new View.OnClickListener() {
  138.  
  139. @Override
  140. public void onClick(View v) {
  141. Runtime runtime = Runtime.getRuntime();
  142. Process proc = null;
  143. OutputStreamWriter osw = null;
  144.  
  145. String command = "/system/bin/reboot recovery";
  146.  
  147. try { // Run Script
  148.  
  149. proc = runtime.exec("su");
  150. osw = new OutputStreamWriter(proc.getOutputStream());
  151. osw.write(command);
  152. osw.flush();
  153. osw.close();
  154.  
  155. Context context = getApplicationContext();
  156. CharSequence text = "Rebooting to Recovery";
  157. int duration = Toast.LENGTH_SHORT;
  158.  
  159. Toast toast = Toast.makeText(context, text, duration);
  160. toast.show();
  161.  
  162. } catch (IOException ex) {
  163. // TODO Auto-generated catch block
  164. ex.printStackTrace();
  165. }
  166. }
  167. });
  168. }
  169.  
  170. @Override
  171. public boolean onCreateOptionsMenu(Menu menu) {
  172. // Inflate the menu; this adds items to the action bar if it is present.
  173. MenuInflater inflater = getMenuInflater();
  174. inflater.inflate(R.menu.main, menu);
  175. return true;
  176. }
  177.  
  178. public boolean onOptionsItemSelected(MenuItem item) {
  179. switch (item.getItemId()) {
  180. case R.id.about:
  181. startActivity(new Intent(this, About.class));
  182. return true;
  183. case R.id.quit:
  184. finish();
  185. return true;
  186. default:
  187. return super.onOptionsItemSelected(item);
  188. }
  189. }
  190.  
  191. /* private boolean checkForDirectory()
  192. {
  193. boolean cardstate = true;
  194.  
  195. String state = Environment.getExternalStorageState();
  196.  
  197. if (Environment.MEDIA_BAD_REMOVAL.equals(state)) {
  198. cardstate = false;
  199. runDialog("Memory Card was removed before it was unmounted");
  200. }
  201. else if (Environment.MEDIA_CHECKING.equals(state)) {
  202. runDialog("Memory Card is present and being disk-checked");
  203. }
  204. else if (Environment.MEDIA_MOUNTED.equals(state)) {
  205. cardstate = true;
  206. //runDialog("Memory Card is present and mounted with read/write access");
  207. }
  208. else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
  209. runDialog("Memory Card is present and mounted with readonly access");
  210. }
  211. else if (Environment.MEDIA_NOFS.equals(state)) {
  212. cardstate = false;
  213. runDialog("Memory Card is present but is blank or using unsupported file system");
  214. }
  215. else if (Environment.MEDIA_REMOVED.equals(state)) {
  216. cardstate = false;
  217. runDialog("Memory Card is not present");
  218. }
  219. else if (Environment.MEDIA_SHARED.equals(state)) {
  220. cardstate = false;
  221. runDialog("Memory Card is present but shared via USB mass storage");
  222. }
  223. else if (Environment.MEDIA_UNMOUNTABLE.equals(state)) {
  224. cardstate = false;
  225. runDialog("Memory Card is present but cannot be mounted");
  226. }
  227. else if (Environment.MEDIA_UNMOUNTED.equals(state)) {
  228. cardstate = false;
  229. runDialog("Memory Card is present but not mounted");
  230. }
  231.  
  232. File dir = new File(Environment.getExternalStorageDirectory() + "/MyDataBackup");
  233. if(dir.exists() && dir.isDirectory())
  234. {
  235. System.out.println("Folder exists");
  236. }
  237. else
  238. {
  239. String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
  240. File myNewFolder = new File(extStorageDirectory + "/MyDataBackup");
  241. myNewFolder.mkdir();
  242. System.out.println("Folder MyDataBackup created ");
  243. }
  244. return cardstate;
  245. }*/
  246.  
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement