Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [WebMethod]
- public byte[] GetNewVersion(string version)
- {
- string filename = @"~/dir/AppFile.apk";
- BinaryReader binReader = new
- BinaryReader(File.Open(Server.MapPath(filename), FileMode.Open,FileAccess.Read));
- binReader.BaseStream.Position = 0;
- byte[] binFile =
- binReader.ReadBytes(Convert.ToInt32(binReader.BaseStream.Length));
- binReader.Close();
- return binFile;
- }
- [WebMethod]
- public void PutFile(byte[] buffer, string filename)
- {
- BinaryWriter binWriter = new
- BinaryWriter(File.Open(Server.MapPath(filename), FileMode.CreateNew, FileAccess.ReadWrite));
- binWriter.Write(buffer);
- binWriter.Close();
- }
- response = envelope.getResponse();
- byte[] b = response.toString().getBytes();
- filePath = Environment.getExternalStorageDirectory().getPath() + "/download/" + "VersionUpdatee" + ".apk";
- File file = new File(filePath);
- //If already file there so delete it.
- if (file.exists())
- file.delete();
- file.getParentFile().mkdirs();
- file.createNewFile();
- BufferedOutputStream objectOut = new BufferedOutputStream(new FileOutputStream(file));
- objectOut.write(b);
- objectOut.close();
- filePath = Environment.getExternalStorageDirectory().getPath() + "/download/" + "VersionUpdatee" + ".apk";
- String command = "chmod " + "666" + " " + filePath;
- Runtime runtime = Runtime.getRuntime();
- try {
- runtime.exec(command);
- } catch (IOException e) {
- e.printStackTrace();
- }
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.fromFile(new File(filePath)), "application/vnd.android.package-archive");
- startActivity(intent);
Add Comment
Please, Sign In to add comment