Android Open Source - GarageRadio Notification Manager






From Project

Back to project page GarageRadio.

License

The source code is released under:

Apache License

If you think the Android project GarageRadio listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.saracraba.garageradio;
//from ww w  . j a v a2  s  . c  o  m
import android.app.Activity;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Intent;

/**
 * Created by Sara Craba.
 *
 * Build and menage a notification that recall a single instanced Activity
 */
public class NotificationManager {

    private static android.app.NotificationManager notificationManager;
    private final Activity mainActivity;

    NotificationManager(Activity mainActivity)
    {
        if (mainActivity== null)
        {
            throw  new NullPointerException();
        }

        this.mainActivity= mainActivity;

        //getting system notification service
        notificationManager= (android.app.NotificationManager) this.mainActivity.getSystemService(Activity.NOTIFICATION_SERVICE);
    }

    private final void startNotification()
    {
        Intent intent = new Intent(mainActivity, MainActivity.class);
        PendingIntent pIntent = PendingIntent.getActivity(mainActivity, 0, intent, 0);

        // build notification
        Notification n  = new Notification.Builder(mainActivity)
                .setContentTitle("Garage Radio")
                .setContentText("La Radio che ti sorprende ti sta tenendo compagnia.")
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentIntent(pIntent).build();

        //fire notification
        notificationManager.notify(0, n);
    }

    private final void stopNotification()
    {
        notificationManager.cancelAll();
    }

    public void start()
    {
        startNotification();
    }

    public void stop()
    {
        stopNotification();
    }

}




Java Source Code List

com.garageradio.app.mainpage.AsyncResponse.java
com.garageradio.app.mainpage.DownloadTitle.java
com.garageradio.app.mainpage.MainActivity.java
com.garageradio.app.palimpsest.DownloadPalimpsest.java
com.garageradio.app.palimpsest.PalimpsestActivity.java
com.garageradio.app.palimpsest.PalimpsestRow.java
com.saracraba.garageradio.ApplicationTest.java
com.saracraba.garageradio.DownloadTitle.java
com.saracraba.garageradio.FirstPageActivity.java
com.saracraba.garageradio.MainActivity.java
com.saracraba.garageradio.MediaPlayerManager.java
com.saracraba.garageradio.NetworkManager.java
com.saracraba.garageradio.NotificationManager.java