本文整理匯總了Java中android.support.customtabs.CustomTabsClient類的典型用法代碼示例。如果您正苦於以下問題:Java CustomTabsClient類的具體用法?Java CustomTabsClient怎麽用?Java CustomTabsClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CustomTabsClient類屬於android.support.customtabs包,在下文中一共展示了CustomTabsClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: warm
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
private Warmer warm(){
mCustomTabServiceConnection =
new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName,
CustomTabsClient customTabsClient) {
mCustomTabsClient = customTabsClient;
mCustomTabsClient.warmup(0);
mCustomTabsSession = mCustomTabsClient.newSession(null);
}
@Override
public void onServiceDisconnected(ComponentName name) {
mCustomTabsClient = null;
}
};
packageNameToUse = ChromePackageHelper.getPackageNameToUse(context);
if (packageNameToUse != null){
CustomTabsClient.bindCustomTabsService(context, packageNameToUse,
mCustomTabServiceConnection);
}
return this;
}
示例2: bindCustomTabsService
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
/**
* Binds the Activity to the Custom Tabs Service.
*
* @param activity the activity to be binded to the service.
*/
public final void bindCustomTabsService(Activity activity)
{
if (client != null)
{
return;
}
final String packageName = CustomTabsHelper.getPackageNameToUse(activity);
if (packageName == null)
{
return;
}
connection = new ServiceConnection(this);
CustomTabsClient.bindCustomTabsService(activity, packageName, connection);
}
示例3: createSession
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
/**
* Creates a {@link android.support.customtabs.CustomTabsSession custom tab session} for
* use with a custom tab intent, with optional callbacks and optional list of URIs that may
* be requested. The URI list should be ordered such that the most likely URI to be requested
* is first. If no custom tab supporting browser is available, this will return {@code null}.
*/
@WorkerThread
@Nullable
public CustomTabsSession createSession(
@Nullable CustomTabsCallback callbacks,
@Nullable Uri... possibleUris) {
CustomTabsClient client = getClient();
if (client == null) {
return null;
}
CustomTabsSession session = client.newSession(callbacks);
if (possibleUris != null && possibleUris.length > 0) {
List<Bundle> additionalUris = UriUtil.toCustomTabUriBundle(possibleUris, 1);
session.mayLaunchUrl(possibleUris[0], null, additionalUris);
}
return session;
}
示例4: bindService
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
/**
* Binds the Activity to the Custom Tabs Service.
* @param context the context to be binded to the service.
* @param origin the origin for the website that will be opened in the TWA.
*/
public void bindService(Context context, Uri origin) {
if (mClient != null) {
if (!origin.equals(mOrigin)) {
throw new IllegalArgumentException(
"Trying to bind to a different origin. Should call unbindService first");
}
// If Service is already bound, just fire the callback.
TwaSessionCallback twaSessionCallback = mTwaSessionCallback.get();
if (twaSessionCallback != null) twaSessionCallback.onTwaSessionReady();
return;
}
this.mOrigin = origin;
this.packageName = CustomTabsClient.getPackageName(
context, CHROME_PACKAGES, false);
Context applicationContext = context.getApplicationContext();
mConnection = new ServiceConnection(this);
CustomTabsClient.bindCustomTabsService(applicationContext, packageName, mConnection);
}
示例5: getChromePackages
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
private static List<String> getChromePackages(Context ctx) {
CustomTabsServiceConnection conn = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
};
String[] packages = {"com.android.chrome", "com.chrome.beta", "com.chrome.dev"};
List<String> availablePkgs = new ArrayList<>();
for (String pkg : packages) {
if (CustomTabsClient.bindCustomTabsService(ctx, pkg, conn)) {
availablePkgs.add(pkg);
}
}
return availablePkgs;
}
示例6: warm
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
private Warmer warm(){
mCustomTabServiceConnection =
new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName,
CustomTabsClient customTabsClient) {
mCustomTabsClient = customTabsClient;
mCustomTabsClient.warmup(0);
mCustomTabsSession = mCustomTabsClient.newSession(null);
}
@Override
public void onServiceDisconnected(ComponentName name) {
mCustomTabsClient = null;
}
};
packageNameToUse = ChromePackageHelper.getPackageNameToUse(context);
if (packageNameToUse != null){
CustomTabsClient.bindCustomTabsService(context, packageNameToUse,
mCustomTabServiceConnection);
}
return this;
}
示例7: onCreate
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mCustomTabsServiceConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
mClient = customTabsClient;
mClient.warmup(0L);
mCustomTabsSession = mClient.newSession(null);
}
@Override
public void onServiceDisconnected(ComponentName name) {
mClient = null;
}
};
CustomTabsClient.bindCustomTabsService(MainActivity.this, CUSTOM_TAB_PACKAGE_NAME, mCustomTabsServiceConnection);
customTabsIntent = new CustomTabsIntent.Builder(mCustomTabsSession)
.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary))
.setShowTitle(true)
.build();
}
示例8: onCustomTabsServiceConnected
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
@Override
public void onCustomTabsServiceConnected(ComponentName componentName,
CustomTabsClient customTabsClient) {
tabsClient = customTabsClient;
tabsClient.warmup(0);
tabsSession = tabsClient.newSession(navCallbackReference.get());
if (tabsSession != null && clientAuthUrl != null) {
tabsSession.mayLaunchUrl(Uri.parse(clientAuthUrl), null, null);
}
AuthenticationCallback callback = authCallbackReference.get();
if (callback != null) {
callback.onReadyToAuthenticate(null);
}
}
示例9: onCustomTabsServiceConnected
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
if (customTabsClient != null) {
customTabsClient.warmup(0L);
// Create a new session
mCustomTabsSession = customTabsClient.newSession(null);
// Let the session know that it may launch a URL soon
if (!TextUtils.isEmpty(mWebsiteUrl)) {
Uri uri = Uri.parse(mWebsiteUrl);
if (uri != null && mCustomTabsSession != null) {
// If this returns true, custom tabs will work,
// otherwise, you need another alternative if you don't want the user
// to be launched out of the app by default
mCustomTabsSession.mayLaunchUrl(uri, null, null);
}
}
}
}
示例10: bindCustomTabsServiceTo
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
public void bindCustomTabsServiceTo(@NonNull final Context context, ServiceConnectionCallback callback) {
if (isConnected()) {
return;
}
serviceConnection = new ServiceConnection(callback);
availableAppProvider.findBestPackage(
new AvailableAppProvider.PackageFoundCallback() {
@Override
public void onPackageFound(String packageName) {
CustomTabsClient.bindCustomTabsService(context, packageName, serviceConnection);
}
@Override
public void onPackageNotFound() {
serviceConnection = null;
}
}, context
);
}
示例11: onActivityCreated
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
CustomTabsServiceConnection connection = new NewsCustomTabsServiceConnection();
isCustomTabsSupported = isChromeCustomTabsSupported(getContext());
setHasOptionsMenu(true);
mListView = getListView();
builder = new CustomTabsIntent.Builder();
share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
builder.setToolbarColor(0x3E50B4);
builder.setStartAnimations(getContext(),
android.support.design.R.anim.abc_popup_enter,
android.support.design.R.anim.abc_popup_exit);
CustomTabsClient.bindCustomTabsService(getContext(),
NewsCustomTabsServiceConnection.CUSTOM_TAB_PACKAGE_NAME, connection);
addNews();
}
示例12: preload
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
/** Caller must unbind the returned ServiceConnection when leaving the scope. */
public static @CheckResult @Nullable ServiceConnection preload(final Context context, final Uri uri, final @Nullable OnSessionReadyListener listener) {
final CustomTabsServiceConnection connection;
if (! CustomTabsClient.bindCustomTabsService(context, KChromePackageName, connection = new CustomTabsServiceConnection() {
@Override public void onCustomTabsServiceConnected(final ComponentName componentName, final CustomTabsClient client) {
Log.d(TAG, "Warming up Chrome custom tabs");
if (client.warmup(0)) {
final CustomTabsSession session = client.newSession(null);
if (session != null) {
session.mayLaunchUrl(uri, null, null);
if (listener != null) listener.onSessionReady(session);
}
}
}
@Override public void onServiceDisconnected(final ComponentName name) {}
})) return null;
return connection;
}
示例13: bindCustomTabsService
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
/**
* Binds the Activity to the Custom Tabs Service.
* @param activity the activity to be binded to the service.
*/
public void bindCustomTabsService(Activity activity) {
if (mClient != null) return;
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
if (packageName == null) return;
mConnection = new ServiceConnection(this);
CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
}
示例14: bindCustomTabsService
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
/**
* Binds the Activity to the Custom Tabs Service.
*
* @param activity the activity to be binded to the service.
*/
public void bindCustomTabsService(Activity activity) {
if (mClient != null) return;
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
if (packageName == null) return;
mConnection = new ServiceConnection(this);
CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
}
示例15: bindCustomTabsService
import android.support.customtabs.CustomTabsClient; //導入依賴的package包/類
public void bindCustomTabsService() {
if (mClient != null) return;
if (mConnection == null) {
mConnection = new ServiceConnection(this);
}
boolean ok = CustomTabsClient.bindCustomTabsService(mContext, CUSTOM_TAB_PACKAGE_NAME, mConnection);
}