Example usage for android.app Notification VISIBILITY_PRIVATE

List of usage examples for android.app Notification VISIBILITY_PRIVATE

Introduction

In this page you can find the example usage for android.app Notification VISIBILITY_PRIVATE.

Prototype

int VISIBILITY_PRIVATE

To view the source code for android.app Notification VISIBILITY_PRIVATE.

Click Source Link

Document

Notification visibility: Show this notification on all lockscreens, but conceal sensitive or private information on secure lockscreens.

Usage

From source file:org.linphone.compatibility.ApiTwentyOnePlus.java

public static Notification createMessageNotification(Context context, int msgCount, String msgSender,
        String msg, Bitmap contactIcon, PendingIntent intent) {
    String title;//w ww .j  av  a 2 s. c  o m
    if (msgCount == 1) {
        title = msgSender;
    } else {
        title = context.getString(R.string.unread_messages).replace("%i", String.valueOf(msgCount));
    }

    Notification notif = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(msg)
            .setSmallIcon(R.drawable.chat_icon_over).setAutoCancel(true).setContentIntent(intent)
            .setDefaults(Notification.DEFAULT_ALL).setLargeIcon(contactIcon)
            .setCategory(Notification.CATEGORY_MESSAGE).setVisibility(Notification.VISIBILITY_PRIVATE)
            .setPriority(Notification.PRIORITY_HIGH).build();

    return notif;
}

From source file:com.google.android.gms.location.sample.backgroundlocationupdates.LocationResultHelper.java

LocationResultHelper(Context context, List<Location> locations) {
    mContext = context;/*from  www .  jav  a 2  s  .c  om*/
    mLocations = locations;

    NotificationChannel channel = new NotificationChannel(PRIMARY_CHANNEL,
            context.getString(R.string.default_channel), NotificationManager.IMPORTANCE_DEFAULT);
    channel.setLightColor(Color.GREEN);
    channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    getNotificationManager().createNotificationChannel(channel);
}

From source file:org.linphone.compatibility.ApiTwentyOnePlus.java

public static Notification createSimpleNotification(Context context, String title, String text,
        PendingIntent intent) {//from  w w w.  j a v a 2  s  .  c o m
    Notification notif = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(text)
            .setSmallIcon(R.drawable.logo_linphone_57x57).setAutoCancel(true).setContentIntent(intent)
            .setDefaults(Notification.DEFAULT_ALL).setCategory(Notification.CATEGORY_MESSAGE)
            .setVisibility(Notification.VISIBILITY_PRIVATE).setPriority(Notification.PRIORITY_HIGH).build();

    return notif;
}

From source file:com.example.android.wearable.wear.wearnotifications.handlers.BigPictureSocialIntentService.java

private NotificationCompat.Builder recreateBuilderWithBigPictureStyle() {

    // Main steps for building a BIG_PICTURE_STYLE notification (for more detailed comments on
    // building this notification, check StandaloneMainActivity.java):
    //      0. Get your data
    //      1. Build the BIG_PICTURE_STYLE
    //      2. Set up main Intent for notification
    //      3. Set up RemoteInput, so users can input (keyboard and voice) from notification
    //      4. Build and issue the notification

    // 0. Get your data (everything unique per Notification)
    MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData = MockDatabase
            .getBigPictureStyleData();/*w  w w.  j  ava  2  s .c om*/

    // 1. Build the BIG_PICTURE_STYLE
    BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle()
            .bigPicture(
                    BitmapFactory.decodeResource(getResources(), bigPictureStyleSocialAppData.getBigImage()))
            .setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle())
            .setSummaryText(bigPictureStyleSocialAppData.getSummaryText());

    // 2. Set up main Intent for notification
    Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class);

    PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // 3. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly
    // from the notification without entering the app.
    String replyLabel = getString(R.string.reply_label);
    RemoteInput remoteInput = new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT)
            .setLabel(replyLabel).setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses()).build();

    Intent replyIntent = new Intent(this, BigPictureSocialIntentService.class);
    replyIntent.setAction(BigPictureSocialIntentService.ACTION_COMMENT);
    PendingIntent replyActionPendingIntent = PendingIntent.getService(this, 0, replyIntent, 0);

    // Enable action to appear inline on Wear 2.0 (24+). This means it will appear over the
    // lower portion of the Notification for easy action (only possible for one action).
    final NotificationCompat.Action.WearableExtender inlineActionForWear2 = new NotificationCompat.Action.WearableExtender()
            .setHintDisplayActionInline(true).setHintLaunchesActivity(false);

    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput)
                    // Add WearableExtender to enable inline actions
                    .extend(inlineActionForWear2).build();

    // 4. Build and issue the notification
    NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder(
            getApplicationContext());

    GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);

    // Build notification
    notificationCompatBuilder.setStyle(bigPictureStyle)
            .setContentTitle(bigPictureStyleSocialAppData.getContentTitle())
            .setContentText(bigPictureStyleSocialAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp))
            .setContentIntent(mainPendingIntent).setColor(getResources().getColor(R.color.colorPrimary))
            .setSubText(Integer.toString(1)).addAction(replyAction).setCategory(Notification.CATEGORY_SOCIAL)
            .setPriority(Notification.PRIORITY_HIGH).setVisibility(Notification.VISIBILITY_PRIVATE)
            .extend(new NotificationCompat.WearableExtender().setHintContentIntentLaunchesActivity(true));

    for (String name : bigPictureStyleSocialAppData.getParticipants()) {
        notificationCompatBuilder.addPerson(name);
    }

    return notificationCompatBuilder;
}

