Example usage for android.widget RemoteViews setTextViewText

List of usage examples for android.widget RemoteViews setTextViewText

Introduction

In this page you can find the example usage for android.widget RemoteViews setTextViewText.

Prototype

public void setTextViewText(int viewId, CharSequence text) 

Source Link

Document

Equivalent to calling TextView#setText(CharSequence)

Usage

From source file:com.android.deskclock.data.StopwatchNotificationBuilderPreN.java

@Override
public Notification build(Context context, NotificationModel nm, Stopwatch stopwatch) {
    @StringRes/*w ww. ja v  a2s .c  o m*/
    final int eventLabel = R.string.label_notification;

    // Intent to load the app when the notification is tapped.
    final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_STOPWATCH)
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

    final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    // Compute some values required below.
    final boolean running = stopwatch.isRunning();
    final String pname = context.getPackageName();
    final Resources res = context.getResources();
    final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime();

    final RemoteViews collapsed = new RemoteViews(pname, R.layout.stopwatch_notif_collapsed);
    collapsed.setChronometer(R.id.swn_collapsed_chronometer, base, null, running);
    collapsed.setOnClickPendingIntent(R.id.swn_collapsed_hitspace, pendingShowApp);
    collapsed.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch);

    final RemoteViews expanded = new RemoteViews(pname, R.layout.stopwatch_notif_expanded);
    expanded.setChronometer(R.id.swn_expanded_chronometer, base, null, running);
    expanded.setOnClickPendingIntent(R.id.swn_expanded_hitspace, pendingShowApp);
    expanded.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch);

    @IdRes
    final int leftButtonId = R.id.swn_left_button;
    @IdRes
    final int rightButtonId = R.id.swn_right_button;
    if (running) {
        // Left button: Pause
        expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_pause_button));
        setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_pause_24dp);
        final Intent pause = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
        final PendingIntent pendingPause = Utils.pendingServiceIntent(context, pause);
        expanded.setOnClickPendingIntent(leftButtonId, pendingPause);

        // Right button: Add Lap
        if (DataModel.getDataModel().canAddMoreLaps()) {
            expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_lap_button));
            setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_sw_lap_24dp);

            final Intent lap = new Intent(context, StopwatchService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
            final PendingIntent pendingLap = Utils.pendingServiceIntent(context, lap);
            expanded.setOnClickPendingIntent(rightButtonId, pendingLap);
            expanded.setViewVisibility(rightButtonId, VISIBLE);
        } else {
            expanded.setViewVisibility(rightButtonId, INVISIBLE);
        }

        // Show the current lap number if any laps have been recorded.
        final int lapCount = DataModel.getDataModel().getLaps().size();
        if (lapCount > 0) {
            final int lapNumber = lapCount + 1;
            final String lap = res.getString(R.string.sw_notification_lap_number, lapNumber);
            collapsed.setTextViewText(R.id.swn_collapsed_laps, lap);
            collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE);
            expanded.setTextViewText(R.id.swn_expanded_laps, lap);
            expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE);
        } else {
            collapsed.setViewVisibility(R.id.swn_collapsed_laps, GONE);
            expanded.setViewVisibility(R.id.swn_expanded_laps, GONE);
        }
    } else {
        // Left button: Start
        expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_start_button));
        setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_start_24dp);
        final Intent start = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
        final PendingIntent pendingStart = Utils.pendingServiceIntent(context, start);
        expanded.setOnClickPendingIntent(leftButtonId, pendingStart);

        // Right button: Reset (dismisses notification and resets stopwatch)
        expanded.setViewVisibility(rightButtonId, VISIBLE);
        expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_reset_button));
        setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_reset_24dp);
        final Intent reset = new Intent(context, StopwatchService.class)
                .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
                .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);
        final PendingIntent pendingReset = Utils.pendingServiceIntent(context, reset);
        expanded.setOnClickPendingIntent(rightButtonId, pendingReset);

        // Indicate the stopwatch is paused.
        collapsed.setTextViewText(R.id.swn_collapsed_laps, res.getString(R.string.swn_paused));
        collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE);
        expanded.setTextViewText(R.id.swn_expanded_laps, res.getString(R.string.swn_paused));
        expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE);
    }

    // Swipe away will reset the stopwatch without bringing forward the app.
    final Intent reset = new Intent(context, StopwatchService.class)
            .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH)
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel);

    final Notification notification = new NotificationCompat.Builder(context).setLocalOnly(true)
            .setOngoing(running).setContent(collapsed).setAutoCancel(stopwatch.isPaused())
            .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.stat_notify_stopwatch)
            .setDeleteIntent(Utils.pendingServiceIntent(context, reset))
            .setColor(ContextCompat.getColor(context, R.color.default_background)).build();
    notification.bigContentView = expanded;
    return notification;
}

From source file:org.alfresco.mobile.android.platform.AlfrescoNotificationManager.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public int createNotification(int notificationId, Bundle params) {
    Notification notification;/*from ww  w  . j  a  v  a  2s .co m*/

    // Get the builder to create notification.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(appContext.getApplicationContext());
    builder.setContentTitle(params.getString(ARGUMENT_TITLE));
    if (params.containsKey(ARGUMENT_DESCRIPTION)) {
        builder.setContentText(params.getString(ARGUMENT_DESCRIPTION));
    }
    builder.setNumber(0);

    if (AndroidVersion.isLollipopOrAbove()) {
        builder.setSmallIcon(R.drawable.ic_notification);
        builder.setColor(appContext.getResources().getColor(R.color.alfresco_sky));
    } else {
        builder.setSmallIcon(R.drawable.ic_notification);
    }

    if (params.containsKey(ARGUMENT_DESCRIPTION)) {
        builder.setContentText(params.getString(ARGUMENT_DESCRIPTION));
    }

    if (params.containsKey(ARGUMENT_CONTENT_INFO)) {
        builder.setContentInfo(params.getString(ARGUMENT_CONTENT_INFO));
    }

    if (params.containsKey(ARGUMENT_SMALL_ICON)) {
        builder.setSmallIcon(params.getInt(ARGUMENT_SMALL_ICON));
    }

    Intent i;
    PendingIntent pIntent;
    switch (notificationId) {
    case CHANNEL_SYNC:
        i = new Intent(PrivateIntent.ACTION_SYNCHRO_DISPLAY);
        pIntent = PendingIntent.getActivity(appContext, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
        break;

    default:
        i = new Intent(PrivateIntent.ACTION_DISPLAY_OPERATIONS);
        i.putExtra(PrivateIntent.EXTRA_OPERATIONS_TYPE, notificationId);
        if (SessionUtils.getAccount(appContext) != null) {
            i.putExtra(PrivateIntent.EXTRA_ACCOUNT_ID, SessionUtils.getAccount(appContext).getId());
        }
        pIntent = PendingIntent.getActivity(appContext, 0, i, 0);
        break;
    }
    builder.setContentIntent(pIntent);

    if (AndroidVersion.isICSOrAbove()) {
        if (params.containsKey(ARGUMENT_PROGRESS_MAX) && params.containsKey(ARGUMENT_PROGRESS)) {
            long max = params.getLong(ARGUMENT_PROGRESS_MAX);
            long progress = params.getLong(ARGUMENT_PROGRESS);
            float value = (((float) progress / ((float) max)) * 100);
            int percentage = Math.round(value);
            builder.setProgress(100, percentage, false);
        }

        if (params.getBoolean(ARGUMENT_INDETERMINATE)) {
            builder.setProgress(0, 0, true);
        }
    } else {
        RemoteViews remote = new RemoteViews(appContext.getPackageName(), R.layout.app_notification);
        remote.setImageViewResource(R.id.status_icon, R.drawable.ic_application_logo);
        remote.setTextViewText(R.id.status_text, params.getString(ARGUMENT_TITLE));
        remote.setProgressBar(R.id.status_progress, params.getInt(ARGUMENT_PROGRESS_MAX), 0, false);
        builder.setContent(remote);
    }

    if (AndroidVersion.isJBOrAbove()) {
        builder.setPriority(0);
        notification = builder.build();
    } else {
        notification = builder.getNotification();
    }

    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    ((NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE)).notify(notificationId,
            notification);

    return notificationId;
}

From source file:com.sean.takeastand.alarmprocess.AlarmService.java

private void updateNotification() {
    /*if (!bRepeatingAlarmStepCheck) {
    mNotifTimePassed++;/*from ww w. j  av a 2 s  .  c  o m*/
    }
    Log.i(TAG, "time since first notification: " + mNotifTimePassed + setMinutes(mNotifTimePassed));*/
    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent[] pendingIntents = makeNotificationIntents();
    RemoteViews rvRibbon = new RemoteViews(getPackageName(), R.layout.stand_notification);
    rvRibbon.setOnClickPendingIntent(R.id.btnStood, pendingIntents[1]);
    rvRibbon.setTextViewText(R.id.notificationTimeStamp, notificationClockTime);
    /*rvRibbon.setTextViewText(R.id.stand_up_minutes, mNotifTimePassed +
        setMinutes(mNotifTimePassed));
    rvRibbon.setTextViewText(R.id.topTextView, getString(R.string.stand_up_time_up));*/
    NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this);
    alarmNotificationBuilder.setContent(rvRibbon);
    alarmNotificationBuilder.setContentIntent(pendingIntents[0]).setAutoCancel(false)
            .setTicker(getString(R.string.stand_up_time_low)).setSmallIcon(R.drawable.ic_notification_small)
            .setContentTitle("Take A Stand ")
            //.setContentText("Mark Stood\n" + mNotifTimePassed + setMinutes(mNotifTimePassed))
            .extend(new NotificationCompat.WearableExtender().addAction(
                    new NotificationCompat.Action.Builder(R.drawable.ic_action_done, "Stood", pendingIntents[1])
                            .build())
                    .setContentAction(0).setHintHideIcon(true)
    //                    .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.alarm_schedule_passed))
    );

    boolean[] alertType;
    if (mCurrentAlarmSchedule != null) {
        alertType = mCurrentAlarmSchedule.getAlertType();
    } else {
        alertType = Utils.getDefaultAlertType(this);
    }

    if ((alertType[0])) {
        alarmNotificationBuilder.setLights(238154000, 1000, 4000);
    }
    if (Utils.getRepeatAlerts(this)) {
        if (alertType[1]) {
            boolean bUseLastStepCounters = false;
            if (!bRepeatingAlarmStepCheck) {
                bRepeatingAlarmStepCheck = true;
                bUseLastStepCounters = UseLastStepCounters(null);
            }
            if (!bUseLastStepCounters) {
                bRepeatingAlarmStepCheck = false;
                alarmNotificationBuilder.setVibrate(mVibrationPattern);
                AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT
                        && Utils.getVibrateOverride(this)) {
                    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                    v.vibrate(mVibrationPattern, -1);
                }
            }
        }
        if (alertType[2]) {
            Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            alarmNotificationBuilder.setSound(soundUri);
        }
    }

    Notification alarmNotification = alarmNotificationBuilder.build();
    notificationManager.notify(R.integer.AlarmNotificationID, alarmNotification);
}

From source file:com.andreadec.musicplayer.MusicService.java

private void updateNotificationMessage() {
    /* Update remote control client */
    if (Build.VERSION.SDK_INT >= 14) {
        if (currentPlayingItem == null) {
            remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        } else {/*from ww w  . j av a 2s  .co m*/
            if (isPlaying()) {
                remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
            } else {
                remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
            }
            RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, currentPlayingItem.getTitle());
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, currentPlayingItem.getArtist());
            metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST,
                    currentPlayingItem.getArtist());
            metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getDuration());
            if (currentPlayingItem.hasImage()) {
                metadataEditor.putBitmap(METADATA_KEY_ARTWORK, currentPlayingItem.getImage());
            } else {
                metadataEditor.putBitmap(METADATA_KEY_ARTWORK, icon.copy(icon.getConfig(), false));
            }
            metadataEditor.apply();
        }
    }

    /* Update notification */
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setSmallIcon(R.drawable.audio_white);
    //notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    notificationBuilder.setOngoing(true);

    int playPauseIcon = isPlaying() ? R.drawable.pause : R.drawable.play;
    //int playPauseString = isPlaying() ? R.string.pause : R.string.play;
    notificationBuilder.setContentIntent(pendingIntent);

    String notificationMessage = "";
    if (currentPlayingItem == null) {
        notificationMessage = getResources().getString(R.string.noSong);
    } else {
        if (currentPlayingItem.getArtist() != null && !currentPlayingItem.getArtist().equals(""))
            notificationMessage = currentPlayingItem.getArtist() + " - ";
        notificationMessage += currentPlayingItem.getTitle();
    }

    /*notificationBuilder.addAction(R.drawable.previous, getResources().getString(R.string.previous), previousPendingIntent);
    notificationBuilder.addAction(playPauseIcon, getResources().getString(playPauseString), playpausePendingIntent);
    notificationBuilder.addAction(R.drawable.next, getResources().getString(R.string.next), nextPendingIntent);*/
    notificationBuilder.setContentTitle(getResources().getString(R.string.app_name));
    notificationBuilder.setContentText(notificationMessage);

    notification = notificationBuilder.build();

    RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.layout_notification);

    if (currentPlayingItem == null) {
        notificationLayout.setTextViewText(R.id.textViewArtist, getString(R.string.app_name));
        notificationLayout.setTextViewText(R.id.textViewTitle, getString(R.string.noSong));
        notificationLayout.setImageViewBitmap(R.id.imageViewNotification,
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    } else {
        notificationLayout.setTextViewText(R.id.textViewArtist, currentPlayingItem.getArtist());
        notificationLayout.setTextViewText(R.id.textViewTitle, currentPlayingItem.getTitle());
        Bitmap image = currentPlayingItem.getImage();
        if (image != null) {
            notificationLayout.setImageViewBitmap(R.id.imageViewNotification, image);
        } else {
            notificationLayout.setImageViewBitmap(R.id.imageViewNotification,
                    BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
        }
    }
    notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationQuit, quitPendingIntent);
    notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationPrevious, previousPendingIntent);
    notificationLayout.setImageViewResource(R.id.buttonNotificationPlayPause, playPauseIcon);
    notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationPlayPause, playpausePendingIntent);
    notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationNext, nextPendingIntent);
    notification.bigContentView = notificationLayout;

    notificationManager.notify(Constants.NOTIFICATION_MAIN, notification);
}

