Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.goranpjanic.a0504;
- import android.app.NotificationManager;
- import android.app.PendingIntent;
- import android.content.Context;
- import android.content.Intent;
- import android.support.v4.app.NotificationCompat;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- public class MainActivity extends AppCompatActivity {
- private Button button;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- button = findViewById(R.id.button);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- notification();
- }
- });
- }
- private void notification() {
- NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MainActivity.this);
- notificationBuilder.setContentTitle("Notifikacija");
- notificationBuilder.setContentText("Ovo je poruka");
- notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
- Intent intent = new Intent(this, MainActivity.class);
- PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- notificationBuilder.setContentIntent(pendingIntent);
- NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- manager.notify(0, notificationBuilder.build());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement