Example usage for android.widget RemoteViews RemoteViews

List of usage examples for android.widget RemoteViews RemoteViews

Introduction

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

Prototype

public RemoteViews(RemoteViews landscape, RemoteViews portrait) 

Source Link

Document

Create a new RemoteViews object that will inflate as the specified landspace or portrait RemoteViews, depending on the current configuration.

Usage

From source file:com.google.android.vending.expansion.downloader.impl.V4CustomNotificationBuilder.java

@Override
public Notification build() {
    if (android.os.Build.VERSION.SDK_INT > 10) {
        // only matters for Honeycomb
        setOnlyAlertOnce(true);//from   w  w  w  .ja v  a2 s. com
    }

    // Build the RemoteView object
    RemoteViews expandedView = new RemoteViews(mContext.getPackageName(),
            R.layout.status_bar_ongoing_event_progress_bar);

    expandedView.setTextViewText(R.id.title, mContentTitle);
    // look at strings
    expandedView.setViewVisibility(R.id.description, View.VISIBLE);
    expandedView.setTextViewText(R.id.description,
            Helpers.getDownloadProgressString(this.mCurrentBytes, mTotalBytes));
    expandedView.setViewVisibility(R.id.progress_bar_frame, View.VISIBLE);
    expandedView.setProgressBar(R.id.progress_bar, (int) (mTotalBytes >> 8), (int) (mCurrentBytes >> 8),
            mTotalBytes <= 0);
    expandedView.setViewVisibility(R.id.time_remaining, View.VISIBLE);
    expandedView.setTextViewText(R.id.time_remaining, mContentInfo);
    expandedView.setTextViewText(R.id.progress_text,
            Helpers.getDownloadProgressPercent(mCurrentBytes, mTotalBytes));
    expandedView.setImageViewResource(R.id.appIcon, mIcon);

    Notification n = super.build();
    n.contentView = expandedView;
    return n;
}

From source file:com.arcusapp.soundbox.player.MediaPlayerNotification.java

public MediaPlayerNotification() {
    mNotificationManager = (NotificationManager) SoundBoxApplication.getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationBuilder = new NotificationCompat.Builder(SoundBoxApplication.getContext());
    mNotificationBuilder.setSmallIcon(R.drawable.ic_launcher);

    //mNotificationBuilder.setContentTitle("SoundBox is awesome.");
    //mNotificationBuilder.setContentText("You are awesome too !");

    mBaseView = new RemoteViews(SoundBoxApplication.getContext().getPackageName(),
            R.layout.notification_media_player_base);
    mExpandedView = new RemoteViews(SoundBoxApplication.getContext().getPackageName(),
            R.layout.notification_media_player_expanded);

    setUpMediaPlayerActions();/*  w w  w.  ja v a2  s  .  co m*/
}

From source file:barqsoft.footballscores.widget.WidgetListProvider.java

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    // Perform this loop procedure for each App Widget that belongs to this provider
    for (int appWidgetId : appWidgetIds) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_list);

        // Create an Intent to launch MainActivity
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        views.setOnClickPendingIntent(R.id.widget_item, pendingIntent);

        // Set up the collection
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            setRemoteAdapter(context, views);
        } else {//  w  w  w.j av  a2  s  . c  o m
            setRemoteAdapterV11(context, views);
        }
        Intent clickIntentTemplate = new Intent(context, MainActivity.class);
        PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
                .addNextIntentWithParentStack(clickIntentTemplate)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate);
        views.setEmptyView(R.id.widget_list, R.id.widget_empty);

        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

From source file:com.android.mms.widget.MmsWidgetProvider.java

/**
 * Update the widget appWidgetId//ww  w .  j  a  v  a 2s . c o  m
 */
private static void updateWidget(Context context, int appWidgetId) {
    if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
        Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
    }
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    PendingIntent clickIntent;

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, MmsWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent);

    remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.sms_app_label));

    // Open Mms's app conversation list when click on header
    final Intent convIntent = new Intent(context, ConversationList.class);
    clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent(context, ComposeMessageActivity.class);
    composeIntent.setAction(Intent.ACTION_SENDTO);
    clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(ComposeMessageActivity.class);
    Intent msgIntent = new Intent(Intent.ACTION_VIEW);
    msgIntent.setType("vnd.android-dir/mms-sms");
    taskStackBuilder.addNextIntent(msgIntent);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list,
            taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
}

