Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.support.annotation.NonNull; public class Main { public static void doItNow(@NonNull Context context, @NonNull String resource) { //If a link if (resource.startsWith("http")) { //If an app if (resource.startsWith("http://play.google.com/store/apps/") || resource.startsWith("https://play.google.com/store/apps/")) { String id = resource.substring(resource.indexOf('/', 32)); //Try, if the user does not have the store installed, launch as web link try { context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://" + id))); } catch (ActivityNotFoundException anfx) { context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(resource))); } } //Otherwise opened with the browser else { Uri uri = Uri.parse(resource); context.startActivity(new Intent(Intent.ACTION_VIEW, uri)); } } } }