CaaS Engine provides open APIs that are based on the HUAWEI MeeTime service, helping you to incorporate voice and video calling into your apps' social framework (such as contacts and friends) with ease. You can customize the text displayed on the incoming and outgoing call screens, to enhance user experience for calls made to strangers by hiding the real mobile numbers of both parties from view.
In this codelab, you will create a demo project, integrate the CaaS Engine SDK into the demo project, and set up the complete CaaS Engine service process.
In this codelab, you will learn how to:
CaaS Engine integration requires the following preparations:
Configure the repository in the build.gradle file of the project.
buildscript {
repositories {
google()
jcenter()
maven {url 'http://developer.huawei.com/repo/'}
}
}
allprojects {
repositories {
maven {url 'http://developer.huawei.com/repo/'}
google()
jcenter()
}
}
Add the following dependencies to the build.gradle file in the app directory of the project.
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
implementation group: 'com.huawei.caaskit', name: 'caaskitlite', version: '1.0.1.400', ext: 'aar'
}
Click the sync button, as shown in the following figure.
After the synchronization, the following screen is displayed.
Add the app ID generated when creating the app on HUAWEI Developers to the AndroidManifest.xml file of the app. The name is com.huawei.hms.client.appid, and the value is appid=****, where ****** indicates the ID of your app.** For details about how to apply for the permission, see Configuring App Information in AppGallery Connect.
CaasKitHelper.java
public class CaasKitHelper {
private static final String TAG = "CaasKitHelper";
private static CaasKitHelper mCaasKitHelper;
private HwCaasServiceManager mHwCaasServiceManager;
private HwCaasHandler mHwCaasHandler;
private Context mContext;
private boolean mIsCaasKitInit;
private CaasKitHelper() {
mContext = CaasKitApplication.getContext();
}
public static CaasKitHelper getInstance() {
if (mCaasKitHelper == null) {
synchronized (CaasKitHelper.class) {
if (mCaasKitHelper == null) {
mCaasKitHelper = new CaasKitHelper();
}
}
}
return mCaasKitHelper;
}
public void caasKitInit(HwCaasServiceCallBack callback) {
Log.d(TAG, "caasKitInit.");
if (!mIsCaasKitInit) {
/** Initialize mHwCaasServiceManager instance. */
mHwCaasServiceManager = HwCaasServiceManager.init();
/** Initialize HwCaasHandler instance through handlerType. */
mHwCaasServiceManager.initHandler(mContext, HwCaasUtils.HIDE_NUMBER_TYPE, callback);
mIsCaasKitInit = true;
}
}
public void setHwCaasHandler(HwCaasHandler handler) {
Log.d(TAG, "setHwCaasHandler.");
mHwCaasHandler = handler;
}
public void setCallAbilityCallBack(HwCallAbilityCallBack callback) {
Log.d(TAG, "setCallAbilityCallBack.");
if (mHwCaasHandler != null) {
mHwCaasHandler.setCallAbilityCallBack(callback);
}
}
}
Add the following code to where appropriate:CaasKitActivity.java
public class CaasKitActivity extends AppCompatActivity {
private static final String TAG = "CaasKitActivity";
private static final int PHONE_NOT_SUPPORT_HICALL = 3002;
private static final int SHOW_TOAST = 0;
private static final int SET_ALL_VISIBALE = 1;
private static final int SET_ALL_INVISIBALE = 2;
private static final int SET_AUDIO_VISIBALE = 3;
private static final int SET_AUDIO_INVISIBALE = 4;
private HwCaasServiceCallBack mCallBack = new HwCaasServiceCallBack() {
@Override
public void initSuccess(HwCaasHandler handler) {
Log.i(TAG, "HwCaasServiceCallBack:initSuccess.");
/** Callback after successful initialization of HwCaasHandler. */
CaasKitHelper.getInstance().setHwCaasHandler(handler);
CaasKitHelper.getInstance().setCallAbilityCallBack(mAbilityCallBack);
CaasKitHelper.getInstance().setMakeCallCallBack(new HwMakeCallCallBack() {
@Override
public void makeCallResult(String number, int retCode) {
Log.d(TAG, "number: " + number + " retCode: " + retCode);
}
});
}
@Override
public void initFail(int retCode) {
/** Callback if init Handler fail. */
Log.i(TAG, "HwCaasServiceCallBack:initFail:retCode: " + retCode);
setVisibility(false, 0);
toast("HwCaasServiceCallBack initFail");
}
@Override
public void releaseSuccess() {
/** Callback after successful release of mHwCaasServiceManager. */
Log.i(TAG, "HwCaasServiceCallBack:releaseSuccess");
CaasKitHelper.getInstance().setHwCaasHandler(null);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_caaskitquickcall);
CaasKitHelper.getInstance().caasKitInit(mCallBack);
}
}
CaasKitHelper.java
public class CaasKitHelper {
private static final String TAG = "CaasKitHelper";
private static CaasKitHelper mCaasKitHelper;
private HwCaasServiceManager mHwCaasServiceManager;
private HwCaasHandler mHwCaasHandler;
private Context mContext;
private boolean mIsCaasKitInit;
public int makeCall(String phoneNumber, HwCaasUtils.CallType callType) {
Log.d(TAG, "makeCall.");
if (mHwCaasHandler != null) {
CustomDisplayInfo info = new CustomDisplayInfo
// Caller app name displayed on the called party's screen - Caller field 1 on the called party's screen (e.g. caller name) - Fields displayed on the calling party's screen (e.g. called party's name)
.Builder("Application","Jane", "Andy")
// Caller field 2 on the called party's screen (e.g. position in company)
.setCallerDisplayInfo2("Company X, CDO")
.build(); // The calling phoneNumber should be encrypted using SHA-256 and must be with a country code, for example, +861320750xxxx.
String phoneNumberSha256 = Sha256Util.encryptNumber(phoneNumber);
int retCode = mHwCaasHandler.makeCall(phoneNumberSha256, callType, info);
Log.d(TAG, "makeCall retCode: " + retCode);
return retCode;
}
return -1;
}
}
Add the following code to where appropriate:CaasKitActivity.java
public class CaasKitActivity extends AppCompatActivity {
private static final String TAG = "CaasKitActivity";
private static final int PHONE_NOT_SUPPORT_HICALL = 3002;
private static final int SHOW_TOAST = 0;
private static final int SET_ALL_VISIBALE = 1;
private static final int SET_ALL_INVISIBALE = 2;
private static final int SET_AUDIO_VISIBALE = 3;
private static final int SET_AUDIO_INVISIBALE = 4;
private EditText mPhoneNumber;
private Button mStartQuery;
private Button mMakeVideoCall;
private Button mMakeAudioCall;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_caaskitquickcall);
initView();
initData();
CaasKitHelper.getInstance().caasKitInit(mCallBack);
}
private void initView() {
mPhoneNumber = (EditText) findViewById(R.id.phone_number);
mStartQuery = (Button) findViewById(R.id.start_query);
mMakeVideoCall = (Button) findViewById(R.id.make_video_call);
mMakeAudioCall = (Button) findViewById(R.id.make_audio_call);
}
private void initData() {
mPhoneNumber.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
setVisibility(false, 0);
}
});
mStartQuery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CaasKitHelper.getInstance().queryHiCallAbility(mPhoneNumber.getText().toString());
}
});
mMakeVideoCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
makeCall(HwCaasUtils.CallType.VIDEO_CALL);
}
});
mMakeAudioCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
makeCall(HwCaasUtils.CallType.VOICE_CALL);
}
});
setVisibility(false, 0);
}
private void makeCall(HwCaasUtils.CallType callType) {
int retCode = CaasKitHelper.getInstance().makeCall(mPhoneNumber.getText().toString(), callType);
Log.d(TAG, "makeCall:retCode: " + retCode);
}
}
CaasKitHelper.java
public class CaasKitHelper {
private static final String TAG = "CaasKitHelper";
private static CaasKitHelper mCaasKitHelper;
private HwCaasServiceManager mHwCaasServiceManager;
private HwCaasHandler mHwCaasHandler;
private Context mContext;
private boolean mIsCaasKitInit;
public void caasKitRelease() {
if (mIsCaasKitInit) {
if (mHwCaasServiceManager != null) {
/** Source release */
mHwCaasServiceManager.release();
mHwCaasServiceManager = null;
}
mIsCaasKitInit = false;
}
}
}
Add the following code to where appropriate:CaasKitActivity.java
public class CaasKitActivity extends AppCompatActivity {
private static final String TAG = "CaasKitActivity";
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy.");
CaasKitHelper.getInstance().caasKitRelease();
}
}
Well done. You have successfully completed this codelab and learned how to:
For more information, please click the following link:
Related documents
You can click the button below to download the source code.