怎么安装瑞士军刀??
来源:互联网 发布:java获取网络时间 编辑:程序博客网 时间:2024/06/10 07:52
一、判断Android系统中是否有瑞士军刀的应用。
第一种方法:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(
"com.utooo.android.knife.free",
"com.utooo.android.knife.free.AndroidRuler"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
startActivity(intent);
如果抛出异常,就说明此系统中没有瑞士军刀的应用。
第二种方法:
PackageInfo packageInfo = null;
try {
packageInfo = this.getPackageManager().getPackageInfo(
"com.utooo.android.knife.free", 0);
} catch (NameNotFoundException e1) {
e1.printStackTrace();
}
如果packageInfo==null,就说明Android系统中没有瑞士军刀的应用。
二、瑞士军刀的apk文件在assets下面,名字为:ruishi_plugin.apk
三、case R.id.ImageButton3:// GPS服务
{
// 使用瑞士军刀标志的服务
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(
"com.utooo.android.knife.free",
"com.utooo.android.knife.free.AndroidRuler"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
try {
startActivity(intent);
} catch (Exception e) {
// new AlertDialog.Builder(Function.this).setTitle("警告!")
// .setMessage("超级瑞士军刀(版本1.1.1)应用的支持")
// .setPositiveButton("确定", null).show();
installApk("ruishi_plugin.apk");
}
// Intent intent = new Intent(this, GpsStatusActivity.class);
// this.startActivity(intent);
}
break;
public void installApk(String apkName) {
FileOutputStream fos;
InputStream is;
try {
is = getAssets().open(apkName);
fos = openFileOutput(apkName, MODE_WORLD_WRITEABLE);
byte[] bytes = new byte[512];
int i = -1;
while ((i = is.read(bytes)) > 0) {
fos.write(bytes);
}
fos.close();
is.close();
} catch (IOException e1) {
e1.printStackTrace();
}
String apkPath = "/data/data/" + this.getPackageName() + "/files";
File file = new File(apkPath, apkName);
String permission = "777";
try {
String command = "chmod " + permission + " "
+ file.getAbsolutePath();
Runtime runtime = Runtime.getRuntime();
runtime.exec(command);
} catch (IOException e) {
e.printStackTrace();
}
Intent intentInstall = new Intent();
intentInstall.setAction(android.content.Intent.ACTION_VIEW);
intentInstall.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
intentInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentInstall);
}
- 怎么安装瑞士军刀??
- 瑞士军刀
- http协议监测调试的“瑞士军刀” LiveHttpHeaders 安装使用教程
- 瑞士军刀起源
- PowerShell 瑞士军刀
- 瑞士军刀---valgrind
- MySQL 瑞士军刀
- Jodd瑞士军刀
- netcat 瑞士军刀
- Python科学计算的瑞士军刀——Anaconda 安装与配置
- Python科学计算的瑞士军刀——Anaconda 安装与配置
- Python科学计算的瑞士军刀——Anaconda 安装与配置
- Python科学计算的瑞士军刀——Anaconda 安装与配置
- netcat(瑞士军刀)的使用
- 瑞士军刀──Valgrind
- nc瑞士军刀常用命令
- XMAL瑞士军刀 - IValueConverter
- 瑞士军刀NC用法
- protobuf如何用proto文件导出C++代码文件及链接protobuf静态库问题
- light oj 1011 - Marriage Ceremonies (状态压缩+记忆化搜索)
- Linux0.11进程切换和TSS结构
- 连接VPN网络
- Concrete Mathematics - Recurrent Problems - (3)
- 怎么安装瑞士军刀??
- 求方程的值——牛顿迭代法
- 【Opengl es】开始学习opengl es,记录学习历程与心得。
- 创建型模式——工厂模式
- Android_Android开发学习资源
- 核心的基本功能
- C#学习笔记(1)
- ORA-02069: global_names parameter must be set to TRUE for this operation
- JAVA多线程与并发学习总结(转)