问题
I am building a launcher app in flutter. But I couldn't add the uninstall feature. Please help me.
回答1:
Add a permission in manifest
file
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
add a package in your pubspec.yaml
file
intent: ^1.3.4
Use the below shown code and
To uninstall an app pass the package name to it. $packageName
is a variable
ex, some.app.id
android_intent.Intent()
..setAction(android_action.Action.ACTION_DELETE)
..setData(Uri.parse("package:$packageName"))
..startActivityForResult().then((data) {
print(data);
}, onError: (e) {
print(e);
});
using this a system generated popup will occur asking to uninstall the app.
So using this you can uninstall apps on your android device using flutter programmatically.
来源:https://stackoverflow.com/questions/55163793/how-to-uninstall-an-app-in-flutter-programatically