Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. package com.example.goranpjanic.a0504;
  2.  
  3. import android.app.NotificationManager;
  4. import android.app.PendingIntent;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.support.v4.app.NotificationCompat;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.widget.Button;
  12.  
  13. public class MainActivity extends AppCompatActivity {
  14.  
  15.     private Button button;
  16.  
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.activity_main);
  21.  
  22.         button = findViewById(R.id.button);
  23.         button.setOnClickListener(new View.OnClickListener() {
  24.             @Override
  25.             public void onClick(View v) {
  26.                 notification();
  27.             }
  28.         });
  29.     }
  30.  
  31.     private void notification() {
  32.         NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MainActivity.this);
  33.  
  34.         notificationBuilder.setContentTitle("Notifikacija");
  35.         notificationBuilder.setContentText("Ovo je poruka");
  36.         notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
  37.  
  38.         Intent intent = new Intent(this, MainActivity.class);
  39.         PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  40.  
  41.         notificationBuilder.setContentIntent(pendingIntent);
  42.  
  43.         NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  44.         manager.notify(0, notificationBuilder.build());
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement