3
package com.example.dell.notification;
import android.annotation.TargetApi;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.format.Time;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.widget.Button;
import android.widget.Toast;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends ActionBarActivity {  
@Override
protected void onCreate(Bundle savedInstanceState)  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   String currentDateandTime = sdf.format(new Date());
if(currentDateandTime=="2015-05-15"){
}
            showNotification();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void showNotification(){
    // define sound URI, the sound to be played when there's a notification
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    // intent triggered, you can add other intent for other actions
    Intent intent = new Intent(MainActivity.this, NotificationReceiver.class);
    PendingIntent pIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
    // this is it, we'll build the notification!
    // in the addAction method, if you don't want any icon, just set the first param to 0
    Notification mNotification = new Notification.Builder(this)
            .setContentTitle("Vigilia dos Obreiros")
            .setContentText("Hoje, as 22 horas")
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentIntent(pIntent)
            .setSound(soundUri)
            .addAction(R.drawable.abc_ic_ab_back_mtrl_am_alpha, "View", pIntent)
            .addAction(0, "Remind", pIntent)
            .build();
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // If you want to hide the notification after it was selected, do the code below
    // myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, mNotification);
}
public void cancelNotification(int notificationId){
    if (Context.NOTIFICATION_SERVICE!=null) {
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager nMgr = (NotificationManager) getApplicationContext().getSystemService(ns);
        nMgr.cancel(notificationId);
    }
}
}
I implemented the code, but the alarm is not going off, with everything I could understand the way to follow to have my solution. Thank you very much
– Gabriel Manuel