Guest User

Untitled

a guest
Jan 15th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. [WebMethod]
  2. public byte[] GetNewVersion(string version)
  3. {
  4.  
  5.  
  6. string filename = @"~/dir/AppFile.apk";
  7. BinaryReader binReader = new
  8. BinaryReader(File.Open(Server.MapPath(filename), FileMode.Open,FileAccess.Read));
  9. binReader.BaseStream.Position = 0;
  10. byte[] binFile =
  11. binReader.ReadBytes(Convert.ToInt32(binReader.BaseStream.Length));
  12. binReader.Close();
  13. return binFile;
  14. }
  15.  
  16. [WebMethod]
  17. public void PutFile(byte[] buffer, string filename)
  18. {
  19. BinaryWriter binWriter = new
  20. BinaryWriter(File.Open(Server.MapPath(filename), FileMode.CreateNew, FileAccess.ReadWrite));
  21. binWriter.Write(buffer);
  22. binWriter.Close();
  23. }
  24.  
  25. response = envelope.getResponse();
  26. byte[] b = response.toString().getBytes();
  27. filePath = Environment.getExternalStorageDirectory().getPath() + "/download/" + "VersionUpdatee" + ".apk";
  28.  
  29. File file = new File(filePath);
  30.  
  31. //If already file there so delete it.
  32. if (file.exists())
  33. file.delete();
  34.  
  35. file.getParentFile().mkdirs();
  36. file.createNewFile();
  37.  
  38. BufferedOutputStream objectOut = new BufferedOutputStream(new FileOutputStream(file));
  39. objectOut.write(b);
  40. objectOut.close();
  41.  
  42. filePath = Environment.getExternalStorageDirectory().getPath() + "/download/" + "VersionUpdatee" + ".apk";
  43. String command = "chmod " + "666" + " " + filePath;
  44. Runtime runtime = Runtime.getRuntime();
  45. try {
  46. runtime.exec(command);
  47. } catch (IOException e) {
  48.  
  49. e.printStackTrace();
  50. }
  51.  
  52. Intent intent = new Intent(Intent.ACTION_VIEW);
  53. intent.setDataAndType(Uri.fromFile(new File(filePath)), "application/vnd.android.package-archive");
  54. startActivity(intent);
Add Comment
Please, Sign In to add comment