Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

现在小米和魅族官方通道都可以用了? #12

Open
yunuo-tech opened this issue Apr 15, 2018 · 4 comments
Open

现在小米和魅族官方通道都可以用了? #12

yunuo-tech opened this issue Apr 15, 2018 · 4 comments

Comments

@yunuo-tech
Copy link

魅族的没做测试,小米的不行呀。
我看XMMessageReceiver.java里面的方法都是空的~

@stevenxyj
Copy link

stevenxyj commented May 23, 2018

@yunuo-tech XMMessageReceiver.java我是这样添加的,供你参考

package com.jeepeng.react.xgpush.receiver;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Build;
import android.app.NotificationManager;
import android.app.Notification;
import android.util.Log;
import android.text.TextUtils;

import com.xiaomi.mipush.sdk.ErrorCode;
import com.xiaomi.mipush.sdk.MiPushClient;
import com.xiaomi.mipush.sdk.MiPushCommandMessage;
import com.xiaomi.mipush.sdk.MiPushMessage;
import com.xiaomi.mipush.sdk.PushMessageReceiver;

import com.jeepeng.react.xgpush.Constants;
import com.tencent.android.tpush.XGPushClickedResult;

/**
 * 小米官方推送通道消息接收器
 * Created by stevenxyj on 2018/5/12.
 */

public class XMMessageReceiver extends PushMessageReceiver {
    public static final String MODULE_NAME = "XMMessageReceiver";

	//接收服务器向客户端发送的透传消息
    @Override
    public void onReceivePassThroughMessage(Context context, MiPushMessage message) {
        Log.d(MODULE_NAME,
                "onReceivePassThroughMessage is called. " + message.toString());
                
		super.onReceivePassThroughMessage(context, message);
    }
    
    /**
     * 接收服务器向客户端发送的通知消息,
 	 * 这个回调方法会在用户手动点击通知后触发。
     */
    @Override
    public void onNotificationMessageArrived(Context context, MiPushMessage message) {
        Log.d(MODULE_NAME,
                "onNotificationMessageArrived is called. " + message.toString());

        Intent intent = new Intent(Constants.ACTION_ON_TEXT_MESSAGE);
        intent.putExtra("title", message.getTitle());
        intent.putExtra("content", message.getDescription());
        intent.putExtra("custom_content", message.getExtra().toString());
        context.sendBroadcast(intent);
        
		super.onNotificationMessageArrived(context, message);		
   }

    /**
     * 接收服务器向客户端发送的通知消息,
 	 * 这个回调方法是在通知消息到达客户端时触发。另外应用在前台时不弹出通知的通知消息到达客户端也会触发这个回调函数。
     */
    @Override
    public void onNotificationMessageClicked(Context context, MiPushMessage message) {
        Log.d(MODULE_NAME,
                "onNotificationMessageClicked is called. " + message.toString());

	    Intent i = new Intent(); 
		i.setClassName("com.xxxxx.xxxxx", "com.xxxxx.xxxxx.MainActivity");  //your appid
	    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        context.startActivity(i);
                
        Intent intent = new Intent(Constants.ACTION_ON_NOTIFICATION_CLICKED);
        Bundle bundle = new Bundle();
        
        bundle.putString("content", message.getDescription());
        bundle.putString("title", message.getTitle());
        intent.putExtra("custom_content", message.getExtra().toString());
        intent.putExtra("notification", bundle);

        intent.putExtra("title", message.getTitle());
        intent.putExtra("content", message.getDescription());
        intent.putExtra("custom_content", message.getExtra().toString());
        intent.putExtra("activity", message.getCategory());
        intent.putExtra("msgId", message.getMessageId());
        intent.putExtra("notificationActionType", message.getNotifyType());
        context.sendBroadcast(intent);
        
		super.onNotificationMessageClicked(context, message);		
    }
    
    //接收客户端向服务器发送命令后的响应结果
    @Override
    public void onCommandResult(Context context, MiPushCommandMessage message) {
        Log.d(MODULE_NAME,
                "onCommandResult is called. " + message.toString());

		super.onCommandResult(context, message);
    }
	
	//来接收客户端向服务器发送注册命令后的响应结果
    @Override
    public void onReceiveRegisterResult(Context context, MiPushCommandMessage message) {
        Log.d(MODULE_NAME,
                "onReceiveRegisterResult is called. " + message.toString());

		super.onReceiveRegisterResult(context, message);
    }
    
}

@hzl3705
Copy link

hzl3705 commented Oct 13, 2018

@stevenxyj 可以用吗 信鸽推送了 但是未到达设备

@stevenxyj
Copy link

@hzl3705 我的可以用,一直在正常使用中。
是不是 SDK 版本不一样

@hzl3705
Copy link

hzl3705 commented Dec 12, 2018

app关闭时点推送打开app,getInitialNotification() 获取不到推送的数据,请问有人解决吗 ?
相关问题底下可能没人回复,到这来提问,见谅见谅!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants