parryworld / react-native-appupdate

Update apk and update from app store in React Native.
MIT License
85 stars 36 forks source link

apk安装的时候,系统没有授权未知安装来源,直接就中止了 #4

Open banli17 opened 7 years ago

dongchuanlei commented 6 years ago

判断一下 @ReactMethod public void installApk(String file) { String cmd = "chmod 777 " + file; try { Runtime.getRuntime().exec(cmd); } catch (Exception e) { e.printStackTrace(); } Intent intent = new Intent(Intent.ACTION_VIEW); if (Build.VERSION.SDK_INT>=24) { Uri contentUri = FileProvider.getUriForFile(getCurrentActivity(), getCurrentActivity().getApplicationContext().getPackageName() + ".provider", new File(file)); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setDataAndType(contentUri, "application/vnd.android.package-archive"); } else { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.parse("file://" + file), "application/vnd.android.package-archive"); } getCurrentActivity().startActivity(intent); }

mengmengdadetonghua commented 6 years ago

按照你的写法 还是报错 new File(file) 找不到符号 不知道什么原因