Exemple #1
0
 //send msg to MainActivity
 private void processCustomMessage(Context context, Bundle bundle)
 {
     if (MainActivity.isForeground)
     {
         string message   = bundle.GetString(JPushInterface.EXTRA_MESSAGE);
         string extras    = bundle.GetString(JPushInterface.EXTRA_EXTRA);
         Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
         msgIntent.PutExtra(MainActivity.KEY_MESSAGE, message);
         if (!ExampleUtil.isEmpty(extras))
         {
             try
             {
                 JSONObject extraJson = new JSONObject(extras);
                 if (extraJson.length() > 0)
                 {
                     msgIntent.PutExtra(MainActivity.KEY_EXTRAS, extras);
                 }
             }
             catch (JSONException)
             {
             }
         }
         //LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
     }
 }
        public virtual void onAliasOperatorResult(Context context, JPushMessage jPushMessage)
        {
            int sequence = jPushMessage.Sequence;

            Logger.i(TAG, "action - onAliasOperatorResult, sequence:" + sequence + ",alias:" + jPushMessage.Alias);
            init(context);
            //根据sequence从之前操作缓存中获取缓存记录
            TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.Get(sequence);

            if (tagAliasBean == null)
            {
                ExampleUtil.showToast("获取缓存记录失败", context);
                return;
            }
            if (jPushMessage.ErrorCode == 0)
            {
                Logger.i(TAG, "action - modify alias Success,sequence:" + sequence);
                setActionCache.Remove(sequence);
                string logs = getActionStr(tagAliasBean.action) + " alias success";
                Logger.i(TAG, logs);
                ExampleUtil.showToast(logs, context);
            }
            else
            {
                string logs = "Failed to " + getActionStr(tagAliasBean.action) + " alias, errorCode:" + jPushMessage.ErrorCode;
                Logger.e(TAG, logs);
                if (!RetryActionIfNeeded(jPushMessage.ErrorCode, tagAliasBean))
                {
                    ExampleUtil.showToast(logs, context);
                }
            }
        }
 //send msg to MainActivity
 private void processCustomMessage(Context context, CustomMessage customMessage)
 {
     if (MainActivity.isForeground)
     {
         string message   = customMessage.Message;
         string extras    = customMessage.Extra;
         Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
         msgIntent.PutExtra(MainActivity.KEY_MESSAGE, message);
         if (!ExampleUtil.isEmpty(extras))
         {
             try
             {
                 Newtonsoft.Json.Linq.JObject extraJson = Newtonsoft.Json.Linq.JObject.Parse(extras);
                 if (extraJson != null)
                 {
                     msgIntent.PutExtra(MainActivity.KEY_EXTRAS, extras);
                 }
             }
             catch (Newtonsoft.Json.JsonException ex)
             {
             }
         }
         // LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
     }
 }
        private void initView()
        {
            TextView mImei = (TextView)FindViewById(JPush.Resource.Id.tv_imei);
            string   udid  = ExampleUtil.getImei(ApplicationContext, "");

            if (null != udid)
            {
                mImei.Text = "IMEI: " + udid;
            }

            TextView mAppKey = (TextView)FindViewById(JPush.Resource.Id.tv_appkey);
            string   appKey  = ExampleUtil.getAppKey(ApplicationContext);

            if (null == appKey)
            {
                appKey = "AppKey异常";
            }
            mAppKey.Text = "AppKey: " + appKey;

            mRegId      = (TextView)FindViewById(JPush.Resource.Id.tv_regId);
            mRegId.Text = "RegId:";

            string   packageName = PackageName;
            TextView mPackage    = (TextView)FindViewById(JPush.Resource.Id.tv_package);

            mPackage.Text = "PackageName: " + packageName;

            string   deviceId  = ExampleUtil.getDeviceId(ApplicationContext);
            TextView mDeviceId = (TextView)FindViewById(JPush.Resource.Id.tv_device_id);

            mDeviceId.Text = "deviceId: " + deviceId;

            string   versionName = ExampleUtil.GetVersion(ApplicationContext);
            TextView mVersion    = (TextView)FindViewById(JPush.Resource.Id.tv_version);

            mVersion.Text = "Version: " + versionName;

            mInit        = (Button)FindViewById(JPush.Resource.Id.init);
            mInit.Click += OnClick;
            mStopPush    = (Button)FindViewById(JPush.Resource.Id.stopPush);

            mStopPush.Click += OnClick;
            mResumePush      = (Button)FindViewById(JPush.Resource.Id.resumePush);

            mResumePush.Click += OnClick;
            mGetRid            = (Button)FindViewById(JPush.Resource.Id.getRegistrationId);

            mGetRid.Click += OnClick;
            mSetting       = (Button)FindViewById(JPush.Resource.Id.setting);

            mSetting.Click += OnClick;
            msgText         = (EditText)FindViewById(JPush.Resource.Id.msg_rec);
        }
