This is my first time to use B4A(My English is poor),I want use third party sdk.
java code
public static void setDebugMode(boolean debugEnalbed)
public static void init(Context context)
public static void setAlias(Context context, String alias, TagAliasCallback callback)
My B4A code
java code
public static void setDebugMode(boolean debugEnalbed)
public static void init(Context context)
public static void setAlias(Context context, String alias, TagAliasCallback callback)
B4X:
private void setAlias() {EditText aliasEdit = (EditText) findViewById(R.id.et_alias);String alias = aliasEdit.getText().toString().trim();if (TextUtils.isEmpty(alias)) {
Toast.makeText(PushSetActivity.this,R.string.error_alias_empty, Toast.LENGTH_SHORT).show();return;}
if (!ExampleUtil.isValidTagAndAlias(alias)) {
Toast.makeText(PushSetActivity.this,R.string.error_tag_gs_empty, Toast.LENGTH_SHORT).show();
return;
}
mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_ALIAS, alias));
}
private final TagAliasCallback mAliasCallback = new TagAliasCallback() {
@Override
public void gotResult(int code, String alias, Set<String> tags) {
String logs ;
switch (code) {
case 0:
logs = "Set tag and alias success";
Log.i(TAG, logs);
break;
case 6002:
logs = "Failed to set alias and tags due to timeout. Try again after 60s.";
Log.i(TAG, logs);
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_SET_ALIAS, alias), 1000 * 60);
break;
default:
logs = "Failed with errorCode = " + code;
Log.e(TAG, logs);
}
ExampleUtil.showToast(logs, getApplicationContext());
}
};
private static final int MSG_SET_ALIAS = 1001;
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(android.os.Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case MSG_SET_ALIAS:
Log.d(TAG, "Set alias in handler.");
JPushInterface.setAliasAndTags(getApplicationContext(),
(String) msg.obj,
null,
mAliasCallback);
break;
default:
Log.i(TAG, "Unhandled msg - " + msg.what);
}
}
};
My B4A code
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("cover")
jpMsg.InitializeStatic("cn.jpush.android.api.JPushInterface").RunMethod("init",Array(GetContext))
jpMsg.RunMethod("setDebugMode",Array (True))
''''''''''next 3 line is wrong,how to do it
Dim jvo As JavaObject
Dim Callback As Object = jvo.CreateEvent("cn.jpush.android.api.TagAliasCallback", "Callback", Null)
jpMsg.RunMethodjo("setAlias",Array(GetContext,"ceshi",Object(jvo))
End Sub
Sub Callback(responseCode As Int , alias As String, tags As String)
End Sub
Sub GetContext As JavaObject
Return GetBA.GetField("context")
End Sub
Sub GetBA As JavaObject
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls)
Return jo.GetFieldJO("processBA")
End Sub