演示例程下载地址:www,boveyyun,com/?page_id=30
代码如下:
package com.e4a.runtime.api;//包名必须固定为这个,不能自己修改
import com.e4a.runtime.annotations.SimpleFunction;
import com.e4a.runtime.annotations.SimpleObject;
import com.e4a.runtime.annotations.UsesPermissions;
import com.e4a.runtime.应用操作;//可以引用E4A支持库中已经存在的类
import com.e4a.runtime.android.mainActivity;
import android.widget.Toast;
// 博维云需要导入的类
import com.bovey.android.AndroidClient;
import com.bovey.android.CString;
import com.bovey.android.MsgRecver;
@UsesPermissions(permissionNames = "android.permission.INTERNET")//安卓权限标记,如果接口函数中需要额外的安卓权限,可在此填写,多个权限可以用逗号隔开
@SimpleObject
public final class 博维云接口{
private static AndroidClient m_client = null;
private static MsgRecver m_recver = null;
@SimpleFunction//导出函数标记
public static boolean 初始化(){
if(m_client != null)
return true;
m_client = new AndroidClient();
m_recver = new MsgRecver();
boolean b = m_client.Init();
m_client.RegRecver(m_recver);
return b;
}
@SimpleFunction//导出函数标记
public static void 关闭连接(){
if(m_client == null)
return;
m_client.Close();
m_client = null;
m_recver = null;
}
@SimpleFunction//导出函数标记
public static String 登录(String token, String custom_code, int time_out){
if(m_client == null)
return m_client.Result(false,"");
CString out_str = new CString();
boolean b = m_client.Login(token,custom_code,out_str,time_out);
return m_client.Result(b,out_str.toString());
}
@SimpleFunction//导出函数标记
public static String 发送短消息(String msg, int time_out){
if(m_client == null)
return m_client.Result(false,"");
CString out_str = new CString();
boolean b = m_client.Request(msg,out_str,time_out);
return m_client.Result(b,out_str.toString());
}
@SimpleFunction//导出函数标记
public static boolean 发送长消息(String msg){
if(m_client == null)
return false;
boolean b = m_client.SendMsg(msg);
return b;
}
@SimpleFunction//导出函数标记
public static String 上传文件(String local_file_path,String server_save_name,String task_token,boolean bExistFail,boolean bApp){
if(m_client == null)
return m_client.Result(false,"");
CString out_str = new CString();
boolean b = m_client.UpFile(local_file_path,server_save_name,task_token,bExistFail,bApp,out_str);
return m_client.Result(b,out_str.toString());
}
@SimpleFunction//导出函数标记
public static String 下载文件(String server_file_path,String local_save_name,String task_token,boolean bExistFail,boolean bApp){
if(m_client == null)
return m_client.Result(false,"");
CString out_str = new CString();
boolean b = m_client.DownFile(server_file_path,local_save_name,task_token,bExistFail,bApp,out_str);
return m_client.Result(b,out_str.toString());
}
@SimpleFunction//导出函数标记
public static String 获取服务器推送消息(){
if(m_recver == null || m_client == null)
return "";
return m_recver.GetRecvMsg();
}
@SimpleFunction//导出函数标记
public static double 获取任务进度(String task_token){
if(m_recver == null || m_client == null)
return 0;
return m_recver.GetTaskPercent(task_token);
}
@SimpleFunction//导出函数标记
public static int 停止任务(String task_token){
if(m_client == null)
return 0;
return m_client.StopTask(task_token);
}
@SimpleFunction//导出函数标记
public static String 获取错误信息(){
if(m_client == null)
return "对象没有初始化";
return m_client.GetLastError();
}
@SimpleFunction//导出函数标记
public static boolean 获取结果值(String res){
return m_client.GetResultCode(res);
}
@SimpleFunction//导出函数标记
public static String 获取结果数据(String res){
return m_client.GetResultData(res);
}
}
|