19 Mart 2017 Pazar

sqllite

https://paste.ubuntu.com/24209958/


package com.example.ahmet.erasmusapp;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.example.ahmet.erasmusapp.SQL_Veritabanı_MesajModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Yenen on 13.3.2017.
 */
public class SQL_MesajVeritabanı extends SQLiteOpenHelper {
    private static final String DATABASE_NAME   = "Mesajlar";
    // Contacts table name
    private static final String TABLE_COUNTRIES = "ÖzelMesaj";
    public SQL_MesajVeritabanı(Context context) {
        super(context, DATABASE_NAME, null, 2);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "CREATE TABLE " + TABLE_COUNTRIES + "(baskaUserid INTEGER,KullaniciAdi TEXT,Mesaj TEXT,TarihZaman TEXT" + ")";
        Log.d("DBHelper", "SQL : " + sql);
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_COUNTRIES);
        onCreate(db);
    }
    public void insertCountry(SQL_Veritabanı_MesajModel sql_veritabanı_mesajModel) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("baskaUserid", sql_veritabanı_mesajModel.getBaskaUserid());
        values.put("KullaniciAdi", sql_veritabanı_mesajModel.getKullanıcıAdi());
        values.put("Mesaj",sql_veritabanı_mesajModel.getMesaj());
        values.put("TarihZaman",sql_veritabanı_mesajModel.getTarihZaman());
        db.insert(TABLE_COUNTRIES, null, values);
        db.close();
    }
    public void MesajlariSilme(int SilinecekId){

        try{
            SQLiteDatabase db = this.getReadableDatabase();
            db.delete(TABLE_COUNTRIES,"baskaUserid"+"="+SilinecekId,null);
            Log.e("Veritabanısilme","Silindi");
        }catch (Exception ex){
            Log.e("Veritabanısilme","Hata oluştu");
        }
    }
    public List<SQL_Veritabanı_MesajModel> getKullanıcıOZelmesajlarıçek(int baskaUserid) {
        List<SQL_Veritabanı_MesajModel> ozelmesaj = new ArrayList<SQL_Veritabanı_MesajModel>();
        SQLiteDatabase db = this.getWritableDatabase();
         String sqlQuery = "SELECT  * FROM " + TABLE_COUNTRIES +" Where baskaUserid="+baskaUserid;
         Cursor cursor = db.rawQuery(sqlQuery, null);
        while (cursor.moveToNext()) {
            SQL_Veritabanı_MesajModel model = new SQL_Veritabanı_MesajModel();
            model.setBaskaUserid(cursor.getInt(0));
            model.setKullanıcıAdi(cursor.getString(1));
            model.setMesaj(cursor.getString(2));
            model.setTarihZaman(cursor.getString(3));
            ozelmesaj.add(model);
        }
        return ozelmesaj;
    }
}

17 Mart 2017 Cuma

bitirme FCM

package com.example.ahmet.erasmusapp;

import android.app.PendingIntent;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.ListView;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    private static final String TAG = "MyFirebaseMsgService";
    public static  ListView özelmesajList;
    @Override
    public void onMessageReceived(final RemoteMessage remoteMessage) {
        if (remoteMessage.getData().size() > 0) { // Data mesajı içeriyor mu
            //Uygulama arkaplanda veya ön planda olması farketmez. Her zaman çağırılacaktır.
            //Gelen içerik json formatındadır.
            Log.d(TAG, "Mesaj data içeriği: " + remoteMessage.getData());
            //Json formatındaki datayı parse edip kullanabiliriz. Biz direk datayı Push Notification olarak bastırıyoruz
            final String[] kelimea =  remoteMessage.getNotification().getTitle().split(",");
            if(kelimea.length ==1){
                sendNotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
                Log.e("uygulamakaoalı:","kelime1e eşit");
            }else {
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        //do stuff on the main thread
                        Log.e("uygulamakaoalı:","kelime1e eşit değil");
                        sendNotification(kelimea[0], remoteMessage.getNotification().getBody());
                        OzelMesaj msj = new OzelMesaj();
                        msj.MesajGeldi(remoteMessage.getNotification().getBody(), remoteMessage.getNotification().getTitle());

                    }
                });
            }
        }
        if (remoteMessage.getNotification() != null) { //Notification mesajı içeriyor mu
            //Uygulama arkaplanda ise burası çağrılmaz.Ön planda ise notification mesajı geldiğinde çağırılır
            //getBody() ile mesaj içeriği
            //getTitle() ile mesaj başlığı
            Log.e(TAG, "Mesaj Notification Başlığı: " + remoteMessage.getNotification().getTitle() +" "+"Mesaj Notification İçeriği: " + remoteMessage.getNotification().getBody() );
              //Gelen içeriğe göre notifikasyon bildiriminde bulunma
            final String[] kelime =  remoteMessage.getNotification().getTitle().split(",");
if(kelime.length ==1){
    sendNotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
}else{
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            //do stuff on the main thread
            sendNotification(kelime[0],remoteMessage.getNotification().getBody());
            OzelMesaj msj = new OzelMesaj();
            msj.MesajGeldi(remoteMessage.getNotification().getBody(),remoteMessage.getNotification().getTitle());

        }
    });
}


        }

    }

    private void sendNotification(String messageTitle,String messageBody) {

        Intent intent = new Intent(this, TabbedActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        long[] pattern = {500,500,500,500};//Titreşim ayarı

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.faceiconn)
                .setContentTitle(messageTitle)
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setVibrate(pattern)
                .setContentIntent(pendingIntent);

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

        try {
            Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
                    + "://" + this.getPackageName() + "/raw/notification");
            Ringtone r = RingtoneManager.getRingtone(this, alarmSound);
            r.play();
        } catch (Exception e) {
            e.printStackTrace();
        }

        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
    }
}