本文整理匯總了Java中android.support.customtabs.CustomTabsIntent.launchUrl方法的典型用法代碼示例。如果您正苦於以下問題:Java CustomTabsIntent.launchUrl方法的具體用法?Java CustomTabsIntent.launchUrl怎麽用?Java CustomTabsIntent.launchUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.customtabs.CustomTabsIntent
的用法示例。
在下文中一共展示了CustomTabsIntent.launchUrl方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: openCustomTab
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
/**
* Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView.
*
* @param activity The host activity.
* @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available.
* @param uri the Uri to be opened.
* @param fallback a CustomTabFallback to be used if Custom Tabs is not available.
*/
public static void openCustomTab(Activity activity,
CustomTabsIntent customTabsIntent,
Uri uri,
CustomTabFallback fallback) {
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
//If we cant find a package name, it means theres no browser that supports
//Chrome Custom Tabs installed. So, we fallback to the webview
if (packageName == null) {
if (fallback != null) {
fallback.openUri(activity, uri);
}
} else {
customTabsIntent.intent.setPackage(packageName);
customTabsIntent.launchUrl(activity, uri);
}
}
示例2: startCustomTab
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
public static void startCustomTab(@NonNull Activity context, @NonNull Uri url) {
String packageNameToUse = CustomTabsHelper.getPackageNameToUse(context);
if (packageNameToUse != null) {
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.setToolbarColor(ViewHelper.getPrimaryColor(context))
.setShowTitle(true)
.build();
customTabsIntent.intent.setPackage(packageNameToUse);
try {
customTabsIntent.launchUrl(context, url);
} catch (ActivityNotFoundException ignored) {
openChooser(context, url, true);
}
} else {
openChooser(context, url, true);
}
}
示例3: openLinkInCustomTab
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
/**
* tries to open a link in a custom tab
* falls back to browser if not possible
*
* @param uri the uri to open
* @param context context
*/
public static void openLinkInCustomTab(Uri uri, Context context) {
boolean lightTheme = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("lightTheme", false);
int toolbarColor = ContextCompat.getColor(context, lightTheme ? R.color.custom_tab_toolbar_light : R.color.custom_tab_toolbar_dark);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(toolbarColor);
CustomTabsIntent customTabsIntent = builder.build();
try {
String packageName = CustomTabsHelper.getPackageNameToUse(context);
//If we cant find a package name, it means theres no browser that supports
//Chrome Custom Tabs installed. So, we fallback to the webview
if (packageName == null) {
openLinkInBrowser(uri, context);
} else {
customTabsIntent.intent.setPackage(packageName);
customTabsIntent.launchUrl(context, uri);
}
} catch (ActivityNotFoundException e) {
Log.w("URLSpan", "Activity was not found for intent, " + customTabsIntent.toString());
}
}
示例4: openCustomTabs
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
private void openCustomTabs(String url) {
if (null == getActivity()) return;
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
intentBuilder.setToolbarColor(Color.WHITE);
intentBuilder.setSecondaryToolbarColor(Color.BLACK);
intentBuilder.addDefaultShareMenuItem();
intentBuilder.setShowTitle(true);
intentBuilder.enableUrlBarHiding();
CustomTabsIntent customTabsIntent = intentBuilder.build();
String packageName = CustomTabsHelper.getPackageNameToUse(getActivity());
customTabsIntent.intent.setPackage(packageName);
customTabsIntent.launchUrl(getActivity(), Uri.parse(url));
dismissAllowingStateLoss();
}
示例5: openCustomTab
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
/**
* Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView
*
* @param context The host activity
* @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available
* @param uri the Uri to be opened
* @param fallback a CustomTabFallback to be used if Custom Tabs is not available
*/
public static void openCustomTab(final Context context,
final CustomTabsIntent customTabsIntent,
final Uri uri,
final CustomTabFallback fallback) {
String packageName = CustomTabsPackageHelper.getPackageNameToUse(context);
//If we cant find a package name, it means there's no browser that supports
//Chrome Custom Tabs installed. So, we fallback to the web-view
if (packageName == null) {
if (fallback != null) {
fallback.openUri(context, uri);
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
customTabsIntent.intent
.putExtra(Intent.EXTRA_REFERRER,
Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + context.getPackageName()));
}
customTabsIntent.intent.setPackage(packageName);
customTabsIntent.launchUrl(context, uri);
}
}
示例6: onOptionsItemSelected
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case android.R.id.home:
startActivity(new Intent(getActivity(), SettingsActivity.class));
return true;
case R.id.action_send_feedback:
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
builder.addDefaultShareMenuItem();
final CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(getContext(), Uri.parse(sendFeedbackUrl));
return true;
case R.id.action_help:
// TODO: Add some stuff
return true;
}
return super.onOptionsItemSelected(item);
}
示例7: openCustomTab
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
/**
* Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView.
*
* @param activity The host activity.
* @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available.
* @param uri the Uri to be opened.
* @param fallback a CustomTabFallback to be used if Custom Tabs is not available.
*/
public static void openCustomTab(Activity activity,
CustomTabsIntent customTabsIntent,
Uri uri,
CustomTabFallback fallback) {
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
//If we cant find a package name, it means theres no browser that supports
//Chrome Custom Tabs installed. So, we fallback to the webview
if (packageName == null) {
if (fallback != null) {
fallback.openUri(activity, uri);
}
} else {
customTabsIntent.intent.setPackage(packageName);
customTabsIntent.launchUrl(activity, uri);
}
}
示例8: launchCustomTabs
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
private void launchCustomTabs(String url) {
String packageName = CustomTabsHelper.getPackageNameToUse(this);
if (TextUtils.isEmpty(packageName)) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return;
}
Intent snsIntent = new Intent(this, SessionBroadcastReceiver.class);
PendingIntent snsPendingIntent = PendingIntent.getBroadcast(this, 121, snsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder(session)
.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary))
.setActionButton(ResourceUtil.createBitmap(SessionActivity.this, icons[0]), "SNS", snsPendingIntent)
.addMenuItem("toggle", createRemoteViewPendingIntent(this))
.setSecondaryToolbarViews(SessionBroadcastReceiver.createRemoteView(), ids, null)
.build();
customTabsIntent.intent.setPackage(packageName);
CustomTabsHelper.addKeepAliveExtra(this, customTabsIntent.intent);
customTabsIntent.launchUrl(this, Uri.parse(url));
}
示例9: launchCustomTabsWithBottomBar
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
private void launchCustomTabsWithBottomBar(String url) {
String packageName = CustomTabsHelper.getPackageNameToUse(this);
if (TextUtils.isEmpty(packageName)) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return;
}
Intent broadcastIntent = new Intent(this, BottombarBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 110, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
int[] ids = {R.id.twitter, R.id.line, R.id.facebook};
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.setSecondaryToolbarViews(createBottomBarRemoteView(), ids, pendingIntent)
.build();
customTabsIntent.intent.setPackage(packageName);
customTabsIntent.launchUrl(this, Uri.parse(url));
}
示例10: openGplus
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
public void openGplus(View view) {
String url = getString(R.string.ramzplus);
String url2 = getString(R.string.sajjuplus);
switch (view.getId()){
case R.id.gplus:
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorAccent));
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
break;
case R.id.gplus2:
CustomTabsIntent.Builder builder1 = new CustomTabsIntent.Builder();
builder1.setToolbarColor(ContextCompat.getColor(this, R.color.black));
CustomTabsIntent customTabsIntent1 = builder1.build();
customTabsIntent1.launchUrl(this, Uri.parse(url2));
break;
}
}
示例11: open
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
public void open(Activity activity, String url) {
Uri uri = Uri.parse(url);
Log.d("Check", "open: " + url);
if (isChromeCustomTabsSupported() &&
(!url.startsWith("http://www.akexorcist.com") &&
!url.startsWith("http://akexorcist.com"))) {
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder(mCustomTabsSession)
.setToolbarColor(activity.getResources().getColor(R.color.colorPrimary))
.setSecondaryToolbarColor(activity.getResources().getColor(R.color.colorPrimary))
.build();
customTabsIntent.launchUrl(activity, uri);
} else {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(intent);
}
}
示例12: openGithub
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
public void openGithub(View view) {
String url = getString(R.string.webianksgit);
String url2 = getString(R.string.salroidgit);
switch (view.getId()){
case R.id.github:
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(ContextCompat.getColor(this, R.color.black));
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
break;
case R.id.github2:
CustomTabsIntent.Builder builder1 = new CustomTabsIntent.Builder();
builder1.setToolbarColor(ContextCompat.getColor(this, R.color.black));
CustomTabsIntent customTabsIntent1 = builder1.build();
customTabsIntent1.launchUrl(this, Uri.parse(url2));
break;
}
}
示例13: openCustomTab
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
/**
* Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView.
*
* @param activity The host activity.
* @param uri The Uri to be opened.
* @param eventName The tracking eventName.
* @param eventTitle The tracking eventTitle.
* @param eventUrl The tracking eventUrl.
*/
public static final void openCustomTab(Activity activity, Uri uri, String eventName, String eventTitle,
String eventUrl)
{
try
{
final String packageName = CustomTabsHelper.getPackageNameToUse(activity);
final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(ContextCompat.getColor(activity, R.color.customTabColor));
builder.enableUrlBarHiding();
builder.setCloseButtonIcon(BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_arrow_back));
builder.setStartAnimations(activity, R.anim.slide_in_right, R.anim.slide_out_left);
builder.setExitAnimations(activity, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
final CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.setPackage(packageName);
customTabsIntent.launchUrl(activity, uri);
AzmeTracker.sendEventForCustomTab(activity, eventName, eventTitle, eventUrl);
}
catch (Exception exception)
{
Log.w(CustomTabActivityHelper.TAG, "Cannot launch the uri '" + uri + "'");
}
}
示例14: openWebsite
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
/**
* "Open Website" button click listener. Opens makeapede.com in a Chrome Custom Tab.
*
* @param view the clicked view
*/
public void openWebsite(View view) {
String url = "http://makeapede.com/";
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
builder.setToolbarColor(getColor(R.color.colorPrimary));
} else {
builder.setToolbarColor(0x91cf34);
}
customTabsIntent.launchUrl(this, Uri.parse(url));
}
示例15: onFbLinkActionClicked
import android.support.customtabs.CustomTabsIntent; //導入方法依賴的package包/類
public void onFbLinkActionClicked(View view) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
builder.setToolbarColor(getColor(R.color.colorPrimary));
} else {
builder.setToolbarColor(0x91cf34);
}
customTabsIntent.launchUrl(this, Uri.parse(fbLinkUrl));
}