From source file:com.google.sample.castcompanionlibrary.notification.VideoCastNotificationService.java

private RemoteViews build(MediaInfo info, Bitmap bitmap, boolean isPlaying)
        throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
    if (mIsLollipopOrAbove) {
        buildForLollipopAndAbove(info, bitmap, isPlaying);
        return null;
    }/* w ww.j a  v  a 2  s . co  m*/
    Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation());
    Intent contentIntent = new Intent(this, mTargetActivity);

    contentIntent.putExtra("media", mediaWrapper);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    stackBuilder.addParentStack(mTargetActivity);

    stackBuilder.addNextIntent(contentIntent);
    if (stackBuilder.getIntentCount() > 1) {
        stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper);
    }

    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID,
            PendingIntent.FLAG_UPDATE_CURRENT);

    MediaMetadata mm = info.getMetadata();

    RemoteViews rv = new RemoteViews(getPackageName(), R.layout.custom_notification);
    if (mIsIcsOrAbove) {
        addPendingIntents(rv, isPlaying, info);
    }
    if (null != bitmap) {
        rv.setImageViewBitmap(R.id.iconView, bitmap);
    } else {
        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dummy_album_art);
        rv.setImageViewBitmap(R.id.iconView, bitmap);
    }
    rv.setTextViewText(R.id.titleView, mm.getString(MediaMetadata.KEY_TITLE));
    String castingTo = getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName());
    rv.setTextViewText(R.id.subTitleView, castingTo);
    mNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification)
            .setContentIntent(resultPendingIntent).setContent(rv).setAutoCancel(false).setOngoing(true).build();

    // to get around a bug in GB version, we add the following line
    // see https://code.google.com/p/android/issues/detail?id=30495
    mNotification.contentView = rv;

    return rv;
}

From source file:com.teclib.service.NotificationGPSActivation.java

public void CustomNotification() {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_install_apps);

    Intent intent = new Intent(this, ActiveGPSActivity.class);

    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_white_stork).setTicker(getString(R.string.gpsAsk_string)).setOngoing(true)
            .setContentIntent(pIntent).setAutoCancel(true).setContent(remoteViews);

    Notification notificationInstall = builder.build();
    notificationInstall.flags |= Notification.FLAG_AUTO_CANCEL;

    remoteViews.setImageViewResource(R.id.imagenotileft, R.mipmap.ic_notification_install_apps);

    remoteViews.setTextViewText(R.id.title, getString(R.string.app_name));
    remoteViews.setTextViewText(R.id.text, getString(R.string.gpsAsk_string));

    NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationmanager.notify(4, builder.build());

}

From source file:com.teclib.service.NotificationRemoveService.java

public void CustomNotification() {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_install_apps);

    Intent intent = new Intent(this, RemoveApplicationActivity.class);

    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_white_stork).setTicker(getString(R.string.removeAsk_string))
            .setOngoing(true).setContentIntent(pIntent).setAutoCancel(true).setContent(remoteViews);

    Notification notificationInstall = builder.build();
    notificationInstall.flags |= Notification.FLAG_AUTO_CANCEL;

    remoteViews.setImageViewResource(R.id.imagenotileft, R.mipmap.ic_notification_install_apps);

    remoteViews.setTextViewText(R.id.title, getString(R.string.app_name));
    remoteViews.setTextViewText(R.id.text, getString(R.string.removeAsk_string));

    NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationmanager.notify(3, builder.build());
}

From source file:com.teclib.service.NotificationAdminRequest.java

public void CustomNotification() {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_install_apps);

    Intent intent = new Intent(this, MQTTNotifierActivity.class);

    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_white_stork).setTicker(getString(R.string.installAsk_string))
            .setOngoing(true).setContentIntent(pIntent).setAutoCancel(true).setContent(remoteViews);

    Notification notificationInstall = builder.build();
    notificationInstall.flags |= Notification.FLAG_AUTO_CANCEL;

    remoteViews.setImageViewResource(R.id.imagenotileft, R.mipmap.ic_notification_install_apps);

    remoteViews.setTextViewText(R.id.title, getString(R.string.app_name));
    remoteViews.setTextViewText(R.id.text, getString(R.string.installAsk_string));

    NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationmanager.notify(6, builder.build());

}

