/**
* 改变文件权限
*/
public void changeModAndInstall() {
File destFile = new File(downloadpath + apkName);
String command = "chmod 777 " + destFile.getAbsolutePath();
Runtime runtime = Runtime.getRuntime();
try {
Process proc = runtime.exec(command);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 安装
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
File f = new File(downloadpath + apkName);
if (f.exists()) {
intent.setDataAndType(Uri.fromFile(f),
"application/vnd.android.package-archive");
startActivity(intent);
}
}
/**
*
* @param path
* 下载后保存apk的路径
* @param apkName
* apk的名称
* @param data
* 下载的数据
*/
public void saveAPK(String path, String apkName, byte[] data) {
String installPath = path + apkName;
File file = new File(installPath);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
FileOutputStream fis = new FileOutputStream(file);
fis.write(data);
fis.close();
Log.i("info", "保存:" + installPath + data.length);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 读取流信息
*/
public static byte[] read(InputStream inStream) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
inStream.close();
return outStream.toByteArray();
}
/**
* 检查 本地是否安装了 被调起的软件 (鑫财通)
* @param packageName
* @return
*/
public boolean checkApkExist(String packageName) {
try {
ApplicationInfo info = this.getPackageManager().getApplicationInfo(
packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
* 改变文件权限
*/
public void changeModAndInstall() {
File destFile = new File(downloadpath + apkName);
String command = "chmod 777 " + destFile.getAbsolutePath();
Runtime runtime = Runtime.getRuntime();
try {
Process proc = runtime.exec(command);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 安装
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
File f = new File(downloadpath + apkName);
if (f.exists()) {
intent.setDataAndType(Uri.fromFile(f),
"application/vnd.android.package-archive");
startActivity(intent);
}
}
/**
*
* @param path
* 下载后保存apk的路径
* @param apkName
* apk的名称
* @param data
* 下载的数据
*/
public void saveAPK(String path, String apkName, byte[] data) {
String installPath = path + apkName;
File file = new File(installPath);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
FileOutputStream fis = new FileOutputStream(file);
fis.write(data);
fis.close();
Log.i("info", "保存:" + installPath + data.length);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 读取流信息
*/
public static byte[] read(InputStream inStream) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
inStream.close();
return outStream.toByteArray();
}
/**
* 检查 本地是否安装了 被调起的软件 (鑫财通)
* @param packageName
* @return
*/
public boolean checkApkExist(String packageName) {
try {
ApplicationInfo info = this.getPackageManager().getApplicationInfo(
packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}