From source file:org.namelessrom.devicecontrol.widgets.RebootWidget.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] ids) {
    final ComponentName widget = new ComponentName(context, RebootWidget.class);

    final int[] allWidgetInstancesIds = appWidgetManager.getAppWidgetIds(widget);
    for (int widgetId : allWidgetInstancesIds) {
        final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_reboot);

        final Intent intent = new Intent(context, RebootWidget.class);
        intent.setAction(SHOW_POPUP_DIALOG_REBOOT_ACTION);

        final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.widget_reboot_image, pendingIntent);

        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    }//from  w w w. ja va  2 s.  com

    super.onUpdate(context, appWidgetManager, ids);
}

From source file:com.wizardsofm.deskclock.data.TimerNotificationBuilderN.java

@Override
public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) {
    final Timer timer = unexpired.get(0);
    final int count = unexpired.size();

    // Compute some values required below.
    final boolean running = timer.isRunning();
    final Resources res = context.getResources();

    final long base = getChronometerBase(timer);
    final String pname = context.getPackageName();
    final RemoteViews content = new RemoteViews(pname,
            com.wizardsofm.deskclock.R.layout.chronometer_notif_content);
    content.setChronometerCountDown(com.wizardsofm.deskclock.R.id.chronometer, true);
    content.setChronometer(com.wizardsofm.deskclock.R.id.chronometer, base, null, running);

    final List<Notification.Action> actions = new ArrayList<>(2);

    final CharSequence stateText;
    if (count == 1) {
        if (running) {
            // Single timer is running.
            if (TextUtils.isEmpty(timer.getLabel())) {
                stateText = res.getString(com.wizardsofm.deskclock.R.string.timer_notification_label);
            } else {
                stateText = timer.getLabel();
            }//from  w ww .ja  v a2 s .co  m

            // Left button: Pause
            final Intent pause = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            final Icon icon1 = Icon.createWithResource(context,
                    com.wizardsofm.deskclock.R.drawable.ic_pause_24dp);
            final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.timer_pause);
            final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause);
            actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

            // Right Button: +1 Minute
            final Intent addMinute = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_ADD_MINUTE_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            final Icon icon2 = Icon.createWithResource(context,
                    com.wizardsofm.deskclock.R.drawable.ic_add_24dp);
            final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.timer_plus_1_min);
            final PendingIntent intent2 = Utils.pendingServiceIntent(context, addMinute);
            actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());

        } else {
            // Single timer is paused.
            stateText = res.getString(com.wizardsofm.deskclock.R.string.timer_paused);

            // Left button: Start
            final Intent start = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_START_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            final Icon icon1 = Icon.createWithResource(context,
                    com.wizardsofm.deskclock.R.drawable.ic_start_24dp);
            final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.sw_resume_button);
            final PendingIntent intent1 = Utils.pendingServiceIntent(context, start);
            actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

            // Right Button: Reset
            final Intent reset = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_RESET_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            final Icon icon2 = Icon.createWithResource(context,
                    com.wizardsofm.deskclock.R.drawable.ic_reset_24dp);
            final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.sw_reset_button);
            final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset);
            actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());
        }
    } else {
        if (running) {
            // At least one timer is running.
            stateText = res.getString(com.wizardsofm.deskclock.R.string.timers_in_use, count);
        } else {
            // All timers are paused.
            stateText = res.getString(com.wizardsofm.deskclock.R.string.timers_stopped, count);
        }

        final Intent reset = TimerService.createResetUnexpiredTimersIntent(context);

        final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_reset_24dp);
        final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.timer_reset_all);
        final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());
    }

    content.setTextViewText(com.wizardsofm.deskclock.R.id.state, stateText);

    // Intent to load the app and show the timer when the notification is tapped.
    final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_TIMERS)
            .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId())
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL,
                    com.wizardsofm.deskclock.R.string.label_notification);

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

    return new Notification.Builder(context).setOngoing(true).setLocalOnly(true).setShowWhen(false)
            .setAutoCancel(false).setCustomContentView(content).setContentIntent(pendingShowApp)
            .setPriority(Notification.PRIORITY_HIGH).setCategory(Notification.CATEGORY_ALARM)
            .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_timer)
            .setGroup(nm.getTimerNotificationGroupKey()).setVisibility(Notification.VISIBILITY_PUBLIC)
            .setStyle(new Notification.DecoratedCustomViewStyle())
            .setActions(actions.toArray(new Notification.Action[actions.size()]))
            .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background))
            .build();
}

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

