Example usage for android.app NotificationManager notify

List of usage examples for android.app NotificationManager notify

Introduction

In this page you can find the example usage for android.app NotificationManager notify.

Prototype

public void notify(int id, Notification notification) 

Source Link

Document

Post a notification to be shown in the status bar.

Usage

From source file:com.boc.lfj.httpdemo.powerrv.demo.NotificationUtil.java

/**
 * ??MainActivity?/*from   w  w w .  j a  v a 2s .co  m*/
 */
public static void sendSimplestNotificationWithAction(Context context) {

    NotificationManager mNotifyManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    //?PendingIntent
    Intent mainIntent = new Intent(context, NormalActivity.class);
    PendingIntent mainPendingIntent = PendingIntent.getActivity(context, 0, mainIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    // Notification.Builder 
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setAutoCancel(true).setContentTitle("tittle")
            .setContentText("").setNumber(++NUMBER).setPriority(2)
            .setContentIntent(mainPendingIntent).setFullScreenIntent(mainPendingIntent, true);
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    String[] events = new String[] { "CCCCCCCCCCCCCCCCC", "DDDDDDDDDDDDDDDDDDDDD", "EEEEEEEEEEEEEEEEEEEE",
            "FFFFFFFFFFFFFFFFFFFF", "HHHHHHHHHHHHHHHHHHH" };
    // Sets a title for the Inbox in expanded layout
    inboxStyle.setBigContentTitle("Event tracker details:");
    // Moves events into the expanded layout
    for (String event : events) {
        inboxStyle.addLine(event);
    }

    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
    bigPictureStyle.bigPicture(BitmapFactory.decodeResource(context.getResources(), R.mipmap.about_bg));
    bigPictureStyle.setSummaryText("DDDDDDDDDDDDDDDDDDDDD");
    // Moves the expanded layout object into the notification object.
    //        builder.setStyle(bigPictureStyle);

    //??
    Notification build = builder.build();

    mNotifyManager.notify(3, build);
}

From source file:cc.echonet.coolmicapp.MainActivity.java

private void RedFlashLight() {
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification notif = new Notification.Builder(context).setLights(0xFFff0000, 100, 100)
            .setSmallIcon(R.drawable.icon).setContentTitle("Streaming").setContentText("Streaming...").build();
    nm.notify(Constants.NOTIFICATION_ID_LED, notif);
}

From source file:org.mythdroid.util.UpdateService.java

private void notify(String title, String message) {

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification = new Notification(R.drawable.logo, title, System.currentTimeMillis());

    notification.flags = Notification.FLAG_AUTO_CANCEL;

    notification.setLatestEventInfo(getApplicationContext(), title, message,
            PendingIntent.getActivity(Globals.appContext, 0, new Intent(), 0));

    nm.notify(-1, notification);
}

From source file:com.orange.oidc.secproxy_service.Service.java

private void showNotification(boolean bProtect) {
    Logd(TAG, "show protected icon " + bProtect);

    // 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 = null;

    if (bProtect) {
        mNotification = new Notification.Builder(this)

                .setContentTitle("SECURE OIDC PROXY").setContentText("privacy protected")
                .setSmallIcon(R.drawable.masked_on).setAutoCancel(false).build();
    } else {/*from www.j  a va2 s  .co  m*/
        mNotification = new Notification.Builder(this)

                .setContentTitle("SECURE OIDC PROXY").setContentText("privacy not protected")
                .setSmallIcon(R.drawable.masked_off).setAutoCancel(false).build();
    }

    // to make it non clearable
    mNotification.flags |= Notification.FLAG_NO_CLEAR;

    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);
}

From source file:net.ccghe.emocha.services.ServerService.java

private void showNotification(String tickertxt, String displayTxt, int max, int progress) {
    NotificationManager notifMgr = (NotificationManager) this.getSystemService(Service.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainMenu.class), 0);

    // construct the Notification object.
    Notification notif = new Notification();

    notif.tickerText = tickertxt;//from w  w w .j  a v  a  2  s  .  c  om
    notif.icon = R.drawable.icon;

    nmView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
    nmView.setProgressBar(R.id.progressbar, max, progress, false);
    nmView.setTextViewText(R.id.TextView01, displayTxt);

    notif.contentView = nmView;

    notif.contentIntent = contentIntent;
    notifMgr.notify(R.layout.custom_notification_layout, notif);
}

