ハイブリッドアプリへの実装

    ハイブリッドアプリへの実装


    記事の要約

    ショートフォーム導入 - ハイブリッドアプリ

    [ステップ1] ライブラリの追加

    以下のコードを build.gradle に追加してください。また、 統合されたライブラリまたは分割されたライブラリをapp/build.gradleに追加してください。

    統合されたライブラリ

    dependencies {
        def shoplive_sdk_version = "1.5.11"
        
        // Shoplive combined packaging
        implementation "cloud.shoplive:shoplive-sdk-all:$shoplive_sdk_version" // live + short-form
    }

    分割されたライブラリ

    dependencies {
        def shoplive_sdk_version = "1.5.11"
        def your_exoplayer_version = "2.19.1"
        def your_media3_version = "1.3.1"
        def shoplive_exoplayer_version = your_exoplayer_version + "." + "8"
        def shoplive_media3_version = your_media3_version + "." + "8"
        
        // Shoplive split packaging
        implementation "cloud.shoplive:shoplive-common:$shoplive_sdk_version" // must required
        implementation "cloud.shoplive:shoplive-exoplayer:$shoplive_exoplayer_version" // must required
        // When using media3. Exoplayer will be deprecated soon.
        // https://developer.android.com/guide/topics/media/media3/getting-started/migration-guide
        // implementation "cloud.shoplive:shoplive-media3:$shoplive_media3_version" 
        implementation "cloud.shoplive:shoplive-network:$shoplive_sdk_version" // must required
      
        implementation "cloud.shoplive:shoplive-short-form:$shoplive_sdk_version" // for short-form player
      
        implementation "cloud.shoplive:shoplive-sdk-core:$shoplive_sdk_version" // for live player
    }

    [ステップ2] Web連携

    ショートフォームのサービスを提供するには、最初にWeb統合を実行する必要があります。Web連携については、以下のリンクをご参照ください。

    [ステップ3]ネイティブコードを適用する

    次のコードをWeb Activity に追加してください。 

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        webView.settings.domStorageEnabled = true // Required
        webView.settings.javaScriptEnabled = true // Required
    
        ShopLiveShortform.connectBridgeInterface(this, webView) // Required
        ShopLiveShortform.receiveBridgeInterface(webView) // Required
        
        webView.webViewClient = object : WebViewClient() {
            ...
            // Required
            override fun doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean) {
                super.doUpdateVisitedHistory(view, url, isReload)
                ShopLiveShortform.updateVisitedHistory(view, url, isReload)
            }
            ...
        }
        
        // Optional
        ShopLiveShortform.setHandler(object : ShopLiveShortformFullTypeHandler() {
            override fun onEvent(command: String, payload: String?) {
                // Do something
            }
            
            override fun onError(error: ShopLiveCommonError) {
                // Do something
            }
            
            override fun onShare(activity: Activity, data: ShopLiveShortformData?, url: String?) {
                // Do something
            }
        })
    }


    What's Next