Coder Social home page Coder Social logo

Comments (4)

stevenxyj avatar stevenxyj commented on August 29, 2024

@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);
    }
    
}

from react-native-xinge-push.

hzl3705 avatar hzl3705 commented on August 29, 2024

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

from react-native-xinge-push.

stevenxyj avatar stevenxyj commented on August 29, 2024

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

from react-native-xinge-push.

hzl3705 avatar hzl3705 commented on August 29, 2024

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

from react-native-xinge-push.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.