private static final String TARGET_APP = "packageName";
ApplicationInfo info = null;
try{
//comprobamos que el usuario tenga la aplicación instalada
info = getActivity().getPackageManager().
getApplicationInfo(TARGET_APP, 0 );
} catch( PackageManager.NameNotFoundException e ){
}
//si NO tiene la aplicación instalada le redirigimos a uno de los 2 markets para que se la descargue
if(info == null){
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+ TARGET_APP)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="+ TARGET_APP)));
}
}else{
//si la tiene instalada la abrimos
Intent LaunchIntent = getActivity().getPackageManager().getLaunchIntentForPackage(TARGET_APP);
startActivity(LaunchIntent);
}
It works!
Roger Sala,
No hay comentarios:
Publicar un comentario