Android-极光推送集成流程

一、添加依赖

//极光推送
compile 'cn.jiguang.sdk:jpush:3.0.0'
compile 'cn.jiguang.sdk:jcore:1.0.0'

二、配置参数

//defaultConfig{
    JPUSH_PKGNAME : applicationId,
    JPUSH_APPKEY : "501e0f31b4e163e1", //JPush上注册的包名对应的appkey.
    JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.   
}

三、配置清单文件

1.添加必要的权限
2.注册广播接受者
    
    
        

            
            
            
            
            
            
            
            
            
            

            
        
    

四、创建Receiver类

    public class PushReceiver extends BroadcastReceiver{
    private static final String TAG = "PushReceiver";

    private NotificationManager nm;
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("lyt","receiver called");
        if (null == nm) {
            nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        }

        Bundle bundle = intent.getExtras();
    //     Log.d(TAG, "onReceive - " + intent.getAction() + ", extras: " + AndroidUtil.printBundle(bundle));

        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, "接受到推送下来的通知");

            receivingNotification(context,bundle);

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

    //      openNotification(context,bundle);
            openLaikan(context);

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

五、在Application中初始化Jpush

JPushInterface.init(this);
JPushInterface.setDebugMode(true);  // 极光推送 设置开启日志,发布时请关闭日志

你可能感兴趣的:(Android-极光推送集成流程)