检查应用程序是否安装并安装应用程序
来源:互联网 发布:mac延长待机时间 编辑:程序博客网 时间:2024/05/23 01:46
看到别人写的copy过来的
如下代码啊:
//检查应用程序是否安装并安装应用程序
public boolean checkApkExist(Context context, String packageName) {
if (packageName == null || "".equals(packageName))
return false;
try {
ApplicationInfo info = context.getPackageManager()
.getApplicationInfo(packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
private void installVoiceServiceApk() {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
String type = "application/vnd.android.package-archive";
AssetManager assets = ProActivity.this.getAssets();
try {
//当文件比较大的时候不能用这个方法 来读取Stream ss.read(buffer) = -1 我的apk大小为5M
InputStream ss = assets.open(AsrService.apk");
//使用下面这个方法 没问题
InputStream is = getClass().getResourceAsStream(
"/assets/AsrService.apk");
FileOutputStream fos = ProActivity.this.openFileOutput(
"AsrService.apk", Context.MODE_PRIVATE
+ Context.MODE_WORLD_READABLE);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.flush();
is.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
File f = new File(ProActivity.this.getFilesDir().getPath()
+ "/AsrService.apk");
// String path = "file:///android_asset/ZXing.apk";
// File f = new File(path);
intent.setDataAndType(Uri.fromFile(f), type);
ProActivity.this.startActivity(intent);
}
//检查服务是否启动
private boolean isStartService(Context ctx) {
ActivityManager mActivityManager = (ActivityManager) ctx
.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> currentService = mActivityManager
.getRunningServices(100);
final String igrsClassName = "com.iflytek.asr.AsrService"; //serviceName
boolean b = igrsBaseServiceIsStart(currentService, igrsClassName);
return b;
}
private boolean igrsBaseServiceIsStart(
List<ActivityManager.RunningServiceInfo> mServiceList,
String className) {
for (int i = 0; i < mServiceList.size(); i++) {
if (className.equals(mServiceList.get(i).service.getClassName())) {
return true;
}
}
return false;
}
- 检查应用程序是否安装并安装应用程序
- android检查应用程序是否安装和检查服务是否启动的方法
- 安装loadrunner11,卸载360浏览器后提示“无效的应用程序路径!请检查应用程序是否存在!
- 广播监听手机中应用程序是否安装并卸载
- 检测应用程序是否已经安装
- Android之获取手机上已安装的所有的应用程序的信息,并判断是否安装了某应用程序(系统程序或非系统应用程序判断)
- Android 判断应用程序是否已安装
- Android判断应用程序是否安装和版本号
- android 判断应用程序是否已安装
- android 判断应用程序是否已安装
- android 判断应用程序是否已安装
- android 判断应用程序是否已安装
- Android判断应用程序是否安装和版本号
- Android判断应用程序是否安装和版本号
- Android判断应用程序是否已安装
- 判断一个应用程序是否已安装
- 判断四大应用程序组件是否安装
- android 判断应用程序是否已安装
- Embedded Linux Primer----嵌入式Linux基础教程--导论
- [ID 498155 daemon.error] Device PS1 AC UNAVAILABLE
- 23种设计模式之我见----创建型模式(1)
- SolrCloud介绍和应用
- 通过实例验证播放本地音乐MediaPlayer的reset函数并不会阻塞主线程
- 检查应用程序是否安装并安装应用程序
- Codeforces Round #114 (Div. 2 )A题
- Android开发(19)---常见dialog对话框的运用
- Struts2 动态Action的三种实现方法
- SolrJ使用教程
- 设计模式(一):开放封闭原则
- javaPNS进阶-高级推送技巧
- oracle [翻译]filter sevlet执行顺序,区别
- java设计模式 第二讲 单例模式