android 干净架构,android – FCMMessagingService在干净的架构中?

我正在开发一个使用Firebase云消息传递的应用程序.我正在为我的应用程序使用干净的架构.我想知道在哪里(在哪一层:数据,域,表示)是我的类的最佳解决方案,我的类名为MyFirebaseMessagingService和MyFirebaseInstanceServiceID?

这些是我的课程:

myFirebaseMessagingService:

public class myFirebaseMessagingService extends FirebaseMessagingService {

private static final String TAG="MyFirebaseMsgService";

@Override

public void onMessageReceived(RemoteMessage remoteMessage) {

super.onMessageReceived(remoteMessage);

Log.d("onMessageReceived", "Pozvana funkcija onMessageReceived");

Log.d(TAG, "From " + remoteMessage.getFrom());

Log.d(TAG, "Body " + remoteMessage.getNotification().getBody());

Log.d(TAG, "Location " + remoteMessage.getNotification().getClickAction());

Log.d(TAG, "Value " + remoteMessage.getData().get("click_action"));

sendNotification(remoteMessage);

Log.d("Function called", "sendNotification");

}

private void sendNotification(RemoteMessage remoteMessage) {

Intent intent = new Intent(myFirebaseMessagingService.this, MainActivity.class);

intent.putExtra("click_action", "goToFragment1");

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

NotificationCompat.Builder notification=new NotificationCompat.Builder(this)

.setSmallIcon(logo)

.setContentText(remoteMessage.getNotification().getBody())

.setContentTitle("Title")

.setAutoCancel(true)

.setSound(defaultSoundUri)

.setContentIntent(pendingIntent);

NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0, notification.build());

String message=remoteMessage.getNotification().getBody();

DataBaseHelper db=new DataBaseHelper(this);

db.insertMsg(message);

intent.putExtra("poruka",message );

Log.d("Log>Poruka", message);

}

这是myFirebaseInstanceServiceID:

public class myFirebaseInstanceServiceID extends FirebaseInstanceIdService {

private static final String TAG = "MyFirebaseIIDService";

@Override

public void onTokenRefresh() {

super.onTokenRefresh();

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

}

private void sendRegistrationToServer(String token) {

// Add custom implementation, as needed.

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值