Alipay, China's leading third-party online payment solutionAlipay, China's leading third-party online payment solution

(Optional) Use Fragment to open WAP pages

You can open WAP pages in Fragment on Android by calling the Griver.createFragment4Url() API. For more information about Fragment, refer to Android's documentation on Fragments. This topic guides you on how to call the Griver.createFragment4Url() API.

Before you begin

Before calling the Griver.createFragment4Url() API, it is recommended to learn the following things:

  • Your SDK version needs to be at least IAPConnect 2.48.0. If you are not clear about the SDK version you integrate, contact your Solution Architect for help.
  • This API is used to open only WAP pages, and can't be used to open DSL-based mini programs.
  • With Fragment, you can adjust the page into different sizes on the screen. However, it does not support displaying the title of the container as the openUrl API does. Refer to Figure 1 and Figure 2 for details. If you want to display a title or create page jumps with the title, you can set a page title in your own code. Refer to Figure 3 for details.

5cf8d71d95ce8c452b25ba62e3caca2f.jpg

5993065779d8ee62fe90e3f67aa2d612.jpg

e47471002f68bfc41461d2d8581e07dd.jpg

  • As a super app, if you want to implement the following capabilities when using Fragment, pass the related callbacks in the host Activity to Mini Program Platform:
    • Junmping from one page to another page
    • Requesting system permissions
    • Detecting physical button presses
  • Since screen rotations cause Fragment to re-render, to handle screen rotations without losing data, you need to add the configuration type to android:configChanges in the host Activity entry in AndroidManifest.xml using the following sample code:
copy
<activity
  android:name="YourActivity"
  android:configChanges="orientation|keyboardHidden|navigation|screenSize"
  />

Request parameters

The following table lists the request parameters of the Griver.createFragment4Url() API:

Property

Type

Required

Description

context

Context

Yes

Indicates the context. For more information, refer to Android's documentation on Context.

url

String

Yes

Indicates the URL of the WAP page.

extraParams

Bundle

No

The startup parameters.

callBack

GriverCreateFragmentCallBack

Yes

The callback on creating a fragment. You need to listen for this callback to retrieve the created fragment.

For more information about how to specify this parameter, refer to the GriverCreateFragmentCallBack section.

Sample

The following sample codes show how to call the Griver.createFragment4Url() API:

copy

public class YourActivity extends AppCompatActivity {

    private GriverBaseFragment fragment1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_web_view);
        Bundle bundle = new Bundle();
        openOffline(bundle);
    }

    void openOffline(Bundle bundle) {
        Griver.createFragment4Url(YourActivity.this, "https://xxx", bundle, new GriverCreateFragmentCallBack() {
            @Override
            public void error(int errorCode, String errorMessage) {
                
            }

            @Override
            public void onFragmentCreate(GriverBaseFragment fragment) {
                if (fragment != null) {
                    YourActivity.this.fragment1 = fragment;
                    YourActivity.this.getSupportFragmentManager().beginTransaction().add(R.id.fragment_container_web, fragment)
                            .show(fragment1).commit();
                }
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (fragment1 != null) {
            boolean b = fragment1.onKeyDown(keyCode, event);
            if (b) {
                return true;
            }
        }
        return super.onKeyDown(keyCode, event);
    }
    
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions,  int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (fragment1 != null) {
            fragment1.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(fragment1 != null) {
            fragment1.onActivityResult(requestCode, resultCode, data);
        }
    }
}
copy
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <FrameLayout
        android:layout_marginTop="50dp"
        android:id="@+id/fragment_container_web"
        android:layout_width="match_parent"
        android:layout_gravity="center"
        android:layout_height="400dp"
        />
</LinearLayout>

GriverCreateFragmentCallBack

The following sample code shows how to specify the GriverCreateFragmentCallBack request parameter:

copy
interface GriverCreateFragmentCallBack {
    void onFragmentCreate(GriverBaseFragment fragment);
    void error(int errorCode, String errorMessage);
}

Error codes

The following table lists the error codes, their descriptions, and further actions:

Error code

Description

Further action

90003

SDK is not initialized.

Initialize the SDK.

90002

Parameter error.

Refer to the Request parameters table and check if all parameter types are correct and if all required parameters are specified.

FAQ

When are fragments destroyed and WAP page resources recycled?

Fragments are destroyed, WAP page resources are recycled, and WAP pages are closed when the onDestroy() method of Fragment is called (for example, the method is called when fragments are removed by FragmentManager).