From source file:com.example.android.wearable.wear.wearnotifications.handlers.MessagingIntentService.java

private NotificationCompat.Builder recreateBuilderWithMessagingStyle() {

    // Main steps for building a MESSAGING_STYLE notification (for more detailed comments on
    // building this notification, check StandaloneMainActivity.java)::
    //      0. Get your data
    //      1. Build the MESSAGING_STYLE
    //      2. Add support for Wear 1.+
    //      3. Set up main Intent for notification
    //      4. Set up RemoteInput (users can input directly from notification)
    //      5. Build and issue the notification

    // 0. Get your data (everything unique per Notification)
    MockDatabase.MessagingStyleCommsAppData messagingStyleCommsAppData = MockDatabase.getMessagingStyleData();

    // 1. Build the Notification.Style (MESSAGING_STYLE)
    String contentTitle = messagingStyleCommsAppData.getContentTitle();

    MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(
            messagingStyleCommsAppData.getReplayName()).setConversationTitle(contentTitle);

    // Adds all Messages
    for (MessagingStyle.Message message : messagingStyleCommsAppData.getMessages()) {
        messagingStyle.addMessage(message);
    }// w ww . j av a2 s.c  om

    // 2. Add support for Wear 1.+.
    String fullMessageForWearVersion1 = messagingStyleCommsAppData.getFullConversation();

    Notification chatHistoryForWearV1 = new NotificationCompat.Builder(getApplicationContext())
            .setStyle(new NotificationCompat.BigTextStyle().bigText(fullMessageForWearVersion1))
            .setContentTitle(contentTitle).setSmallIcon(R.drawable.ic_launcher)
            .setContentText(fullMessageForWearVersion1).build();

    // Adds page with all text to support Wear 1.+.
    NotificationCompat.WearableExtender wearableExtenderForWearVersion1 = new NotificationCompat.WearableExtender()
            .setHintContentIntentLaunchesActivity(true).addPage(chatHistoryForWearV1);

    // 3. Set up main Intent for notification
    Intent notifyIntent = new Intent(this, MessagingMainActivity.class);

    PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // 4. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly
    // from the notification without entering the app.
    String replyLabel = getString(R.string.reply_label);
    RemoteInput remoteInput = new RemoteInput.Builder(MessagingIntentService.EXTRA_REPLY).setLabel(replyLabel)
            .build();

    Intent replyIntent = new Intent(this, MessagingIntentService.class);
    replyIntent.setAction(MessagingIntentService.ACTION_REPLY);
    PendingIntent replyActionPendingIntent = PendingIntent.getService(this, 0, replyIntent, 0);

    // Enable action to appear inline on Wear 2.0 (24+). This means it will appear over the
    // lower portion of the Notification for easy action (only possible for one action).
    final NotificationCompat.Action.WearableExtender inlineActionForWear2_0 = new NotificationCompat.Action.WearableExtender()
            .setHintDisplayActionInline(true).setHintLaunchesActivity(false);

    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput)
                    // Allows system to generate replies by context of conversation
                    .setAllowGeneratedReplies(true)
                    // Add WearableExtender to enable inline actions
                    .extend(inlineActionForWear2_0).build();

    // 5. Build and issue the notification
    NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder(
            getApplicationContext());

    GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);

    // Builds and issues notification
    notificationCompatBuilder.setStyle(messagingStyle).setContentTitle(contentTitle)
            .setContentText(messagingStyleCommsAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp))
            .setContentIntent(mainPendingIntent).setColor(getResources().getColor(R.color.colorPrimary))
            .setSubText(Integer.toString(messagingStyleCommsAppData.getNumberOfNewMessages()))
            .addAction(replyAction).setCategory(Notification.CATEGORY_MESSAGE)
            .setPriority(Notification.PRIORITY_HIGH).setVisibility(Notification.VISIBILITY_PRIVATE)
            .extend(wearableExtenderForWearVersion1);

    for (String name : messagingStyleCommsAppData.getParticipants()) {
        notificationCompatBuilder.addPerson(name);
    }

    return notificationCompatBuilder;
}

From source file:org.ciasaboark.tacere.manager.NotificationManagerWrapper.java

/**
 * Builds and displays a notification for the given CalEvent. This method uses the new
 * Notification API to place an action button in the notification.
 *
 * @param event the CalEvent that is currently active
 *//*  w  w w . j  a  v a2s  .  c  o m*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void displayNewEventNotification(EventInstance event) {
    // clicking the notification should take the user to the app
    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    // FLAG_CANCEL_CURRENT is required to make sure that the extras are including in
    // the new pending intent
    PendingIntent pendIntent = PendingIntent.getActivity(context, REQUEST_CODES.EVENT_OPEN_MAIN,
            notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    Notification.Builder notBuilder = new Notification.Builder(context)
            .setContentTitle(context.getString(R.string.notification_event_active_title))
            .setContentText(event.toString()).setAutoCancel(false).setOnlyAlertOnce(true).setOngoing(true)
            .setContentIntent(pendIntent);

    EventManager eventManager = new EventManager(context, event);
    switch (eventManager.getBestRinger()) {
    case SILENT:
        notBuilder.setSmallIcon(R.drawable.not_silence);
        break;
    case VIBRATE:
        notBuilder.setSmallIcon(R.drawable.not_vibrate);
        break;
    case NORMAL:
        notBuilder.setSmallIcon(R.drawable.not_normal);
        break;
    }

    // this intent will be attached to the button on the notification
    Intent skipEventIntent = new Intent(context, SkipEventService.class);
    skipEventIntent.putExtra(SkipEventService.EVENT_ID_TAG, event.getId());
    PendingIntent skipEventPendIntent = PendingIntent.getService(context, REQUEST_CODES.EVENT_IGNORE,
            skipEventIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    notBuilder.addAction(R.drawable.not_ignore, context.getString(R.string.notification_event_skip),
            skipEventPendIntent);

    //an intent to add an additional 15 minutes of silencing for an event
    Intent addSilencingIntent = new Intent(context, ExtendEventService.class);
    addSilencingIntent.putExtra(ExtendEventService.INSTANCE_ID, event.getId());
    addSilencingIntent.putExtra(ExtendEventService.NEW_EXTEND_LENGTH, event.getExtendMinutes() + 15); //TODO use minutes stored in prefs
    PendingIntent addSilenceingPendIntent = PendingIntent.getService(context, REQUEST_CODES.EVENT_ADD_TIME,
            addSilencingIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    Authenticator authenticator = new Authenticator(context);
    if (authenticator.isAuthenticated()) {
        notBuilder.addAction(R.drawable.not_clock, "+15", addSilenceingPendIntent);
    }

    // the ticker text should only be shown the first time the notification is
    // created, not on each update
    notBuilder
            .setTicker(context.getString(R.string.notification_event_active_starting) + " " + event.toString());

    if (Build.VERSION.SDK_INT >= 21) {
        notBuilder.setVisibility(Notification.VISIBILITY_PRIVATE);
        Notification.Builder publicNotification = getBaseEventNotificationBuilder();
        publicNotification.setContentTitle(context.getString(R.string.notification_event_active_title_public));
        publicNotification.setContentIntent(pendIntent);
        notBuilder.setPublicVersion(publicNotification.build());
        notBuilder.setColor(context.getResources().getColor(R.color.accent));

        Drawable d = context.getResources().getDrawable(R.drawable.shape_circle);
        int height = (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_height);
        int width = (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_width);
        d.setBounds(0, 0, width, height);
        d.mutate().setColorFilter(event.getDisplayColor(), PorterDuff.Mode.MULTIPLY);
        DatabaseInterface databaseInterface = DatabaseInterface.getInstance(context);
        String calendarTitle = databaseInterface.getCalendarNameForId(event.getCalendarId());
        String c = "";
        if (calendarTitle != null && calendarTitle != "") {
            c = ((Character) calendarTitle.charAt(0)).toString().toUpperCase();
        }

        Bitmap largeIcon = createMarkerIcon(d, c, width, height);
        //            Bitmap largeIcon = combineDrawablesToBitmap(d, getRingerIconForEvent(event), width, height);
        notBuilder.setLargeIcon(largeIcon);
    }

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, notBuilder.build());
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService.java

private void generateNotification(Context context, String ticker, String title, String msg, int icon,
        Intent intent, String sound, int notificationId, MFPInternalPushMessage message) {

    int androidSDKVersion = Build.VERSION.SDK_INT;
    long when = System.currentTimeMillis();
    Notification notification = null;
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    if (message.getGcmStyle() != null && androidSDKVersion > 21) {
        NotificationCompat.Builder mBuilder = null;
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        try {//from ww  w.j a va2s. c  o  m
            JSONObject gcmStyleObject = new JSONObject(message.getGcmStyle());
            String type = gcmStyleObject.getString(TYPE);

            if (type != null && type.equalsIgnoreCase(PICTURE_NOTIFICATION)) {
                Bitmap remote_picture = null;
                NotificationCompat.BigPictureStyle notificationStyle = new NotificationCompat.BigPictureStyle();
                notificationStyle.setBigContentTitle(ticker);
                notificationStyle.setSummaryText(gcmStyleObject.getString(TITLE));

                try {
                    remote_picture = new getBitMapBigPictureNotification()
                            .execute(gcmStyleObject.getString(URL)).get();
                } catch (Exception e) {
                    logger.error(
                            "MFPPushIntentService:generateNotification() - Error while fetching image file.");
                }
                if (remote_picture != null) {
                    notificationStyle.bigPicture(remote_picture);
                }

                mBuilder = new NotificationCompat.Builder(context);
                notification = mBuilder.setSmallIcon(icon).setLargeIcon(remote_picture).setAutoCancel(true)
                        .setContentTitle(title)
                        .setContentIntent(PendingIntent.getActivity(context, notificationId, intent,
                                PendingIntent.FLAG_UPDATE_CURRENT))
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setContentText(msg).setStyle(notificationStyle).build();

            } else if (type != null && type.equalsIgnoreCase(BIGTEXT_NOTIFICATION)) {
                NotificationCompat.BigTextStyle notificationStyle = new NotificationCompat.BigTextStyle();
                notificationStyle.setBigContentTitle(ticker);
                notificationStyle.setSummaryText(gcmStyleObject.getString(TITLE));
                notificationStyle.bigText(gcmStyleObject.getString(TEXT));

                mBuilder = new NotificationCompat.Builder(context);
                notification = mBuilder.setSmallIcon(icon).setAutoCancel(true).setContentTitle(title)
                        .setContentIntent(PendingIntent.getActivity(context, notificationId, intent,
                                PendingIntent.FLAG_UPDATE_CURRENT))
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setContentText(msg).setStyle(notificationStyle).build();
            } else if (type != null && type.equalsIgnoreCase(INBOX_NOTIFICATION)) {
                NotificationCompat.InboxStyle notificationStyle = new NotificationCompat.InboxStyle();
                notificationStyle.setBigContentTitle(ticker);
                notificationStyle.setSummaryText(gcmStyleObject.getString(TITLE));

                String lines = gcmStyleObject.getString(LINES).replaceAll("\\[", "").replaceAll("\\]", "");
                String[] lineArray = lines.split(",");

                for (String line : lineArray) {
                    notificationStyle.addLine(line);
                }

                mBuilder = new NotificationCompat.Builder(context);
                notification = mBuilder.setSmallIcon(icon).setAutoCancel(true).setContentTitle(title)
                        .setContentIntent(PendingIntent.getActivity(context, notificationId, intent,
                                PendingIntent.FLAG_UPDATE_CURRENT))
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setContentText(msg).setStyle(notificationStyle).build();
            }

            notification.flags = Notification.FLAG_AUTO_CANCEL;
            notificationManager.notify(notificationId, notification);
        } catch (JSONException e) {
            logger.error("MFPPushIntentService:generateNotification() - Error while parsing JSON.");
        }

    } else {
        if (androidSDKVersion > 10) {
            builder.setContentIntent(PendingIntent.getActivity(context, notificationId, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT)).setSmallIcon(icon).setTicker(ticker).setWhen(when)
                    .setAutoCancel(true).setContentTitle(title).setContentText(msg)
                    .setSound(getNotificationSoundUri(context, sound));

            if (androidSDKVersion > 15) {
                int priority = getPriorityOfMessage(message);
                builder.setPriority(priority);
                notification = builder.build();
            }

            if (androidSDKVersion > 19) {
                //As new material theme is very light, the icon is not shown clearly
                //hence setting the background of icon to black
                builder.setColor(Color.BLACK);
                Boolean isBridgeSet = message.getBridge();
                if (!isBridgeSet) {
                    // show notification only on current device.
                    builder.setLocalOnly(true);
                }

                notification = builder.build();
                int receivedVisibility = 1;
                String visibility = message.getVisibility();
                if (visibility != null && visibility.equalsIgnoreCase(MFPPushConstants.VISIBILITY_PRIVATE)) {
                    receivedVisibility = 0;
                }
                if (receivedVisibility == Notification.VISIBILITY_PRIVATE && message.getRedact() != null) {
                    builder.setContentIntent(PendingIntent.getActivity(context, notificationId, intent,
                            PendingIntent.FLAG_UPDATE_CURRENT)).setSmallIcon(icon).setTicker(ticker)
                            .setWhen(when).setAutoCancel(true).setContentTitle(title)
                            .setContentText(message.getRedact())
                            .setSound(getNotificationSoundUri(context, sound));

                    notification.publicVersion = builder.build();
                }
            }

            if (androidSDKVersion > 21) {
                String setPriority = message.getPriority();
                if (setPriority != null && setPriority.equalsIgnoreCase(MFPPushConstants.PRIORITY_MAX)) {
                    //heads-up notification
                    builder.setContentText(msg).setFullScreenIntent(PendingIntent.getActivity(context,
                            notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT), true);
                    notification = builder.build();
                }
            }

        } else {
            notification = builder
                    .setContentIntent(
                            PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
                    .setSmallIcon(icon).setTicker(ticker).setWhen(when).setAutoCancel(true)
                    .setContentTitle(title).setContentText(msg)
                    .setSound(getNotificationSoundUri(context, sound)).build();
        }

        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(notificationId, notification);
    }
}

From source file:com.android.cts.verifier.managedprovisioning.ByodHelperActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        Log.w(TAG, "Restored state");
        mOriginalSettings = savedInstanceState.getBundle(ORIGINAL_SETTINGS_NAME);
    } else {//  www  .  jav a  2 s. c  om
        mOriginalSettings = new Bundle();
    }

    mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
    mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Intent intent = getIntent();
    String action = intent.getAction();
    Log.d(TAG, "ByodHelperActivity.onCreate: " + action);

    // we are explicitly started by {@link DeviceAdminTestReceiver} after a successful provisioning.
    if (action.equals(ACTION_PROFILE_PROVISIONED)) {
        // Jump back to CTS verifier with result.
        Intent response = new Intent(ACTION_PROFILE_OWNER_STATUS);
        response.putExtra(EXTRA_PROVISIONED, isProfileOwner());
        startActivityInPrimary(response);
        // Queried by CtsVerifier in the primary side using startActivityForResult.
    } else if (action.equals(ACTION_QUERY_PROFILE_OWNER)) {
        Intent response = new Intent();
        response.putExtra(EXTRA_PROVISIONED, isProfileOwner());
        setResult(RESULT_OK, response);
        // Request to delete work profile.
    } else if (action.equals(ACTION_REMOVE_MANAGED_PROFILE)) {
        if (isProfileOwner()) {
            Log.d(TAG, "Clearing cross profile intents");
            mDevicePolicyManager.clearCrossProfileIntentFilters(mAdminReceiverComponent);
            mDevicePolicyManager.wipeData(0);
            showToast(R.string.provisioning_byod_profile_deleted);
        }
    } else if (action.equals(ACTION_INSTALL_APK)) {
        boolean allowNonMarket = intent.getBooleanExtra(EXTRA_ALLOW_NON_MARKET_APPS, false);
        boolean wasAllowed = getAllowNonMarket();

        // Update permission to install non-market apps
        setAllowNonMarket(allowNonMarket);
        mOriginalSettings.putBoolean(INSTALL_NON_MARKET_APPS, wasAllowed);

        // Request to install a non-market application- easiest way is to reinstall ourself
        final Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE)
                .setData(Uri.parse("package:" + getPackageName()))
                .putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true).putExtra(Intent.EXTRA_RETURN_RESULT, true);
        startActivityForResult(installIntent, REQUEST_INSTALL_PACKAGE);

        // Not yet ready to finish- wait until the result comes back
        return;
        // Queried by CtsVerifier in the primary side using startActivityForResult.
    } else if (action.equals(ACTION_CHECK_INTENT_FILTERS)) {
        final boolean intentFiltersSetForManagedIntents = new IntentFiltersTestHelper(this)
                .checkCrossProfileIntentFilters(IntentFiltersTestHelper.FLAG_INTENTS_FROM_MANAGED);
        setResult(intentFiltersSetForManagedIntents ? RESULT_OK : RESULT_FAILED, null);
    } else if (action.equals(ACTION_CAPTURE_AND_CHECK_IMAGE)) {
        // We need the camera permission to send the image capture intent.
        grantCameraPermissionToSelf();
        Intent captureImageIntent = getCaptureImageIntent();
        Pair<File, Uri> pair = getTempUri("image.jpg");
        mImageFile = pair.first;
        mImageUri = pair.second;
        captureImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
        if (captureImageIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(captureImageIntent, REQUEST_IMAGE_CAPTURE);
        } else {
            Log.e(TAG, "Capture image intent could not be resolved in managed profile.");
            showToast(R.string.provisioning_byod_capture_media_error);
            finish();
        }
        return;
    } else if (action.equals(ACTION_CAPTURE_AND_CHECK_VIDEO_WITH_EXTRA_OUTPUT)
            || action.equals(ACTION_CAPTURE_AND_CHECK_VIDEO_WITHOUT_EXTRA_OUTPUT)) {
        // We need the camera permission to send the video capture intent.
        grantCameraPermissionToSelf();
        Intent captureVideoIntent = getCaptureVideoIntent();
        int videoCaptureRequestId;
        if (action.equals(ACTION_CAPTURE_AND_CHECK_VIDEO_WITH_EXTRA_OUTPUT)) {
            mVideoUri = getTempUri("video.mp4").second;
            captureVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mVideoUri);
            videoCaptureRequestId = REQUEST_VIDEO_CAPTURE_WITH_EXTRA_OUTPUT;
        } else {
            videoCaptureRequestId = REQUEST_VIDEO_CAPTURE_WITHOUT_EXTRA_OUTPUT;
        }
        if (captureVideoIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(captureVideoIntent, videoCaptureRequestId);
        } else {
            Log.e(TAG, "Capture video intent could not be resolved in managed profile.");
            showToast(R.string.provisioning_byod_capture_media_error);
            finish();
        }
        return;
    } else if (action.equals(ACTION_CAPTURE_AND_CHECK_AUDIO)) {
        Intent captureAudioIntent = getCaptureAudioIntent();
        if (captureAudioIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(captureAudioIntent, REQUEST_AUDIO_CAPTURE);
        } else {
            Log.e(TAG, "Capture audio intent could not be resolved in managed profile.");
            showToast(R.string.provisioning_byod_capture_media_error);
            finish();
        }
        return;
    } else if (ACTION_KEYGUARD_DISABLED_FEATURES.equals(action)) {
        final int value = intent.getIntExtra(EXTRA_PARAMETER_1,
                DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE);
        mDevicePolicyManager.setKeyguardDisabledFeatures(mAdminReceiverComponent, value);
    } else if (ACTION_LOCKNOW.equals(action)) {
        mDevicePolicyManager.lockNow();
        setResult(RESULT_OK);
    } else if (action.equals(ACTION_TEST_NFC_BEAM)) {
        Intent testNfcBeamIntent = new Intent(this, NfcTestActivity.class);
        testNfcBeamIntent.putExtras(intent);
        startActivity(testNfcBeamIntent);
        finish();
        return;
    } else if (action.equals(ACTION_TEST_CROSS_PROFILE_INTENTS_DIALOG)) {
        sendIntentInsideChooser(new Intent(CrossProfileTestActivity.ACTION_CROSS_PROFILE_TO_PERSONAL));
    } else if (action.equals(ACTION_TEST_APP_LINKING_DIALOG)) {
        mDevicePolicyManager.addUserRestriction(DeviceAdminTestReceiver.getReceiverComponentName(),
                UserManager.ALLOW_PARENT_PROFILE_APP_LINKING);
        Intent toSend = new Intent(Intent.ACTION_VIEW);
        toSend.setData(Uri.parse("http://com.android.cts.verifier"));
        sendIntentInsideChooser(toSend);
    } else if (action.equals(ACTION_SET_USER_RESTRICTION)) {
        final String restriction = intent.getStringExtra(EXTRA_PARAMETER_1);
        if (restriction != null) {
            mDevicePolicyManager.addUserRestriction(DeviceAdminTestReceiver.getReceiverComponentName(),
                    restriction);
        }
    } else if (action.equals(ACTION_CLEAR_USER_RESTRICTION)) {
        final String restriction = intent.getStringExtra(EXTRA_PARAMETER_1);
        if (restriction != null) {
            mDevicePolicyManager.clearUserRestriction(DeviceAdminTestReceiver.getReceiverComponentName(),
                    restriction);
        }
    } else if (action.equals(ACTION_BYOD_SET_LOCATION_AND_CHECK_UPDATES)) {
        handleLocationAction();
        return;
    } else if (action.equals(ACTION_NOTIFICATION)) {
        showNotification(Notification.VISIBILITY_PUBLIC);
    } else if (ACTION_NOTIFICATION_ON_LOCKSCREEN.equals(action)) {
        mDevicePolicyManager.lockNow();
        showNotification(Notification.VISIBILITY_PRIVATE);
    } else if (ACTION_CLEAR_NOTIFICATION.equals(action)) {
        mNotificationManager.cancel(NOTIFICATION_ID);
    } else if (ACTION_TEST_SELECT_WORK_CHALLENGE.equals(action)) {
        mDevicePolicyManager.setOrganizationColor(mAdminReceiverComponent, Color.BLUE);
        mDevicePolicyManager.setOrganizationName(mAdminReceiverComponent,
                getResources().getString(R.string.provisioning_byod_confirm_work_credentials_header));
        startActivity(new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD));
    } else if (ACTION_LAUNCH_CONFIRM_WORK_CREDENTIALS.equals(action)) {
        KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        Intent launchIntent = keyguardManager.createConfirmDeviceCredentialIntent(null, null);
        startActivity(launchIntent);
    } else if (ACTION_SET_ORGANIZATION_INFO.equals(action)) {
        if (intent.hasExtra(OrganizationInfoTestActivity.EXTRA_ORGANIZATION_NAME)) {
            final String organizationName = intent
                    .getStringExtra(OrganizationInfoTestActivity.EXTRA_ORGANIZATION_NAME);
            mDevicePolicyManager.setOrganizationName(mAdminReceiverComponent, organizationName);
        }
        final int organizationColor = intent.getIntExtra(OrganizationInfoTestActivity.EXTRA_ORGANIZATION_COLOR,
                mDevicePolicyManager.getOrganizationColor(mAdminReceiverComponent));
        mDevicePolicyManager.setOrganizationColor(mAdminReceiverComponent, organizationColor);
    } else if (ACTION_TEST_PARENT_PROFILE_PASSWORD.equals(action)) {
        startActivity(new Intent(DevicePolicyManager.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD));
    }
    // This activity has no UI and is only used to respond to CtsVerifier in the primary side.
    finish();
}

From source file:com.example.android.wearable.wear.wearnotifications.StandaloneMainActivity.java

private void generateBigPictureStyleNotification() {

    Log.d(TAG, "generateBigPictureStyleNotification()");

    // Main steps for building a BIG_PICTURE_STYLE notification:
    //      0. Get your data
    //      1. Build the BIG_PICTURE_STYLE
    //      2. Set up main Intent for notification
    //      3. Set up RemoteInput, so users can input (keyboard and voice) from notification
    //      4. Build and issue the notification

    // 0. Get your data (everything unique per Notification)
    MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData = MockDatabase
            .getBigPictureStyleData();/* w  ww .  j a v a 2  s  .c  o m*/

    // 1. Build the BIG_PICTURE_STYLE
    BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle()
            // Provides the bitmap for the BigPicture notification
            .bigPicture(
                    BitmapFactory.decodeResource(getResources(), bigPictureStyleSocialAppData.getBigImage()))
            // Overrides ContentTitle in the big form of the template
            .setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle())
            // Summary line after the detail section in the big form of the template
            .setSummaryText(bigPictureStyleSocialAppData.getSummaryText());

    // 2. Set up main Intent for notification
    Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class);

    PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // 3. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly
    // from the notification without entering the app.

    // Create the RemoteInput.
    String replyLabel = getString(R.string.reply_label);
    RemoteInput remoteInput = new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT)
            .setLabel(replyLabel)
            // List of quick response choices for any wearables paired with the phone
            .setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses()).build();

    // Create PendingIntent for service that handles input.
    Intent replyIntent = new Intent(this, BigPictureSocialIntentService.class);
    replyIntent.setAction(BigPictureSocialIntentService.ACTION_COMMENT);
    PendingIntent replyActionPendingIntent = PendingIntent.getService(this, 0, replyIntent, 0);

    // Enable action to appear inline on Wear 2.0 (24+). This means it will appear over the
    // lower portion of the Notification for easy action (only possible for one action).
    final NotificationCompat.Action.WearableExtender inlineActionForWear2 = new NotificationCompat.Action.WearableExtender()
            .setHintDisplayActionInline(true).setHintLaunchesActivity(false);

    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput)
                    // Add WearableExtender to enable inline actions
                    .extend(inlineActionForWear2).build();

    // 4. Build and issue the notification

    // Because we want this to be a new notification (not updating a previous notification), we
    // create a new Builder. Later, we use the same global builder to get back the notification
    // we built here for a comment on the post.

    NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder(
            getApplicationContext());

    GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);

    // Build notification
    notificationCompatBuilder
            // BIG_PICTURE_STYLE sets title and content
            .setStyle(bigPictureStyle).setContentTitle(bigPictureStyleSocialAppData.getContentTitle())
            .setContentText(bigPictureStyleSocialAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp))
            .setContentIntent(mainPendingIntent)
            // Set primary color (important for Wear 2.0 Notifications)
            .setColor(getResources().getColor(R.color.colorPrimary))

            .setSubText(Integer.toString(1)).addAction(replyAction).setCategory(Notification.CATEGORY_SOCIAL)
            .setPriority(Notification.PRIORITY_HIGH)

            // Hides content on the lock-screen
            .setVisibility(Notification.VISIBILITY_PRIVATE)
            // Notifies system that the main launch intent is an Activity.
            .extend(new NotificationCompat.WearableExtender().setHintContentIntentLaunchesActivity(true));

    // If the phone is in "Do not disturb mode, the user will still be notified if
    // the sender(s) is starred as a favorite.
    for (String name : bigPictureStyleSocialAppData.getParticipants()) {
        notificationCompatBuilder.addPerson(name);
    }

    Notification notification = notificationCompatBuilder.build();
    mNotificationManagerCompat.notify(NOTIFICATION_ID, notification);

    // Close app to demonstrate notification in steam.
    finish();
}

