仰天大笑出门去,我辈岂是蓬蒿人。这篇文章主要讲述Android- App不会从解析平台接收推送通知相关的知识,希望能为你提供帮助。
我在解析平台上使用但我无法在我的设备上收到任何通知。
这是我的manifest
:
<
?xml version="1.0" encoding="utf-8"?>
<
manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lib.finder.ir.deletme">
<
uses-permission android:name="android.permission.INTERNET" />
<
uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<
uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<
uses-permission android:name="android.permission.WAKE_LOCK" />
<
uses-permission android:name="android.permission.VIBRATE" />
<
application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<
service
android:name="com.parse.fcm.ParseFirebaseInstanceIdService"
android:exported="true">
<
intent-filter>
<
action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
<
/intent-filter>
<
/service>
<
service
android:name="com.parse.fcm.ParseFirebaseMessagingService"
android:exported="false">
<
intent-filter>
<
action android:name="com.google.firebase.MESSAGING_EVENT" />
<
/intent-filter>
<
/service>
<
receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<
intent-filter>
<
action android:name="com.parse.push.intent.RECEIVE" />
<
action android:name="com.parse.push.intent.DELETE" />
<
action android:name="com.parse.push.intent.OPEN" />
<
/intent-filter>
<
/receiver>
<
meta-data
android:name="com.parse.push.notification_icon"
android:resource="@drawable/ic_message" />
<
activity android:name=".MainActivity">
<
intent-filter>
<
action android:name="android.intent.action.MAIN" />
<
category android:name="android.intent.category.LAUNCHER" />
<
/intent-filter>
<
/activity>
<
/application>
<
/manifest>
我的
App.java
:public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
// Use for monitoring Parse OkHttp traffic
// Can be Level.BASIC, Level.HEADERS, or Level.BODY
// See http://square.github.io/okhttp/3.x/logging-interceptor/ to see the options.
OkHttpClient.Builder builder = new OkHttpClient.Builder();
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.networkInterceptors().add(httpLoggingInterceptor);
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("1")
// if defined
.clientKey("1")
.server("http://1:80/parse/")
.clientBuilder(builder)
.build()
);
Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG);
// Save the current Installation to Parse.
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.i("log", "A: successfully subscribed to the broadcast channel.");
} else {
Log.i("log", "B: failed to subscribe for push", e);
}
}
});
}
}
和
GetPush.java
:public class GetPush extends ParsePushBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
}@Override
protected void onPushReceive(Context context, Intent intent) {
super.onPushReceive(context, intent);
}@Override
protected void onPushOpen(Context context, Intent intent) {
super.onPushOpen(context, intent);
}
}
然后我得到
google-services.json
然后添加到我的项目中。{
"project_info": {
"project_number": "344518768459",
"firebase_url": "https://parsetest-f7e60.firebaseio.com",
"project_id": "parsetest-f7e60",
"storage_bucket": "parsetest-f7e60.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:344518768459:android:a36a6a64540561a3",
"android_client_info": {
"package_name": "lib.finder.ir.deletme"
}
},
"oauth_client": [
{
"client_id": "344518768459-09g2pnfhscijt01e4ee8hr02mqaovurh.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyBZg-xc8vq5Eu2OJQIaDTbe91W5l5XA1eA"
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 2
}
}
}
],
"configuration_version": "1"
}
答案试试这个,
在Manifest文件上添加以下代码,
<
meta-data
android:name="com.google.android.gms.version"
android:value="https://www.songbingjia.com/android/@integer/google_play_services_version" />
<
service android:name="com.parse.fcm.MyFirebaseMessagingService">
<
intent-filter>
<
action android:name="com.google.firebase.MESSAGING_EVENT" />
<
/intent-filter>
<
/service>
<
service android:name="com.parse.fcm.MyFirebaseInstanceIDService">
<
intent-filter>
<
action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
<
/intent-filter>
<
/service>
MyFirebaseMessagingService.java文件
public class MyFirebaseMessagingService extends FirebaseMessagingService {
public static String FCMTAG = "FCM Message";
public static String FCMSTATE = "FCMSTATE";
JSONObject jsonObject;
public MyFirebaseMessagingService() {
super();
}@Override
public void onMessageSent(String s) {
Log.v("Fcm", "MyFirebaseMessagingService :: onMessageSent" + s);
super.onMessageSent(s);
}@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
try {
if (remoteMessage != null &
&
remoteMessage.getNotification() != null) {
RemoteMessage.Notification notification = remoteMessage.getNotification();
if (notification.getTitle() != null &
&
notification.getBody() != null) {
String title = notification.getTitle();
String message = notification.getBody();
Log.d("FCM", "Title: " + title + " , Message: " + message);
showStatusBarNotification(title, message);
}
}
} catch (Exception e) {
Log.d("FCM", "Error : " + e.getMessage());
e.printStackTrace();
}
}private void showStatusBarNotification(String title, String sendMessage) {
//Code to show Push notification on Toolbar
}}
MyFirebaseInstanceIDService.java文件
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "Fcm";
Context context;
String token;
public MyFirebaseInstanceIDService() {
}public MyFirebaseInstanceIDService(Context context) {
this.context = context;
onTokenRefresh();
}@Override
public void onTokenRefresh() {
FirebaseApp.initializeApp(context);
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.v(TAG, "MyFirebaseInstanceIDService: Refreshed token: " + refreshedToken);
}public String getToken(){
return token;
}}
现在您需要在Activity页面的
onCreate
函数上初始化MyFirebaseInstanceIDService以生成推送令牌,new MyFirebaseInstanceIDService(ShopLoginActivity.this);
另一答案从以下服务中删除
android:exported="false"
。<
service
android:name="com.parse.fcm.ParseFirebaseMessagingService"
android:exported="false">
<
intent-filter>
<
action android:name="com.google.firebase.MESSAGING_EVENT" />
<
/intent-filter>
<
/service>
【Android- App不会从解析平台接收推送通知】可能来自Firebase配置设置。
也许你应该再次阅读教程。 https://docs.parseplatform.org/tutorials/android-push-notifications/验证你做得很好。由于你的代码很干净,我无法弄清楚出了什么问题
推荐阅读
- 在android studio上设置bitnami Parse服务器的电子邮件验证
- 推送通知未在Android 8.0中使用解析sdk显示
- Android片段和依赖注入
- 如何注入动态创建的用例(android,clean architecture,dagger2)
- 如何在Ninject中使用AutoMApper.5.2.0()
- 在Mapping时向Automapper提供构造函数参数
- 如何将Applescript scpt文件转换为命令
- .Net Core App - 命令行格式异常
- 在Android中登录尝试失败时app崩溃了