From source file:com.example.SmartBoard.MQTTHandler.java

public void messageArrived(String topic, MqttMessage message) {
    MyActivity drawingActivity = (MyActivity) drawingContext;
    JSONObject recvMessage = null;//from w w  w . j  a va  2 s . c o  m

    if (message.toString().compareTo("") == 0) {
        //user went offline
        String[] topicStruct = topic.split("/");
        // System.out.println("user to be removed: "+topicStruct[2]);

        if (topicStruct[2].compareTo("users") == 0) {
            usersListHistory.remove(new OnlineStateMessage(null, topicStruct[3]));
            usersAdapter.notifyDataSetChanged();

        } else if (topicStruct[2].compareTo("objects") == 0) {
            drawingActivity.drawer.removeObject(topicStruct[3]);
        }
        return;
    }

    try {
        recvMessage = new JSONObject(message.toString());
    } catch (JSONException j) {
        j.printStackTrace();
    }

    if (recvMessage.optString("status").compareTo("online") == 0) {

        OnlineStateMessage newUser = new OnlineStateMessage(recvMessage.optString("selfie"),
                recvMessage.optString("userId"));
        // System.out.println("user added: "+ recvMessage.optString("userId"));
        usersListHistory.add(newUser);
        usersAdapter.notifyDataSetChanged();
        return;

    }

    String clientId = recvMessage.optString("clientId");

    if (clientId.compareTo(client.getClientId()) != 0) {

        switch (type.valueOf(recvMessage.optString("type"))) {

        case Point:
            drawingActivity.drawer.drawPoint((float) recvMessage.optDouble("mX"),
                    (float) recvMessage.optDouble("mY"), recvMessage.optInt("drawActionFlag"),
                    recvMessage.optInt("color"), recvMessage.optString("mode"), recvMessage.optInt("brushSize"),
                    recvMessage.optString("clientId"));
            break;
        case Eraser:
            float eSize = (float) recvMessage.optDouble("size");
            drawingActivity.drawer.updateEraseSize(eSize);
            break;
        case Pencil: //shares topic with Eraser
            float size = (float) recvMessage.optDouble("size");
            drawingActivity.drawer.updateBrushSize(size);
            break;

        case ColorChange:
            drawingActivity.drawer.updateColor(recvMessage.optInt("code"));
            break;

        case ClearScreen:
            drawingActivity.drawer.updateClearScreen();
            break;
        case Chat:
            Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(new long[] { 3, 100 }, -1);

            String[] nameMessage = recvMessage.optString("message").split(":");
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
                    .setLargeIcon(stringToBitmap(recvMessage.optString("selfie")))
                    .setSmallIcon(R.drawable.smart2).setContentTitle(nameMessage[0])
                    .setContentText(nameMessage[1]).setTicker("New Message Arrived").setAutoCancel(true)
                    .setNumber(++numMessages);

            NotificationManager mNotificationManager = (NotificationManager) ctx
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            // mId allows you to update the notification later on.
            mNotificationManager.notify(1000, mBuilder.build());

            ChatMessageWithSelfie mChatMessage = new ChatMessageWithSelfie(recvMessage.optBoolean("direction"),
                    recvMessage.optString("message"), recvMessage.optString("selfie"),
                    recvMessage.optString("imageSent"), null);
            sessionHistory.add(mChatMessage);
            Chat.chatAdapter.add(mChatMessage);
            break;

        case Image:
            Vibrator v2 = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
            v2.vibrate(new long[] { 3, 100 }, -1);
            Toast.makeText(ctx, recvMessage.optString("username") + " has sent you a message!",
                    Toast.LENGTH_SHORT).show();
            ChatMessageWithSelfie mChatImageMessage = new ChatMessageWithSelfie(
                    recvMessage.optBoolean("direction"), null, recvMessage.optString("selfie"),
                    recvMessage.optString("image"), null);
            sessionHistory.add(mChatImageMessage);
            Chat.chatAdapter.add(mChatImageMessage);
            break;
        case Rectangle:
            drawingActivity.drawer.onDrawReceivedRectangle(recvMessage);
            break;
        case Circle:
            drawingActivity.drawer.onDrawReceivedCircle(recvMessage);
            break;
        case Line:
            drawingActivity.drawer.onDrawReceivedLine(recvMessage);
            break;
        case Text:
            drawingActivity.drawer.onDrawReceivedText(recvMessage);
            break;
        default:
            //ignore the message
        }
    }
}

