Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Firebase控制台中哪里可以看到上游消息?_Firebase_Firebase Cloud Messaging - Fatal编程技术网

在Firebase控制台中哪里可以看到上游消息?

在Firebase控制台中哪里可以看到上游消息?,firebase,firebase-cloud-messaging,Firebase,Firebase Cloud Messaging,我最近开始使用Firebase Messaging,我希望其中一个客户端生成一个通知,可以通过应用程序发送给其他用户 所以,通过向服务器上游发送消息,然后再从服务器向其他有应用程序的设备发送消息似乎是一个解决方案 在firebase控制台的何处可以看到我的firebase上游消息 public class FirebaseNotifier extends FirebaseMessagingService { static FirebaseMessaging fmst; static Fireb

我最近开始使用Firebase Messaging,我希望其中一个客户端生成一个通知,可以通过应用程序发送给其他用户 所以,通过向服务器上游发送消息,然后再从服务器向其他有应用程序的设备发送消息似乎是一个解决方案

在firebase控制台的何处可以看到我的firebase上游消息

public class FirebaseNotifier extends FirebaseMessagingService {

static FirebaseMessaging fmst;
static FirebaseInstanceId fid;
static Button b1;



public void onMessageReceived(RemoteMessage remoteMessage) {

    sendNotification(remoteMessage);
}

private void sendNotification(RemoteMessage remoteMessage) {

    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);


    int icon = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) ? R.drawable.myicon : R.drawable.myicon;
    NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
            .setSmallIcon(icon)
            .setContentTitle(remoteMessage.getFrom())
            .setContentText(remoteMessage.getNotification().getBody())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}


public static void sendEm(AtomicInteger msid,String fms) {


    fmst=MainActivity.fms;



            fmst.send(new RemoteMessage.Builder(fms + "@gcm.googleapis.com")
                    .setMessageId(Integer.toString(msid.incrementAndGet()))
                    .addData("my_message", "fhdhchj")
                    .addData("my_action", "SAY_HELLO")
                    .build());



}

@Override
public void onMessageSent(String s) {
    super.onMessageSent(s);
    Log.i("Message is:", "" + s);
}

public void onSendError(String msgID, Exception exception) {

    Log.i("message id id:"+msgID,"Exception:"+ exception.getMessage());
}
}
我用一个按钮从main打电话

public class MainActivity extends AppCompatActivity {


static EditText et;
Button b1;
static FirebaseMessaging fms;
static  String senderid="";
static  AtomicInteger msgId;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //setSupportActionBar(toolbar);
    b1=(Button)findViewById(R.id.button);
    msgId= new AtomicInteger(1);



    et=(EditText)findViewById(R.id.editText);

    fms=FirebaseMessaging.getInstance();



    b1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(MainActivity.this,"Button Clicked",Toast.LENGTH_SHORT).show();
            FirebaseNotifier.sendEm(msgId, fms.toString());

        }
    });




}



private boolean Validate(EditText et) {


    if(et.getText().toString().length()>0) return true;
    return false;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}





}

要接收使用上游API发送的消息,您需要实现一个XMPP服务器

见:


然后,您的XMPP服务器可以接收上游消息并将通知发送到其他设备。

要接收通过上游API发送的消息,您需要实现XMPP服务器

见:


然后,您的XMPP服务器可以接收上游消息并将通知发送到其他设备。

谢谢,但我应该在服务器端将代码写到哪里?您需要实现一个自定义服务器。部署可以在任何云提供商或内部服务器上进行。谢谢,但我应该在服务器端的何处编写代码?您需要实现自定义服务器。部署可以在任何云提供商或内部服务器上进行。