您也许可以玩弄这个并让它在您的应用程序中工作。这是我的示例,因为谷歌没有将他们最近的日历应用程序提供给早期版本,我不得不在我的应用程序中使用它。它检查用户是否拥有应用程序,如果没有,则在应用程序描述页面上启动 Google Play 商店,以便他们可以下载它以使用应用程序中的功能。希望这可以帮助!
boolean installed = appInstalledOrNot("com.google.android.calendar");
if(installed)
{
Intent launchCalendar = new Intent();
String deviceVersion = Build.VERSION.RELEASE;
String[] versions = deviceVersion.split("\\.");
ComponentName googleCalendar = new ComponentName("com.google.android.calendar", "com.android.calendar.LaunchActivity");
if (Integer.valueOf(versions[0]) > 2) {
if (Integer.valueOf(versions[1]) > 2) {
//Froyo or greater (mind you I just tested this on CM7 and the less than froyo one worked so it depends on the phone...)
googleCalendar = new ComponentName("com.google.android.calendar", "com.android.calendar.LaunchActivity");
}
} else {
//less than Froyo
googleCalendar = new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity");
}
launchCalendar.setComponent(googleCalendar);
startActivity(launchCalendar);
} else {
Intent googleCalendarInstall = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.calendar"));
startActivity(googleCalendarInstall);
Toast.makeText(DatesActivity.this, "Please install the Google Calendar app in order to use the calendar functionality.", Toast.LENGTH_LONG).show();
}
finish();
}
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;
}