我正在尝试从Google Play安装应用。我了解到,打开Google Play商店网址后,它会打开Google Play,当我按“后退”按钮时,活动将恢复。
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(appURL));
marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(marketIntent);
当我回到活动中时,我尝试称其为 onResume()
以检查是否已安装该应用程序,但收到错误消息:
@Override
protected void onResume() {
super.onResume();
boolean installed = false;
while (!installed) {
installed = appInstalledOrNot(APPPACKAGE);
if (installed) {
Toast.makeText(this, "App installed", Toast.LENGTH_SHORT).show();
}
}
}
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed ;
}
错误如下:
E / AndroidRuntime(796):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.appinstaller / com.example.appinstaller.MainActivity}:android.content.ActivityNotFoundException:未找到处理意图的活动{act = android .intent.action.VIEW dat = market:// details?id = com.package.name flg = 0x40080000}
我想活动是onPause()
。有没有更好的方法来实现它?我正在尝试检查应用程序是否已完成安装。