From source file:at.aec.solutions.checkmkagent.AgentService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.v(TAG, "onCreate");

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    m_wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
    m_wakeLock.acquire();//  w  w w.  ja  v a  2 s . c om

    //Copy busybox binary to app directory
    if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("bbinstalled",
            false)) {
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit()
                .putBoolean("bbinstalled", true).commit();

        // There is also String[] Build.SUPPORTED_ABIS from API 21 on and
        // before String Build.CPU_ABI String Build.CPU_ABI2, maybe i should investigate there
        String arch = System.getProperty("os.arch");
        Log.v(TAG, arch);
        if (arch.equals("armv7l")) {
            copyAsset(getAssets(), "bbb/busybox", getApplicationInfo().dataDir + "/busybox");
        }
        if (arch.equals("i686")) {
            copyAsset(getAssets(), "bbb/busybox-i686", getApplicationInfo().dataDir + "/busybox");
        }

        //         copyAsset(getAssets(), "bbb/busybox-x86_64", getApplicationInfo().dataDir+"/busybox-x86_64");
        changeBusyboxPermission();
    }

    socketServerThread = new Thread(new SocketServerThread());
    socketServerThread.setName("CheckMK-Agent ServerThread");
    socketServerThread.start();

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("CheckMK Agent started.")
            .setContentText("Listening on Port " + SERVERPORT + ". Tap to configure.");

    Intent resultIntent = new Intent(this, ConfigureActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ConfigureActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    Notification notify = mBuilder.build();
    notify.flags |= Notification.FLAG_NO_CLEAR;

    mNotificationManager.notify(mId, notify);
}

From source file:butter.droid.base.ButterApplication.java

@Override
public void updateAvailable(String updateFile) {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (updateFile.length() > 0) {
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_notif_logo).setContentTitle(getString(R.string.update_available))
                .setContentText(getString(R.string.press_install)).setAutoCancel(true)
                .setDefaults(NotificationCompat.DEFAULT_ALL);

        Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setDataAndType(Uri.parse("file://" + updateFile), ButterUpdater.ANDROID_PACKAGE);

        notificationBuilder.setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0));

        nm.notify(ButterUpdater.NOTIFICATION_ID, notificationBuilder.build());
    }/*from  w  w w.  j  a va2s . c o m*/
}

From source file:com.flowzr.budget.holo.export.flowzr.FlowzrBillTask.java

protected Object work(Context context, DatabaseAdapter dba, String... params) throws ImportExportException {

    AccountManager accountManager = AccountManager.get(context);
    android.accounts.Account[] accounts = accountManager.getAccountsByType("com.google");

    String accountName = MyPreferences.getFlowzrAccount(context);
    if (accountName == null) {
        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        Intent notificationIntent = new Intent(context, FlowzrSyncActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        Builder mNotifyBuilder = new NotificationCompat.Builder(context);
        mNotifyBuilder.setContentIntent(contentIntent).setSmallIcon(R.drawable.icon)
                .setWhen(System.currentTimeMillis()).setAutoCancel(true)
                .setContentTitle(context.getString(R.string.flowzr_sync))
                .setContentText(context.getString(R.string.flowzr_choose_account));
        nm.notify(0, mNotifyBuilder.build());
        Log.i("Flowzr", "account name is null");
        throw new ImportExportException(R.string.flowzr_choose_account);
    }/*from  w w  w. j  a v a 2 s .co  m*/
    Account useCredential = null;
    for (int i = 0; i < accounts.length; i++) {
        if (accountName.equals(((android.accounts.Account) accounts[i]).name)) {
            useCredential = accounts[i];
        }
    }
    AccountManager.get(context).getAuthToken(useCredential, "ah", null, (Activity) context,
            new GetAuthTokenCallback(), null);

    return null;
}