Exemple #5
0
        private void handleSetMobileNumber()
        {
            EditText mobileEdit   = (EditText)findViewById(R.id.et_mobilenumber);
            string   mobileNumber = mobileEdit.Text.ToString().Trim();

            if (TextUtils.isEmpty(mobileNumber))
            {
                Toast.makeText(ApplicationContext, [email protected]_empty_guide, Toast.LENGTH_SHORT).show();
            }
            if (!ExampleUtil.isValidMobileNumber(mobileNumber))
            {
                Toast.makeText(ApplicationContext, [email protected]_tag_gs_empty, Toast.LENGTH_SHORT).show();
                return;
            }
            sequence++;
            TagAliasOperatorHelper.Instance.handleAction(ApplicationContext, sequence, mobileNumber);
        }
 public override void OnReceive(Context context, Intent intent)
 {
     try
     {
         if (MESSAGE_RECEIVED_ACTION.Equals(intent.Action))
         {
             string        messge  = intent.GetStringExtra(KEY_MESSAGE);
             string        extras  = intent.GetStringExtra(KEY_EXTRAS);
             StringBuilder showMsg = new StringBuilder();
             showMsg.Append(KEY_MESSAGE + " : " + messge + "\n");
             if (!ExampleUtil.isEmpty(extras))
             {
                 showMsg.Append(KEY_EXTRAS + " : " + extras + "\n");
             }
             outerInstance.CostomMsg = showMsg.ToString();
         }
     }
     catch (System.Exception ex)
     {
     }
 }
        //设置手机号码回调
        public virtual void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage)
        {
            int sequence = jPushMessage.Sequence;

            Logger.i(TAG, "action - onMobileNumberOperatorResult, sequence:" + sequence + ",mobileNumber:" + jPushMessage.MobileNumber);
            init(context);
            if (jPushMessage.ErrorCode == 0)
            {
                Logger.i(TAG, "action - set mobile number Success,sequence:" + sequence);
                setActionCache.Remove(sequence);
            }
            else
            {
                string logs = "Failed to set mobile number, errorCode:" + jPushMessage.ErrorCode;
                Logger.e(TAG, logs);
                if (!RetrySetMObileNumberActionIfNeeded(jPushMessage.ErrorCode, jPushMessage.MobileNumber))
                {
                    ExampleUtil.showToast(logs, context);
                }
            }
        }
        public virtual void onTagOperatorResult(Context context, JPushMessage jPushMessage)
        {
            int sequence = jPushMessage.Sequence;

            Logger.i(TAG, "action - onTagOperatorResult, sequence:" + sequence + ",tags:" + jPushMessage.Tags);
            Logger.i(TAG, "tags size:" + jPushMessage.Tags.Count);
            init(context);
            //根据sequence从之前操作缓存中获取缓存记录
            TagAliasBean tagAliasBean = (TagAliasBean)setActionCache.Get(sequence);

            if (tagAliasBean == null)
            {
                ExampleUtil.showToast("获取缓存记录失败", context);
                return;
            }
            if (jPushMessage.ErrorCode == 0)
            {
                Logger.i(TAG, "action - modify tag Success,sequence:" + sequence);
                setActionCache.Remove(sequence);
                string logs = getActionStr(tagAliasBean.action) + " tags success";
                Logger.i(TAG, logs);
                ExampleUtil.showToast(logs, context);
            }
            else
            {
                string logs = "Failed to " + getActionStr(tagAliasBean.action) + " tags";
                if (jPushMessage.ErrorCode == 6018)
                {
                    //tag数量超过限制,需要先清除一部分再add
                    logs += ", tags is exceed limit need to clean";
                }
                logs += ", errorCode:" + jPushMessage.ErrorCode;
                Logger.e(TAG, logs);
                if (!RetryActionIfNeeded(jPushMessage.ErrorCode, tagAliasBean))
                {
                    ExampleUtil.showToast(logs, context);
                }
            }
        }
 private bool RetrySetMObileNumberActionIfNeeded(int errorCode, string mobileNumber)
 {
     if (!ExampleUtil.isConnected(context))
     {
         Logger.w(TAG, "no network");
         return(false);
     }
     //返回的错误码为6002 超时,6024 服务器内部错误,建议稍后重试
     if (errorCode == 6002 || errorCode == 6024)
     {
         Logger.d(TAG, "need retry");
         Message message = new Message();
         message.What = DELAY_SET_MOBILE_NUMBER_ACTION;
         message.Obj  = mobileNumber;
         delaySendHandler.SendMessageDelayed(message, 1000 * 60);
         string str = "Failed to set mobile number due to %s. Try again after 60s.";
         str = Java.Lang.String.Format(Locale.English, str, (errorCode == 6002 ? "timeout" : "server internal error”"));
         ExampleUtil.showToast(str, context);
         return(true);
     }
     return(false);
 }
 private bool RetryActionIfNeeded(int errorCode, TagAliasBean tagAliasBean)
 {
     if (!ExampleUtil.isConnected(context))
     {
         Logger.w(TAG, "no network");
         return(false);
     }
     //返回的错误码为6002 超时,6014 服务器繁忙,都建议延迟重试
     if (errorCode == 6002 || errorCode == 6014)
     {
         Logger.d(TAG, "need retry");
         if (tagAliasBean != null)
         {
             Message message = new Message();
             message.What = DELAY_SEND_ACTION;
             message.Obj  = tagAliasBean;
             delaySendHandler.SendMessageDelayed(message, 1000 * 60);
             string logs = getRetryStr(tagAliasBean.isAliasAction, tagAliasBean.action, errorCode);
             ExampleUtil.showToast(logs, context);
             return(true);
         }
     }
     return(false);
 }