当前位置: 首页>>代码示例>>Java>>正文


Java CustomTabsIntent.launchUrl方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:CustomTabActivityHelper.java

示例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);
    }
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:18,代码来源:ActivityHelper.java

示例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());
    }

}
 
开发者ID:Vavassor,项目名称:Tusky,代码行数:30,代码来源:LinkHelper.java

示例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();
}
 
开发者ID:alphater,项目名称:garras,代码行数:17,代码来源:LicensesDialog.java

示例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);
    }
}
 
开发者ID:saschpe,项目名称:android-customtabs,代码行数:32,代码来源:CustomTabsHelper.java

示例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);
}
 
开发者ID:Chan4077,项目名称:StudyBuddy,代码行数:21,代码来源:SettingsActivity.java

示例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);
  }
}
 
开发者ID:tomoya92,项目名称:android-apps,代码行数:26,代码来源:CustomTabActivityHelper.java

示例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));
}
 
开发者ID:sakebook,项目名称:CustomTabsSample,代码行数:20,代码来源:SessionActivity.java

示例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));
}
 
开发者ID:sakebook,项目名称:CustomTabsSample,代码行数:19,代码来源:RemoteViewActivity.java

示例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;
        }


    }
 
开发者ID:salRoid,项目名称:Filmy,代码行数:24,代码来源:AboutActivity.java

示例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);
    }
}
 
开发者ID:akexorcist,项目名称:Android-SleepingForLess,代码行数:17,代码来源:ExternalBrowserUtility.java

示例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;
    }

}
 
开发者ID:salRoid,项目名称:Filmy,代码行数:22,代码来源:AboutActivity.java

示例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 + "'");
  }
}
 
开发者ID:Azure,项目名称:azure-mobile-engagement-app-android,代码行数:33,代码来源:CustomTabActivityHelper.java

示例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));
}
 
开发者ID:Make-A-Pede,项目名称:Make-A-Pede-Android-App,代码行数:17,代码来源:HomeActivity.java

示例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));
}
 
开发者ID:Make-A-Pede,项目名称:Make-A-Pede-Android-App,代码行数:11,代码来源:HomeActivity.java


注:本文中的android.support.customtabs.CustomTabsIntent.launchUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。