From source file:eu.power_switch.widget.provider.ReceiverWidgetProvider.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    Log.d("Updating Receiver Widgets...");
    // Perform this loop procedure for each App Widget that belongs to this provider
    for (int i = 0; i < appWidgetIds.length; i++) {
        int appWidgetId = appWidgetIds[i];
        RemoteViews remoteViews = new RemoteViews(
                context.getResources().getString(eu.power_switch.shared.R.string.PACKAGE_NAME),
                R.layout.widget_receiver);

        try {//from   w ww. j  av  a2 s. com
            ReceiverWidget receiverWidget = DatabaseHandler.getReceiverWidget(appWidgetId);
            Room room = DatabaseHandler.getRoom(receiverWidget.getRoomId());
            if (room != null) {
                Receiver receiver = DatabaseHandler.getReceiver(receiverWidget.getReceiverId());

                if (receiver != null) {
                    Apartment apartment = DatabaseHandler.getApartment(room.getApartmentId());
                    // update UI
                    remoteViews.setTextViewText(R.id.textView_receiver_widget_name,
                            apartment.getName() + ": " + room.getName() + ": " + receiver.getName());

                    LinkedList<Button> buttons = receiver.getButtons();

                    // remove all previous buttons
                    remoteViews.removeAllViews(R.id.linearlayout_receiver_widget);

                    // add buttons from database
                    int buttonOffset = 0;
                    for (Button button : buttons) {
                        // set button action
                        RemoteViews buttonView = new RemoteViews(
                                context.getResources().getString(eu.power_switch.shared.R.string.PACKAGE_NAME),
                                R.layout.widget_receiver_button_layout);
                        SpannableString s = new SpannableString(button.getName());
                        s.setSpan(new StyleSpan(Typeface.BOLD), 0, button.getName().length(), 0);
                        buttonView.setTextViewText(R.id.button_widget_universal, s);
                        if (SmartphonePreferencesHandler.getHighlightLastActivatedButton()
                                && receiver.getLastActivatedButtonId().equals(button.getId())) {
                            buttonView.setTextColor(R.id.button_widget_universal,
                                    ContextCompat.getColor(context, R.color.color_light_blue_a700));
                        }

                        PendingIntent intent = WidgetIntentReceiver.buildReceiverWidgetActionPendingIntent(
                                context, apartment, room, receiver, button, appWidgetId * 15 + buttonOffset);
                        buttonView.setOnClickPendingIntent(R.id.button_widget_universal, intent);

                        remoteViews.addView(R.id.linearlayout_receiver_widget, buttonView);
                        buttonOffset++;
                    }
                    remoteViews.setViewVisibility(R.id.linearlayout_receiver_widget, View.VISIBLE);
                } else {
                    remoteViews.setTextViewText(R.id.textView_receiver_widget_name,
                            context.getString(R.string.receiver_not_found));
                    remoteViews.removeAllViews(R.id.linearlayout_receiver_widget);
                    remoteViews.setViewVisibility(R.id.linearlayout_receiver_widget, View.GONE);
                }
            } else {
                remoteViews.setTextViewText(R.id.textView_receiver_widget_name,
                        context.getString(R.string.room_not_found));
                remoteViews.removeAllViews(R.id.linearlayout_receiver_widget);
                remoteViews.setViewVisibility(R.id.linearlayout_receiver_widget, View.GONE);
            }
        } catch (Exception e) {
            Log.e(e);
            remoteViews.setTextViewText(R.id.textView_receiver_widget_name,
                    context.getString(R.string.unknown_error));
            remoteViews.removeAllViews(R.id.linearlayout_receiver_widget);
            remoteViews.setViewVisibility(R.id.linearlayout_receiver_widget, View.GONE);
        }
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void refreshCityOrWeather(Context context, String what, int which) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    if (appWidgetManager != null) {
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
        for (int appWidgetId : appWidgetIds) {
            RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
            if (1 == which) {
                widget.setTextViewText(R.id.city, what);
            } else if (2 == which) {
                if (what.equals("")) {
                    //widget.setTextViewText(R.id.temperature, context.getString(R.string.weather_network_error));
                } else if (what.contains(",")) {
                    String weather = what.split(",")[0];
                    String temperature = what.split(",")[1];
                    String image = what.split(",")[2];
                    widget.setTextViewText(R.id.temperature, temperature);
                    widget.setImageViewResource(R.id.weather, getWeatherImageId(image));
                }/*from w w w .  ja  va  2  s  .  co m*/
            }
            appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
        }
    }
}