xec*_*c86 55 android firebase google-cloud-messaging firebase-cloud-messaging
我有火力点云信息的问题,我从设备获取的令牌,并不过,在透过谷歌火力地堡通知控制台发送通知测试,该通知从未登录,也被推到了Android的虚拟设备.对于FCM的文档几乎一模一样,我有以下及一些其它在还有什么你必须做的就是推送通知与火力的工作方式的代码.我已经完成了所有的设置信息了(的build.gradle增加,安装谷歌播放服务等)的文件中规定,但仍然没有消息产生.我按下通知后立即收到一次性错误,指出"I/FA:找不到标签管理器,因此不会被使用",但这是唯一输出的数据,我没有找到与标签相关的任何内容经理要求和谷歌上的FCM.我没有收到对logcat或设备的推送通知的代码有什么问题?请让我知道任何有用的进一步信息.谢谢.
NotificationGenie.java
public class NotificationGenie extends FirebaseMessagingService {
private static final String TAG = "Firebase_MSG";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
sendNotification(remoteMessage.getNotification().getBody());
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, PostLoginActivity.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);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.tf2spyprofile)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.test.movile_android">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DashBoardActivity"
android:label="@string/title_activity_dash_board"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".NewOrderActivity"
android:label="@string/title_activity_dash_board"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".PostLoginActivity"
android:label="@string/title_activity_dash_board"
android:theme="@style/AppTheme.NoActionBar">
</activity>
</application>
<service
android:name=".NotificationGenie">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
Tri*_*ard 51
您已将服务放在应用程序标记之外.改变底部.
<service
android:name=".NotificationGenie">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
Run Code Online (Sandbox Code Playgroud)
Hob*_*oby 37
我有同样的问题,它通过在我的服务中定义enabled,导出为true来解决
<service
android:name=".MyFirebaseMessagingService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
Htm*_*sin 33
"您还必须记住,要接收从Firebase控制台发送的消息,应用程序必须处于后台,而不是既未隐藏也未启动." ---根据@Laurent Russier的评论.
我从来没有从Firebase收到任何消息,直到我将我的应用程序放在后台.
这仅适用于模拟器的USB连接,您也可以在前台获得通知
我遇到了设备未收到的Firebase云消息传递问题.
在我的案例中,Firebase控制台项目中定义的包名称与我在Android项目的Manifest&Gradle上定义的包名称不同.
结果我正确地收到了令牌,但根本没有收到任何消息.
要进行sumarize,Firebase控制台包名称和Manifest&Gradle必须匹配.
您还必须记住,要接收从Firebase控制台发送的消息,应用程序必须位于后台,不能同时启动.
我遇到了类似的问题,但在我的情况下,我错过了Gradle版本中的google-services
插件(我将Firebase添加到现有项目中).
我在我的根目录中添加了以下内容build.gradle
:
classpath 'com.google.gms:google-services:3.1.0'
Run Code Online (Sandbox Code Playgroud)
和以下到我的app
级别的结尾build.gradle
:
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)
然后,我必须google-services.json
从Firebase控制台下载文件(最初导入现有的Google Cloud项目)并将其复制到我的app
目录`.
我遇到了同样的问题,但我的旧版GCM的清单中仍然有一些碎片.当我从我的清单中取出以下权限时,它修复了错误.com.google.android.c2dm.permission.RECEIVE
在这个问题上花了几个小时后,当我故意破坏“google-services.json”的格式并且我的构建仍然成功时,我终于意识到了问题。我的IDE(AndroidStudio)没有注意到这个文件中的更改。我尝试了很多东西,“从磁盘重新加载”,gradle 任务“cleanBuildCache”,新的虚拟设备,卸载/重新安装应用程序等,但都不起作用。
对我来说,解决方案AndroidStudio -> Build -> Clean Project
是Build -> Rebuild Project
PS:还要确保“google-services.json”位于“app”文件夹中。
就我而言,我注意到 mergemanifest 缺少接收器。所以我必须包括:
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
107794 次 |
最近记录: |