From source file:com.example.android.wearable.wear.wearnotifications.MainActivity.java

private void generateBigPictureStyleNotification() {

    Log.d(TAG, "generateBigPictureStyleNotification()");

    // Main steps for building a BIG_PICTURE_STYLE notification:
    //      0. Get your data
    //      1. Build the BIG_PICTURE_STYLE
    //      2. Set up main Intent for notification
    //      3. Set up RemoteInput, so users can input (keyboard and voice) from notification
    //      4. Build and issue the notification

    // 0. Get your data (everything unique per Notification)
    MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData = MockDatabase
            .getBigPictureStyleData();/*from   ww w .  j a v a  2s. co  m*/

    // 1. Build the BIG_PICTURE_STYLE
    BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle()
            // Provides the bitmap for the BigPicture notification
            .bigPicture(
                    BitmapFactory.decodeResource(getResources(), bigPictureStyleSocialAppData.getBigImage()))
            // Overrides ContentTitle in the big form of the template
            .setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle())
            // Summary line after the detail section in the big form of the template
            .setSummaryText(bigPictureStyleSocialAppData.getSummaryText());

    // 2. Set up main Intent for notification
    Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class);

    // When creating your Intent, you need to take into account the back state, i.e., what
    // happens after your Activity launches and the user presses the back button.

    // There are two options:
    //      1. Regular activity - You're starting an Activity that's part of the application's
    //      normal workflow.

    //      2. Special activity - The user only sees this Activity if it's started from a
    //      notification. In a sense, the Activity extends the notification by providing
    //      information that would be hard to display in the notification itself.

    // Even though this sample's MainActivity doesn't link to the Activity this Notification
    // launches directly, i.e., it isn't part of the normal workflow, a social app generally
    // always links to individual posts as part of the app flow, so we will follow option 1.

    // For an example of option 2, check out the BIG_TEXT_STYLE example.

    // For more information, check out our dev article:
    // https://developer.android.com/training/notify-user/navigation.html

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack
    stackBuilder.addParentStack(BigPictureSocialMainActivity.class);
    // Adds the Intent to the top of the stack
    stackBuilder.addNextIntent(mainIntent);
    // Gets a PendingIntent containing the entire back stack
    PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification

    // Note: For API <24 (M and below) we need to use an Activity, so the lock-screen presents
    // the auth challenge. For API 24+ (N and above), we use a Service (could be a
    // BroadcastReceiver), so the user can input from Notification or lock-screen (they have
    // choice to allow) without leaving the notification.

    // Create the RemoteInput
    String replyLabel = getString(R.string.reply_label);
    RemoteInput remoteInput = new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT)
            .setLabel(replyLabel)
            // List of quick response choices for any wearables paired with the phone
            .setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses()).build();

    // Pending intent =
    //      API <24 (M and below): activity so the lock-screen presents the auth challenge
    //      API 24+ (N and above): this should be a Service or BroadcastReceiver
    PendingIntent replyActionPendingIntent;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        Intent intent = new Intent(this, BigPictureSocialIntentService.class);
        intent.setAction(BigPictureSocialIntentService.ACTION_COMMENT);
        replyActionPendingIntent = PendingIntent.getService(this, 0, intent, 0);

    } else {
        replyActionPendingIntent = mainPendingIntent;
    }

    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput)
                    .build();

    // 4. Build and issue the notification

    // Because we want this to be a new notification (not updating a previous notification), we
    // create a new Builder. Later, we use the same global builder to get back the notification
    // we built here for a comment on the post.

    NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder(
            getApplicationContext());

    GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder);

    // 4. Build and issue the notification
    notificationCompatBuilder
            // BIG_PICTURE_STYLE sets title and content for API 16 (4.1 and after)
            .setStyle(bigPictureStyle)
            // Title for API <16 (4.0 and below) devices
            .setContentTitle(bigPictureStyleSocialAppData.getContentTitle())
            // Content for API <24 (7.0 and below) devices
            .setContentText(bigPictureStyleSocialAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp))
            .setContentIntent(mainPendingIntent)
            // Set primary color (important for Wear 2.0 Notifications)
            .setColor(getResources().getColor(R.color.colorPrimary))

            // SIDE NOTE: Auto-bundling is enabled for 4 or more notifications on API 24+ (N+)
            // devices and all Android Wear devices. If you have more than one notification and
            // you prefer a different summary notification, set a group key and create a
            // summary notification via
            // .setGroupSummary(true)
            // .setGroup(GROUP_KEY_YOUR_NAME_HERE)

            .setSubText(Integer.toString(1)).addAction(replyAction).setCategory(Notification.CATEGORY_SOCIAL)
            .setPriority(Notification.PRIORITY_HIGH)

            // Hides content on the lock-screen
            .setVisibility(Notification.VISIBILITY_PRIVATE);

    // If the phone is in "Do not disturb mode, the user will still be notified if
    // the sender(s) is starred as a favorite.
    for (String name : bigPictureStyleSocialAppData.getParticipants()) {
        notificationCompatBuilder.addPerson(name);
    }

    Notification notification = notificationCompatBuilder.build();

    mNotificationManagerCompat.notify(NOTIFICATION_ID, notification);
}