Use the developer assistant

更新时间:
复制 MD 格式

This topic describes how to connect, start, and extend the developer assistant.

Connect the developer assistant

Prerequisites

You have connected to mPaaS using the component-based Portal & Bundle connection type.

Procedure

To connect the developer assistant, add the following code to the `build.gradle` file of the Portal project.

devbundle "com.mpaas.android.dev.helper:devhelper-build:1.0.0.200720113923@jar"
devmanifest "com.mpaas.android.dev.helper:devhelper-build:1.0.0.200720113923:AndroidManifest@xml"

Start the developer assistant

The developer assistant starts automatically with the mPaaS framework and requires no additional code. However, note the following special cases:

  1. When an Android phone runs in monkey mode, the developer assistant does not start automatically.

  2. In release mode, where android:debuggable="false", the developer assistant does not start by default. To start the developer assistant in release mode, set the following property in the `AndroidManifest.xml` file. However, you must remove this configuration before the official release. The code is as follows:

    <meta-data
          android:name="devhelper_start"
          android:value="true" />

    Also, replace the developer assistant dependency as shown in the following code:

    bundle "com.mpaas.android.dev.helper:devhelper-build:1.0.0.200720113923@jar"
    manifest "com.mpaas.android.dev.helper:devhelper-build:1.0.0.200720113923:AndroidManifest@xml"

Extend the developer assistant

You can extend the developer assistant with custom features, such as a feature to view encrypted user data. To do this, you must add new implementation classes.

Procedure

  1. Add a file with a unique name that ends with .devhelper.json to the `assets` folder. The JSON file must contain the following content:

    [
    {
    "className": "com.alipay.android.phone.devtool.devhelper.woodpecker.panel.items.SpmItem", 
    "bundleName": "com-mpaas-android-dev-helper-devhelper"
    }
    ]
    • className: Specifies the class name. This is the name of the new implementation class that you create in Step 2.

    • bundleName: Specifies the bundle name.

      • The bundle name can be found in the /build/intermediates/bundle/META-INF/BUNDLE.MF file of the main module.

      • If the extended feature is added to the Portal project, set bundleName to an empty string "".

  2. Create a new class and implement the following methods. The class must have one, and only one, parameterless constructor.

    /**
    * @param context
    * @return The entry icon for the developer assistant panel.
    */
    Drawable icon(Context context);
    
    /**
    * @param context
    * @return The name displayed on the developer assistant panel.
    */
    String title(Context context);
    
    /**
    * @param context
    * @return Whether the response is processed. If it is processed, return True.
    */
    boolean onClick(Context context);
    
    /**
    * @param context
    * @return Whether the feature is active. If it is active, return True.
    */
    boolean enabled(Context context);
    
    /**
    * Returns one of the following groups:
    * {@link #GROUP_OTHER} = 'OTHER'
    * {@link #GROUP_TOOL} = 'TOOL'
    * {@link #GROUP_UI} = 'UI'
    * {@link #GROUP_LOG} = 'LOG'
    *
    * @return
    */
    String group();

Code example

The following example shows how to extend the developer assistant. In this example, an extended feature named Extension Connection is added. When the icon for this feature is clicked, it returns the string "onclick".

package com.alipay.mpaas.test.helper;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.widget.Toast;
import com.mpaas.demo.R;

public class SpmItem {
    private final static String TAG = SpmItem.class.getName();

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public Drawable icon(Context context) {
        return context.getDrawable(R.drawable.appicon);
    }

    public String title(Context context) {
        return "Extension Connection";
    }

    public boolean onClick(Context context) {
        Toast.makeText(context,"onclick",Toast.LENGTH_LONG).show();
        return true;
    }

    public boolean enabled(Context context) {
        return true;
    }

    public String group() {
        return "OTHER";
    }
}

Result

As shown in the following figures, Extension Connection is added to the OTHER group in the developer assistant. When the icon is clicked, the string "onclick" is displayed.