I am new to creating android application and I am working on project where I need to download and install application from Android Playstore and install without user input. The only solution i could find is to launch market app and then click install button manually. But I want to install automatically. Is there any better way?
Installation of apps without user input isn't possible, but you can ask user to install it by following intent:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(GOOGLE_PLAY_APP_URL)); startActivity(intent);
And for check if app is already installed you can use something like this:
public static boolean isInstalled(Context context, String packageName) {
PackageManager pkgManager = context.getPackageManager();
Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resInfo = pkgManager.queryIntentActivities(launchIntent, 0);
for (int i = 0; i < resInfo.size(); i++) {
ResolveInfo ri = resInfo.get(i);
String pkgName = ri.activityInfo.packageName;
if (pkgName.contains(packageName)) {
return true;
}
}
return false;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.