用户工具

站点工具


这是本文档旧的修订版!


HuaweiPush Plugin

Huawei Push the plug is Cobub Razor official platform based Huawei alliance to push the development of a plug-in. It integrates features a push function Tag Huawei and Cobub Razor Alliance platform provides more convenient, fast and accurate a push. Huawei Union open platform for messaging applications to help companies push through low-cost Internet access, provide a sound, efficient and stable service system solves the Internet cloud to the phone side of the message interoperability problems.

===== Integration steps: =====I

Huawei push the plug before integration, ensure the establishment of a database related tables, can go toheresql file Download related to import into your database, create a related table (note changes in the prefix table sql razor_, in order to maintain your own database table prefix and consistent).

1.Ensure Cobub Razor and Cobub authorized users Center has successfully bound. If not binding, see here. 2.Activate Huawei Cobub Razor in push applications 若要使用华为推送插件中的推送,系统需要为每个App(当前只支持Android平台)分配相应的授权Key。 3.华为推送SDK集成** 在华为联盟下载下来的华为推送SDK为.rar文件,在本地解压后,进入“微内核SDK\Doc”目录,参考Doc目录下的《华为PushSDK集成说明.pdf》文档集成华为推送SDK

集成步骤:

3.1.集成jar包:

将获取到的cobub razor的ums.jar添加到华为推送项目的libs目录。 在项目上右键选择Build Path→Configure build path…—>左侧选择 Java Build Path—>;选择Libraries选择卡—>;Add JARs.. —>;选择当前项目的Libs目录,选中jar包,然后点击OK.

3.2.修改华为推送SDK项目包名与您创建应用的包名相一致

3.3.配置AndroidManifest.xml文件。

* 添加授权

    uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
    uses-permission android:name="com.android.mylauncher.permission.INSTALL_SHORTCUT"

* 加入服务声明

meta-data 
             android:name="UMS_APPKEY" 
             android:value="APPKEY"
meta-data

注意:PACKAGENAME替换为项目包名. 其中的APPKEY是通过Cobub razor创建应用时获取到的

3.4 添加SendMapping.java映射文件:将SendMapping.java文件放在’..\src\项目名’目录下

package  PACKAGENAME;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;
import com.wbtech.ums.UmsAgent;
import com.wbtech.ums.common.CommonUtil;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class SendMapping extends BroadcastReceiver {
    public static String NAME = "BroadcastReceiver2SendMapping";
    boolean isGetCobubBroadcoast = false;
    boolean isGetHuaWeiBroadcoast = false;
    String serviceURL = "http://push.cobub.com/index.php?/api/huawei/postmapping";

    public SendMapping() {
    }
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Log.d(NAME,"SendMapping onReceive");
//注册 receiver
//        SendMapping receiver = new SendMapping();
//        IntentFilter filter = new IntentFilter();
//        filter.addAction("cobub.razor.message");
//        filter.addAction("com.huawei.android.push.intent.REGISTRATION");
//        registerReceiver(receiver, filter);
        String action = intent.getAction();
        SharedPreferences sp= context.getSharedPreferences("cobub_huawei_sharepreference", 0);
        if(action.equals("cobub.razor.message")){
            String deviceid = intent.getStringExtra("deviceid");
            Log.d("postdata ", "get deviceid   : "+deviceid);
            sp.edit().putString("deviceid", deviceid).commit();
            isGetCobubBroadcoast = true;
        }
        if(action.equals("com.huawei.android.push.intent.REGISTRATION")){
            String deviceToken;
            try {
                deviceToken = new String(intent.getByteArrayExtra("device_token"), "UTF-8");
                sp.edit().putString("deviceToken", deviceToken).commit();
                Log.d("postdata ", "get deviceToken   : "+deviceToken);
                isGetHuaWeiBroadcoast = true;
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
        if(isGetCobubBroadcoast&& isGetHuaWeiBroadcoast){
            final JSONObject obj = new JSONObject();
            String deviceid = sp.getString("deviceid", "");
            String deviceToken = sp.getString("deviceToken", "");
            try {
                obj.put("deviceToken", deviceToken);
                obj.put("deviceid", deviceid);
                obj.put("app_key", CommonUtil.getAppKey(context));
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            Log.d("postdata ", "post deviceid and deviceToken");
            new Thread(new Runnable() {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					 post(serviceURL,obj.toString());
					 isGetCobubBroadcoast = false;
					 isGetHuaWeiBroadcoast = false;
				}
			}).start();
        }
    }
    public static int post(String url, String data) {
        String returnContent = "";
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);
        Log.d("postdata", "SMpost"+url+"  "+data);
        try {
            StringEntity se = new StringEntity("content="+data, HTTP.UTF_8);
            se.setContentType("application/x-www-form-urlencoded");
            httppost.setEntity(se);
            HttpResponse response = httpclient.execute(httppost);
            int status = response.getStatusLine().getStatusCode();
            Log.d("postdata ", "status==="+status);
            String returnXML = EntityUtils.toString(response.getEntity());
            returnContent = URLDecoder.decode(returnXML);
            switch (status) {
            case 200:
            {
            	Log.d("postdata ", "status===200");
                JSONObject obj = new JSONObject(returnContent);
                return obj.getInt("flag");
            } 
              default:
            	  Log.d("postdata ", "status="+status);
                break;
            }
        } catch (Exception e) { 
        	 e.printStackTrace();
            JSONObject jsonObject = new JSONObject();
                try {
                    jsonObject.put("err", e.toString());
                    returnContent = jsonObject.toString();
                } catch (JSONException e1) {
                    e1.printStackTrace();
                }
        }
        Log.d("postdata ", "post deviceid error deviceToken");
        return 0;
    } 
}