@Override
public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) {
    final Timer timer = unexpired.get(0);
    final int count = unexpired.size();

    // Compute some values required below.
    final boolean running = timer.isRunning();
    final Resources res = context.getResources();

    final long base = getChronometerBase(timer);
    final String pname = context.getPackageName();
    final RemoteViews content = new RemoteViews(pname, R.layout.chronometer_notif_content);
    content.setChronometerCountDown(R.id.chronometer, true);
    content.setChronometer(R.id.chronometer, base, null, running);

    final List<Notification.Action> actions = new ArrayList<>(2);

    final CharSequence stateText;
    if (count == 1) {
        if (running) {
            // Single timer is running.
            if (TextUtils.isEmpty(timer.getLabel())) {
                stateText = res.getString(R.string.timer_notification_label);
            } else {
                stateText = timer.getLabel();
            }// ww  w  .  j  av a 2s .com

            // Left button: Pause
            final Intent pause = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_pause_24dp);
            final CharSequence title1 = res.getText(R.string.timer_pause);
            final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause);
            actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

            // Right Button: +1 Minute
            final Intent addMinute = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_ADD_MINUTE_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_add_24dp);
            final CharSequence title2 = res.getText(R.string.timer_plus_1_min);
            final PendingIntent intent2 = Utils.pendingServiceIntent(context, addMinute);
            actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());

        } else {
            // Single timer is paused.
            stateText = res.getString(R.string.timer_paused);

            // Left button: Start
            final Intent start = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_START_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_start_24dp);
            final CharSequence title1 = res.getText(R.string.sw_resume_button);
            final PendingIntent intent1 = Utils.pendingServiceIntent(context, start);
            actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

            // Right Button: Reset
            final Intent reset = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_RESET_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_reset_24dp);
            final CharSequence title2 = res.getText(R.string.sw_reset_button);
            final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset);
            actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());
        }
    } else {
        if (running) {
            // At least one timer is running.
            stateText = res.getString(R.string.timers_in_use, count);
        } else {
            // All timers are paused.
            stateText = res.getString(R.string.timers_stopped, count);
        }

        final Intent reset = TimerService.createResetUnexpiredTimersIntent(context);

        final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_reset_24dp);
        final CharSequence title1 = res.getText(R.string.timer_reset_all);
        final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());
    }

    content.setTextViewText(R.id.state, stateText);

    // Intent to load the app and show the timer when the notification is tapped.
    final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_TIMERS)
            .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId())
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, R.string.label_notification);

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

    return new Notification.Builder(context).setOngoing(true).setLocalOnly(true).setShowWhen(false)
            .setAutoCancel(false).setCustomContentView(content).setContentIntent(pendingShowApp)
            .setPriority(Notification.PRIORITY_HIGH).setCategory(Notification.CATEGORY_ALARM)
            .setSmallIcon(R.drawable.stat_notify_timer).setGroup(nm.getTimerNotificationGroupKey())
            .setVisibility(Notification.VISIBILITY_PUBLIC).setStyle(new Notification.DecoratedCustomViewStyle())
            .setActions(actions.toArray(new Notification.Action[actions.size()]))
            .setColor(ContextCompat.getColor(context, R.color.default_background)).build();
}

From source file:eu.operando.operandoapp.util.NotificationUtil.java

