Soru & Cevap

Uygulama kapalıyken veri kaydetme ...

29.01.2017 - 11:55

 android ile alakalı bir sorum olacaktı kullanıcılara bildirim mesajı gönderiyorum bunu daha sonra veritabanına kaydediyorum ancak uygulama çalışır haldeyken işlem başarılı oluyor ancak uygulama kapalıyken bildirim geliyor ama veritabanına kayıt olmuyor bu konu ile alakalı bilgisi olan varmı

Bildirim alırken Firebase Messaging Service kullanıyorum kodlar bu şekilde:

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "MyFirebaseMsgService";
    private String bildirim;
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

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

        //Check if the message contains data
        if(remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data: " + remoteMessage.getData());
        }

        //Check if the message contains notification

        if(remoteMessage.getNotification() != null) {
            Log.d(TAG, "Mesage body:" + remoteMessage.getNotification().getBody());
            sendNotification(remoteMessage.getNotification().getBody());
            bildirim=remoteMessage.getNotification().getBody();
            Veritabani db=new Veritabani(this);
            db.VeriEkle(bildirim);
        }

    }

    /**
     * Dispay the notification
     * @param body
     */
    private void sendNotification(String body) {
        Intent intent = new Intent(this, Bildirim.class);

        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0/*Request code*/, intent, PendingIntent.FLAG_ONE_SHOT);
        //Set sound of notification
        Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder notifiBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Bildirim")
                .setContentText(body)
                .setAutoCancel(true)
                .setSound(notificationSound)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0 /*ID of notification*/, notifiBuilder.build());


        //Toast.makeText(getApplicationContext(),bildirim,Toast.LENGTH_LONG).show();
    }

}

 

11 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

Profile picture for user ahmetyenen
ahmetyenen
17.03.2017 - 10:54

Sorunu Çözebildinnmi , Çözebildiysen cevap yazarsan iyi olur aynı sorunla bende karşılaştım çözemiyorum suan