3.5. 初始化SDK

在您应用程序主Activity里导入 UmsAgent;

import com.wbtech.ums.UmsAgent;

然后在您应用程序启动初始化阶段,初始化SDK:

UmsAgent.setBaseURL("http://192.168.1.104:80/dev07/razor/web/index.php?");
		 UmsAgent.update(this);
		 UmsAgent.onError(this);
		 UmsAgent.setDefaultReportPolicy(this, 1);
		 UmsAgent.bindUserIdentifier(this, "xd..");
		 UmsAgent.postClientData(this);

		//注册 receiver
	      SendMapping receiver = new SendMapping();
	      IntentFilter filter = new IntentFilter();
	      filter.addAction("cobub.razor.message");
	      filter.addAction("com.huawei.android.push.intent.REGISTRATION");
	      registerReceiver(receiver, filter);

该方法必须在Activity或Service类内调用。一般情况下,可以在Activity的onCreate()方法中调用 为保证意外情况导致初始化失败,建议应用程序每次启动时都调用一次该初始化接口。

4.使用华为推送服务

进入Cobub Razor插件华为推送首页,插件会读取所有当前系统中的Android应用列表。 在每个应用后都有推送操作,用户可以根据自身需要进行选择消息类型。 进入推送详细界面,根据要求选择标签或者整个APP推送,填写相关内容并进行推送

5.查看个推推送报告

进入插件中的推送报告模块,用户可以查看用户推送的报告。注:系统只支持30日内推送报告查询服务。用户可通过右上角选择时间段。 推送报告显示了所有激活的APP的推送报告,点击单个APP查看单个应用的推送报告。

6.账户与结算

华为推送插件按月结算,系统会每个月根据用户上个月的用户所有APP在线用户总数来进行结算。 华为推送插件的收费是按照当月在线人数结算,与推送次数无关。 为保证推送服务正常进行,请到个人中心账户充值模块预先充值。

7.常见问题

如何获取Package Name? 应用标识(Package Name),常以com开头 方法:

  • 手机上打开你的应用
  • 点击设置 →; 应用程序 →; 管理应用程序 →; 正在运行,在列表中找到你的程序
  • 在进程中可以看到应用的应用标识(Package Name)
en/razor/plugins/huaweipush.1426737126.txt.gz · 最后更改: 2017/07/14 11:12 (外部编辑)