Commit 7bd62e93 authored by 李增强's avatar 李增强

m

parent 3cc749ff
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.qiaomeng.flutter.request_install_packages"> xmlns:tools="http://schemas.android.com/tools"
package="com.qiaomeng.flutter.request_install_packages">
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES"
tools:ignore="ProtectedPermissions" />
</manifest> </manifest>
...@@ -103,10 +103,29 @@ public class Handler { ...@@ -103,10 +103,29 @@ public class Handler {
} }
}; };
Uri packageURI = Uri.parse("package:" + mActivity.getPackageName()); // ActivityCompat.requestPermissions(mActivity,new String[]{Manifest.permission.REQUEST_INSTALL_PACKAGES},REQUESE_CODE);
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageURI);
//系统将打开是未知来源应用的管理列表,需要用户手动设置未知来源应用安装权限 Thread thread = new Thread(new Runnable() {
mActivity.startActivityForResult(intent, REQUESE_CODE); @Override
public void run() {
Uri packageURI = Uri.parse("package:" + mActivity.getPackageName());
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageURI);
//系统将打开是未知来源应用的管理列表,需要用户手动设置未知来源应用安装权限
mActivity.startActivityForResult(intent, REQUESE_CODE);
}
});
thread.start();
}
public void installApk(String path){
Intent var5 = new Intent("android.intent.action.VIEW");
var5.setDataAndType(Uri.parse(path), "apk");
try {
mActivity.startActivity(var5);
} catch (Exception var8) {
}
} }
......
...@@ -52,6 +52,8 @@ public class RequestInstallPackagesPlugin implements FlutterPlugin, MethodCallHa ...@@ -52,6 +52,8 @@ public class RequestInstallPackagesPlugin implements FlutterPlugin, MethodCallHa
handler.request(result); handler.request(result);
} else if (call.method.equals("check")) { } else if (call.method.equals("check")) {
handler.check(result); handler.check(result);
} else if (call.method.equals("installApk")) {
handler.installApk((String) call.argument("path"));
} else { } else {
result.notImplemented(); result.notImplemented();
} }
......
...@@ -20,4 +20,11 @@ class RequestInstallPackages { ...@@ -20,4 +20,11 @@ class RequestInstallPackages {
} }
return _channel.invokeMethod('check'); return _channel.invokeMethod('check');
} }
static Future<bool> installApk(String path) {
if (!Platform.isAndroid) {
return Future.value(true);
}
return _channel.invokeMethod('installApk', {"path": path});
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment