কাস্টম ট্যাবের সাথে আপনার অ্যাপ্লিকেশন ইন্টিগ্রেট করার জন্য সাজেস্ট করা পদ্ধতি হল AndroidX ব্রাউজার লাইব্রেরি ব্যবহার করা, তবে আপনি সাপোর্ট লাইব্রেরি ছাড়াই কাস্টম ট্যাব শুরু করতে পারেন। এই নির্দেশিকা থেকে আপনি এটি কীভাবে করবেন তার ওভারভিউ পাবেন।
Support Library-র সম্পূর্ণ ইমপ্লিমেন্টেশন [GitHub][1]-এ উপলভ্য এবং এটি শুরু করার পয়েন্ট হিসেবে ব্যবহার করা যেতে পারে। এছাড়াও, এতে পরিষেবার সাথে কানেক্ট করার জন্য প্রয়োজনীয় [AIDL ফাইল][2] থাকে, কারণ Chromium রিপোজিটরিতে থাকা ফাইলগুলি Android Studio-র সাথে সরাসরি ব্যবহার করা যায় না।
লো লেভেল API ব্যবহার করে কাস্টম ট্যাব লঞ্চ করার প্রাথমিক তথ্য
// Using a VIEW intent for compatibility with any other browsers on device.
// Caller should not be setting FLAG_ACTIVITY_NEW_TASK or
// FLAG_ACTIVITY_NEW_DOCUMENT.
val url = "https://paul.kinlan.me/"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
// Must have. Extra used to match the session. Its value is an IBinder passed
// whilst creating a news session. See newSession() below. Even if the service is not
// used and there is no valid session id to be provided, this extra has to be present
// with a null value to launch a custom tab.
val extraCustomTabsSession = "android.support.customtabs.extra.SESSION"
val extras = Bundle()
extras.putBinder(
extraCustomTabsSession,
sessionICustomTabsCallback.asBinder() /* Set to null for no session */
)
intent.putExtras(extras)
UI কাস্টমাইজেশন যোগ করা হচ্ছে
ACTION_VIEW ইনটেন্টে অতিরিক্ত তথ্য যোগ করে UI কাস্টমাইজেশন অন্তর্ভুক্ত করা হয়। UI কাস্টমাইজ করার জন্য ব্যবহৃত এক্সট্রা কী-এর সম্পূর্ণ তালিকা [CustomTabsIntent docs][3]-এ পাওয়া যাবে। কীভাবে কাস্টম টুলবার রঙ যোগ করতে হয় তার একটি উদাহরণ নিচে দেওয়া হল:
// Extra that changes the background color for the address bar. colorInt is an int
// that specifies a Color.
val extraCustomTabsToolbarColor = "android.support.customtabs.extra.TOOLBAR_COLOR"
intent.putExtra(extraCustomTabsToolbarColor, colorInt)
কাস্টম ট্যাব পরিষেবার সাথে কানেক্ট করা হচ্ছে
অন্যান্য Android পরিষেবার মতো একইভাবে কাস্টম ট্যাব পরিষেবা ব্যবহার করা যেতে পারে। ইন্টারফেসটি AIDL-এর মাধ্যমে তৈরি করা হয় এবং এটি আপনার জন্য অটোমেটিক প্রক্সি সার্ভিস ক্লাস তৈরি করে।
প্রক্সি সার্ভিসে পদ্ধতি ব্যবহার করে ওয়ার্ম-আপ, সেশন তৈরি ও প্রি-ফেচ করুন:
// Package name for the Chrome channel the client wants to connect to. This
// depends on the channel name.
// Stable = com.android.chrome
// Beta = com.chrome.beta
// Dev = com.chrome.dev
val customTabPackageName = "com.chrome.dev" // Change when in stable
// Action to add to the service intent. This action can be used as a way
// generically pick apps that handle custom tabs for both activity and service
// side implementations.
val actionCustomTabsConnection =
"android.support.customtabs.action.CustomTabsService"
val serviceIntent = Intent(actionCustomTabsConnection)
serviceIntent.setPackage(customTabPackageName)
// serviceConnection is your ServiceConnection implementation. Its
// onServiceConnected() callback receives the IBinder for the Custom Tabs service.
context.bindService(
serviceIntent,
serviceConnection,
Context.BIND_AUTO_CREATE or Context.BIND_WAIVE_PRIORITY
)
[১]: https://github.com/GoogleChrome/custom-tabs-client/tree/master/customtabs [২]: https://developer.android.com/guide/components/aidl.html [৩]: https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent