Add a user to a firebase group












-1















So I tried adding a user to a firebase group to be able to send data notification to multiple user on a simple app that show the notification when it receives it.



My problem is that following the firebase documentation I tried adding the following line to my mainactivity.java



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


But android studio told me that the .getInstance couldn't be called/"Cannot resolve symbol 'getInstance'é it so I don't know what to do to make it work



edit:



The app 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'
}


The Project 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
}


and if needed this is what the mainactivity does :



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");


}









share|improve this question

























  • Can we see your firebase dependecies?

    – DevMike01
    Jan 2 at 18:20











  • Just added it all

    – Shayru
    Jan 2 at 18:46


















-1















So I tried adding a user to a firebase group to be able to send data notification to multiple user on a simple app that show the notification when it receives it.



My problem is that following the firebase documentation I tried adding the following line to my mainactivity.java



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


But android studio told me that the .getInstance couldn't be called/"Cannot resolve symbol 'getInstance'é it so I don't know what to do to make it work



edit:



The app 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'
}


The Project 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
}


and if needed this is what the mainactivity does :



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");


}









share|improve this question

























  • Can we see your firebase dependecies?

    – DevMike01
    Jan 2 at 18:20











  • Just added it all

    – Shayru
    Jan 2 at 18:46
















-1












-1








-1








So I tried adding a user to a firebase group to be able to send data notification to multiple user on a simple app that show the notification when it receives it.



My problem is that following the firebase documentation I tried adding the following line to my mainactivity.java



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


But android studio told me that the .getInstance couldn't be called/"Cannot resolve symbol 'getInstance'é it so I don't know what to do to make it work



edit:



The app 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'
}


The Project 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
}


and if needed this is what the mainactivity does :



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");


}









share|improve this question
















So I tried adding a user to a firebase group to be able to send data notification to multiple user on a simple app that show the notification when it receives it.



My problem is that following the firebase documentation I tried adding the following line to my mainactivity.java



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


But android studio told me that the .getInstance couldn't be called/"Cannot resolve symbol 'getInstance'é it so I don't know what to do to make it work



edit:



The app 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'
}


The Project 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
}


and if needed this is what the mainactivity does :



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");


}






android firebase firebase-cloud-messaging






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 19:42









Frank van Puffelen

241k29386413




241k29386413










asked Jan 2 at 18:17









ShayruShayru

33




33













  • Can we see your firebase dependecies?

    – DevMike01
    Jan 2 at 18:20











  • Just added it all

    – Shayru
    Jan 2 at 18:46





















  • Can we see your firebase dependecies?

    – DevMike01
    Jan 2 at 18:20











  • Just added it all

    – Shayru
    Jan 2 at 18:46



















Can we see your firebase dependecies?

– DevMike01
Jan 2 at 18:20





Can we see your firebase dependecies?

– DevMike01
Jan 2 at 18:20













Just added it all

– Shayru
Jan 2 at 18:46







Just added it all

– Shayru
Jan 2 at 18:46














1 Answer
1






active

oldest

votes


















0














The problem is not with Firebase, rather its with your code. Subscribe to the topic in your onCreate() method, not outside a method.



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





share|improve this answer
























  • The method is finally recognized seems like it'll work, thanks

    – Shayru
    Jan 2 at 19:08











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011235%2fadd-a-user-to-a-firebase-group%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The problem is not with Firebase, rather its with your code. Subscribe to the topic in your onCreate() method, not outside a method.



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





share|improve this answer
























  • The method is finally recognized seems like it'll work, thanks

    – Shayru
    Jan 2 at 19:08
















0














The problem is not with Firebase, rather its with your code. Subscribe to the topic in your onCreate() method, not outside a method.



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





share|improve this answer
























  • The method is finally recognized seems like it'll work, thanks

    – Shayru
    Jan 2 at 19:08














0












0








0







The problem is not with Firebase, rather its with your code. Subscribe to the topic in your onCreate() method, not outside a method.



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





share|improve this answer













The problem is not with Firebase, rather its with your code. Subscribe to the topic in your onCreate() method, not outside a method.



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






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 18:59









DevMike01DevMike01

8231920




8231920













  • The method is finally recognized seems like it'll work, thanks

    – Shayru
    Jan 2 at 19:08



















  • The method is finally recognized seems like it'll work, thanks

    – Shayru
    Jan 2 at 19:08

















The method is finally recognized seems like it'll work, thanks

– Shayru
Jan 2 at 19:08





The method is finally recognized seems like it'll work, thanks

– Shayru
Jan 2 at 19:08




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011235%2fadd-a-user-to-a-firebase-group%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas