• 判断服务是否开启,应用是否安装,并安装应用


    //检查应用程序是否安装并安装应用程序
    
            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;
            }
  • 相关阅读:
    一个很实用的css3兼容工具很多属性可以兼容到IE6
    html5 canvas 填充渐变形状
    找到任何形状的中心-总结篇
    html canvas非正方旋转和缩放...写的大多是正方的有人表示一直看正方的看厌了
    把jQuery的类、插件封装成seajs的模块的方法
    那些年实用但被我忘掉javascript属性.onresize
    总有一些实用javascript的元素被人遗忘在角落-slice
    jquery(入门篇)无缝滚动
    html5 canvas旋转+缩放
    今天看到这篇新闻之后,决定休息一下咯
  • 原文地址:https://www.cnblogs.com/huidaoli/p/3947785.html
Copyright © 2020-2023  润新知