将用户添加到Firebase组

时间:2019-01-02 18:17:42

标签: android firebase firebase-cloud-messaging

因此,我尝试将用户添加到Firebase组中,以便能够在一个简单的应用程序上向多个用户发送数据通知,该应用程序会在收到通知时显示通知。

我的问题是,根据firebase文档,我尝试将以下行添加到mainactivity.java

FirebaseMessaging.getInstance().subscribeToTopic("weather")

但是android studio告诉我.getInstance不能被调用/“无法解析符号'getInstance'é,因此我不知道该怎么做才能使它起作用

编辑:

应用程序build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.shayru.myapplication"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'com.google.firebase:firebase-core:16.0.6'
}

项目build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

如果需要,这是mainactivity的作用:

package com.shayru.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.firebase.messaging.FirebaseMessaging;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    FirebaseMessaging.getInstance().subscribeToTopic("News");


}

1 个答案:

答案 0 :(得分:0)

问题不在于Firebase,而在于您的代码。在您的[[[ 0.35294118 0.39607843 0.41960784] [ 0.38039216 0.42352941 0.44705882] [ 0.41568627 0.45098039 0.47058824] ..., [ 0.05490196 0.04705882 0.05098039] [ 0.04705882 0.03921569 0.04313725] [ 0.04313725 0.03529412 0.03921569]] [[ 0.36470588 0.4 0.42745098] [ 0.38823529 0.42352941 0.44313725] [ 0.40784314 0.44313725 0.4627451 ] ..., etc ] 方法中而不是方法之外订阅主题。

onCreate()