NotifierActivity.java


Dosyayı İndir
package com.godoro.androidnavigations;

import android.app.Activity;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


public class NotifierActivity extends AppCompatActivity {

    private TextView messageView;
    private Button notifyButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notifier);
        messageView=(TextView) findViewById(R.id.messageView);
        notifyButton=(Button) findViewById(R.id.notifyButton);
        notifyButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendNotification();
            }
        });
    }
    private void sendNotification(){
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(
                    "com.godoro.androidnavigations", "Bizim Ark", NotificationManager.IMPORTANCE_LOW);
            channel.enableLights(true);
            notificationManager.createNotificationChannel(channel);
        }

        Intent notifiedIntent = new Intent(this, NotifiedActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifiedIntent, 0);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this,
                    "com.godoro.androidnavigations")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Bildirim Başlığı ")
                .setContentText("Bildirimin ayrıntılı açıklaması")
                .setContentIntent(pendingIntent)
                .setAutoCancel(true);

        int notificationId=1234;
        notificationManager.notify(notificationId,builder.build());
        messageView.setText("Bildirim gönderildi.");

    }



}

				
Dosyayı İndir

Bu Sayfayı Paylaş:




Bu Sayfayı Paylaş:

İletişim Bilgileri

Takip Et

Her Hakkı Saklıdır. Bu sitede yayınlanan tüm bilgi ve fikirlerin kullanımından fibiler.com sorumlu değildir. Bu sitede üretilmiş , derlenmiş içerikleri, fibiler.com'u kaynak göstermek koşuluyla kendi sitenizde kullanılabilirsiniz. Ancak telif hakkı olan içeriklerin hakları sahiplerine aittir