Custom in-app browser
Buzzvil SDK passes the URL of the clicked ad or content to Launcher. launch() determines which browser opens it: an external browser, Buzzvil's in-app browser or your own custom browser.
The default launcher chooses between an external browser and Buzzvil's in-app browser according to the ad settings. To use your own browser, implement it, create a launcher to open it and register the launcher in BuzzAdBenefit.
Implement a custom in-app browser
The following example implements a custom browser. You must use BuzzAdBrowser.getInstance(this).getFragment(url); otherwise, action-based ads and time-based reward ads may not work correctly.
class CustomBrowserActivity : AppCompatActivity() {
companion object {
const val KEY_URL = "com.sample.KEY_URL"
private lateinit var fragment: BuzzAdBrowserFragment
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_custom_browser)
// URL을 KY로 하여 WebView를 가지고있는 Fragment를 받아와 사용합니다.
fragment = BuzzAdBrowser.getInstance(this).getFragment(intent.getStringExtra(KEY_URL))
supportFragmentManager.beginTransaction().replace(R.id.browserContainer, fragment).commit()
val webView = fragment.webView
// Browser의 이벤트를 받을 수 있습니다. DeepLink가 열렸을 경우, Browser를 닫아주어야 빈 페이지가 보여지는 현상을 방지할 수 있습니다.
BuzzAdBrowser.getInstance(this).addBrowserEventListener(object : OnBrowserEventListener() {
override fun onDeepLinkOpened() {
super.onDeepLinkOpened()
finish()
}
})
}
override fun onBackPressed() {
val webView = fragment.webView
if (webView != null && webView.canGoBack()) {
webView.goBack()
} else {
super.onBackPressed()
}
}
}
The following example implements the custom browser layout.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/browserContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Implement a custom launcher
Implement a launcher to use your browser. You can define different behavior for ads and content, and set a deep link for the content's sourceUrl.
The following example implements a custom launcher that opens ads in your browser.
class CustomLauncher: Serializable, Launcher() {
override fun launch(context: Context, launchInfo: LaunchInfo, listener: LauncherEventListener?, javascriptInterfaces: List<Class<out BuzzAdJavascriptInterface>>?) {
// 자체 구현 인앱 브라우저를 실행합니다.
val intent = Intent(context, CustomBrowserActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.putExtra(CustomBrowserActivity.KEY_URL, launchInfo.uri.toString()) // URI는 변경 하면 안 됨
context.startActivity(intent)
}
}
Register the custom launcher
Register your custom launcher in BuzzAdBenefit as shown below.
BuzzAdBenefit.setLauncher(CustomLauncher())