Android Open Source - example-lock-app Notification Status






From Project

Back to project page example-lock-app.

License

The source code is released under:

Apache License

If you think the Android project example-lock-app 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.lockapp.fragments;
/*from  w w  w  .  j  a v a2 s .  c  o  m*/
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

import com.lockapp.LockDeviceReceiver;
import com.lockapp.R;

public class NotificationStatus {
    private static final int ID = 1, REQUEST_CODE = 123;
    private static NotificationStatus mInstance;

    private boolean mHasNotification = false;
    private NotificationStatus() {
    }

    private static void checkInstance() {
        if (mInstance == null) {
            mInstance = new NotificationStatus();
        }
    }
    public static boolean hasNotification() {
        checkInstance();
        return mInstance.mHasNotification;
    }

    public static void cancelNotification(Context context) {
        checkInstance();
        ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).cancel(ID);
        mInstance.mHasNotification = false;
    }

    public static void createNotification(Context context) {
        checkInstance();
        Intent lockIntent = new Intent (context, LockDeviceReceiver.class);
        PendingIntent pendIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        Notification notification = new NotificationCompat.Builder(context)
                .setContentTitle("Lock Device")
                .setContentText("Touch to lock now")
                .setOngoing(true)
                .setShowWhen(false)
                .setSmallIcon (R.drawable.ic_stat_lock)
                .setContentIntent(pendIntent)
                .setVisibility(NotificationCompat.VISIBILITY_SECRET)
                .build();
        ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify (ID, notification);
        mInstance.mHasNotification = true;
    }
}




Java Source Code List

com.lockapp.AboutActivity.java
com.lockapp.LockDeviceReceiver.java
com.lockapp.LockWidgetProvider.java
com.lockapp.MainActivity.java
com.lockapp.fragments.FragmentUtils.java
com.lockapp.fragments.NotificationStatus.java
com.lockapp.fragments.PromptUtils.java
com.lockapp.fragments.lollipop.ControlsFragment.java
com.lockapp.fragments.lollipop.ControlsUtils.java
com.lockapp.fragments.lollipop.PromptFragment.java
com.lockapp.fragments.others.ControlsFragment.java
com.lockapp.fragments.others.PromptFragment.java