public void displayExfiltratedNotification(Context context, String applicationInfo,
        Set<RequestFilterUtil.FilterType> exfiltrated, int mainNotificationId) {
    try {//from w  ww. ja  v a 2s  . co  m
        StringBuilder sb = new StringBuilder();
        for (RequestFilterUtil.FilterType f : exfiltrated) {
            sb.append(f + ", ");
        }
        sb.delete(sb.length() - 2, sb.length() - 1);

        RemoteViews smallContentView = new RemoteViews(context.getPackageName(),
                R.layout.proxy_notification_small);
        smallContentView.setImageViewResource(R.id.image, R.drawable.logo_bevel);
        smallContentView.setTextViewText(R.id.titleTxtView, "Personal Information");
        smallContentView.setTextViewText(R.id.subtitleTxtView, "Expand for more info");

        RemoteViews bigContentView = new RemoteViews(context.getPackageName(),
                R.layout.proxy_notification_large);
        bigContentView.setImageViewResource(R.id.image, R.drawable.logo_bevel);
        bigContentView.setTextViewText(R.id.titleTxtView, "Personal Information");
        bigContentView.setTextViewText(R.id.subtitleTxtView,
                applicationInfo.replaceAll("\\s\\(.*?\\)", "") + " requires access to " + sb);
        bigContentView.setTextViewText(R.id.allowBtn, "Allow");
        bigContentView.setTextViewText(R.id.blockBtn, "Block");

        //get exfiltrated info to string array
        String[] exfiltrated_array = new String[exfiltrated.size()];
        int i = 0;
        for (RequestFilterUtil.FilterType filter_type : exfiltrated) {
            exfiltrated_array[i] = filter_type.name();
            i++;
        }

        //set listeners for notification buttons

        Intent allowIntent = new Intent(context, NotificationActivityReceiver.class);
        allowIntent.setAction("allow");
        Bundle allowBundle = new Bundle();
        allowBundle.putString("appInfo", applicationInfo);
        allowBundle.putInt("notificationId", mainNotificationId);
        allowBundle.putStringArray("exfiltrated", exfiltrated_array);
        allowIntent.putExtras(allowBundle);
        PendingIntent pendingAllowIntent = PendingIntent.getBroadcast(context, mainNotificationId + 1,
                allowIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        bigContentView.setOnClickPendingIntent(R.id.allowBtn, pendingAllowIntent);

        Intent blockIntent = new Intent(context, NotificationActivityReceiver.class);
        blockIntent.setAction("block");
        Bundle blockBundle = new Bundle();
        blockBundle.putString("appInfo", applicationInfo);
        blockBundle.putInt("notificationId", mainNotificationId);
        blockBundle.putStringArray("exfiltrated", exfiltrated_array);
        blockIntent.putExtras(blockBundle);
        PendingIntent pendingBlockIntent = PendingIntent.getBroadcast(context, mainNotificationId + 2,
                blockIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        bigContentView.setOnClickPendingIntent(R.id.blockBtn, pendingBlockIntent);

        Notification.Builder mBuilder = new Notification.Builder(context).setSmallIcon(R.drawable.logo_bevel)
                .setContent(smallContentView);
        Notification proxyNotification = mBuilder.build();
        proxyNotification.defaults |= Notification.DEFAULT_ALL;
        proxyNotification.bigContentView = bigContentView;

        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(mainNotificationId, proxyNotification);
        DatabaseHelper db = new DatabaseHelper(context);
        db.addPendingNotification(new PendingNotification(applicationInfo,
                TextUtils.join(", ", exfiltrated_array), mainNotificationId));
    } catch (Exception e) {
        Log.d("ERROR", e.getMessage());
    }

}

From source file:org.jitsi.android.gui.call.notification.CallNotificationManager.java

/**
 * Displays notification allowing user to control the call directly from
 * the status bar.// w w w  .ja v a 2  s  . c o  m
 * @param ctx the Android context.
 * @param callID the ID of call that will be used. The ID is managed by
 * {@link CallManager}.
 */
public synchronized void showCallNotification(Context ctx, final String callID) {
    final Call call = CallManager.getActiveCall(callID);
    if (call == null) {
        throw new IllegalArgumentException("There's no call with id: " + callID);
    }

    NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(ctx)
            .setWhen(System.currentTimeMillis()).setSmallIcon(R.drawable.notificationicon);

    RemoteViews contentView = new RemoteViews(ctx.getPackageName(), R.layout.status_bar_call);

    // Sets call peer display name
    CallPeer callPeer = call.getCallPeers().next();
    contentView.setTextViewText(R.id.calleeDisplayName, callPeer.getDisplayName());

    // Binds pending intents
    setIntents(ctx, contentView, callID);

    // Sets the content view
    nBuilder.setContent(contentView);

    Notification notification = nBuilder.build();

    NotificationManager mNotificationManager = (NotificationManager) ctx
            .getSystemService(Context.NOTIFICATION_SERVICE);

    int id = SystrayServiceImpl.getGeneralNotificationId();
    mNotificationManager.notify(id, notification);

    CtrlNotificationThread notificationHandler = new CtrlNotificationThread(ctx, call, id, notification);

    handlersMap.put(callID, notificationHandler);

    call.addCallChangeListener(new CallChangeListener() {
        public void callPeerAdded(CallPeerEvent evt) {
        }

        public void callPeerRemoved(CallPeerEvent evt) {
            stopNotification(callID);
            call.removeCallChangeListener(this);
        }

        public void callStateChanged(CallChangeEvent evt) {
        }
    });

    // Starts notification update thread
    notificationHandler.start();
}

From source file:com.commonsware.android.hcnotify.SillyService.java

private RemoteViews buildTicker() {
    RemoteViews ticker = new RemoteViews(this.getPackageName(), R.layout.ticker);

    ticker.setTextViewText(R.id.ticker_text, getString(R.string.ticker));

    return (ticker);
}