我是Android开发新手。 我有在应用程序结算,让人们购买推送通知。如何从共享首选项(Android)的布尔值禁用Firebase消息传递
当我实施Firebase消息传递时。它只是开箱即用。真棒!
但是。如果没有购买,我现在想禁用它。 (在共享偏好存储布尔值)
我不知道如何解决这个问题。
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO: 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.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
}
和
public class FirebaseIDService extends FirebaseInstanceIdService {
private static final String TAG = "FirebaseIDService";
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// TODO: Implement this method to send any registration to your app's servers.
sendRegistrationToServer(refreshedToken);
}
/**
* Persist token to third-party servers.
*
* Modify this method to associate the user's FCM InstanceID token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
private void sendRegistrationToServer(String token) {
// Add custom implementation, as needed.
}
}
清单:(内部应用标签)
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".FirebaseIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
我已经存储在共享偏好的布尔称为 “通知”
基本上我的问题是: 我在哪里放
if(boolean == true){
// do notification (no clue what this method would be)
}
我在哪里寻找或做什么搜索? 请点我在正确的方向:)
亲切的问候,
克里斯
其中所有通知都显示根据通知变量的状态禁用它们。 我可能不清楚你的问题! –
你使用'notification'或'data'类型的消息吗? – Wilik
@nightcoder。问题是我不知道通知显示的位置在哪里。 – Chrizlee