raha_jon
جمعه 10 مرداد 1393, 15:17 عصر
سلام و ادب من می خوام باتونی بزارم که با زدن اون برنامه آپدیت بشه
اینم کدم اما ارور میده
btnUPDATE.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
URL url = new URL("http://10.0.3.2/rt/app.apk");
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "app.apk");
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();//till here, it works fine - .apk is download to my sdcard in download file
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse(PATH+"app.apk"))
.setType("application/khodam.from_interne");
startActivity(promptInstall);
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Update error!", Toast.LENGTH_LONG).show();
}
و این دسترسی ها که لازم داره که در منیفست ارور هم می داد به اینا
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
که ارور ها را ctrl+1 رفع کردم
اینم کدم اما ارور میده
btnUPDATE.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
URL url = new URL("http://10.0.3.2/rt/app.apk");
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "app.apk");
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();//till here, it works fine - .apk is download to my sdcard in download file
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse(PATH+"app.apk"))
.setType("application/khodam.from_interne");
startActivity(promptInstall);
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Update error!", Toast.LENGTH_LONG).show();
}
و این دسترسی ها که لازم داره که در منیفست ارور هم می داد به اینا
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
که ارور ها را ctrl+1 رفع کردم