极光推送初识

极光推送文档上注册这些就不说了
写一些自己觉得有用的


1.广播,接到通知以后的处理

public class JPushReceiver extends BroadcastReceiver {

    private static final String TAG = "MyReceiver";
    private NotificationManager nm;
    @Override
    public void onReceive(Context context, Intent intent) {
        if (null == nm) {
            nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        }

        Bundle bundle = intent.getExtras();

        if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
            Log.d(TAG, "JPush用户注册成功");

        } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
            Log.d(TAG, "接受到推送下来的自定义消息");

        } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
            Log.d(TAG, "接受到推送下来的通知");

        } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
            Log.d(TAG, "用户点击打开了通知");

            openNotification(context,bundle);
        } else {
            Log.d(TAG, "Unhandled intent - " + intent.getAction());
        }
    }

    private void openNotification(Context context, Bundle bundle){
        String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
        String url = "";
        String title="";
        try {
            JSONObject extrasJson = new JSONObject(extras);
            Log.i("extrasJson",extrasJson.toString());
            String back=extrasJson.optString("url");
            String top=  back.substring(0,3);
            Log.i("topff",top);
            if(top.equals("app")){
                String exittop=back.substring(6);
                Log.i("exittop",exittop);
                //  ios.YYVoucherViewController.android.MyCouponActivity?
                String exitend= exittop.substring(0,exittop.indexOf("?"));
                Log.i("exitend",exitend);
                //ios.YYVoucherViewController.android.MyCouponActivity
                String[] strs=exitend.split("\\.");

                String togoclass=strs[3].toString();

                  Intent  intent2 =new Intent(context, Class.forName("com.yylc.yylearncar.view.activity.mine."+togoclass));
                context.startActivity(intent2);

            }else {
                url = extrasJson.optString("url");
                title = extrasJson.optString("title");
                Intent intent=new Intent(context, WebActivity.class);
                intent.putExtra("url",url);
                intent.putExtra("title",title);
                Log.i("extrasJson2",url);
                Log.i("extrasJson2",title);
                context.startActivity(intent);
            }

        } catch (Exception e) {
            Log.d(TAG, "Unexpected: extras is not a valid json", e);
            return;
        }
    }
}

记得在配置文件之中,把这个广播注册了


2.如果想精准推送,需要设置alias

JPushInterface.setAlias(getActivity(), 100, MD5Util.MD5(MD5Util.MD5(account)));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值