FCM, I can not create topics / topics to send notifications

0

I have an application that uses the firebase notification service, the problem is that I can not create topics or topics, seeing the documentation would be created with the following line:

FirebaseMessaging.getInstance().subscribeToTopic(nuevasVias);

I will leave you the 2 classes I use and the manifesto:

public class Firebase_Instance_ID_Service extends FirebaseInstanceIdService {

    final static String tokenPreferenceKey="fcm_token";
    final static String nuevasVias="Nuevas Ciclovias";

    @Override
    public void onTokenRefresh(){
        super.onTokenRefresh();
        SharedPreferences sharedPreferences= PreferenceManager.getDefaultSharedPreferences(this);
        sharedPreferences.edit().putString(tokenPreferenceKey, FirebaseInstanceId.getInstance().getToken());


        FirebaseMessaging.getInstance().subscribeToTopic(nuevasVias);
    }
}

the second class is:

public class NotificacionesFirebase extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage){

        FirebaseMessaging.getInstance().subscribeToTopic(Firebase_Instance_ID_Service.nuevasVias);
        if(remoteMessage.getFrom().equals("/topics/"+Firebase_Instance_ID_Service.nuevasVias)){
            recibirMensaje("Nuevas Ciclovías",remoteMessage.getNotification().getBody());
        }
        else{
                recibirMensaje("CicloMapp",remoteMessage.getNotification().getBody());
        }

    }

    private void recibirMensaje(String title,String contentText){
        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Intent intent= new Intent(this,MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent= PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder notificationBuilder= new NotificationCompat.Builder(this);
        notificationBuilder.setContentTitle(title);
        notificationBuilder.setContentText(contentText);
        notificationBuilder.setAutoCancel(true);
        notificationBuilder.setSound(defaultSoundUri);
        notificationBuilder.setSmallIcon(R.drawable.logo);
        notificationBuilder.setContentIntent(pendingIntent);
        NotificationManager notificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0,notificationBuilder.build());
    }
}

and the manifesto

<!-- To auto-complete the email text field in the login form with the user's emails -->

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<application
    android:name=".Facebook"
    android:allowBackup="true"
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="value" />
    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />

    <activity
        android:name=".Inicio"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Login"
        android:label="@string/app_name">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".Inicio" />
    </activity>
    <activity android:name=".Registrarse" />
    <activity
        android:name=".MainActivity"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity android:name=".Valoraraciones" />
    <activity android:name=".Reportar" />
    <activity android:name=".agregarRuta" />
    <activity android:name=".Tiendas"></activity>
    <service android:name=".NotificacionesFirebase">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"></action>
        </intent-filter>
    </service>
    <service android:name=".Firebase_Instance_ID_Service">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"></action>
        </intent-filter>
    </service>
</application>

pd: I only have problems with the creation of topics, I can send notifications to all users or to one in specific, the problem is that the topic is not created

    
asked by zhet 09.12.2016 в 18:29
source

0 answers