Example usage for android.app PendingIntent getBroadcast

List of usage examples for android.app PendingIntent getBroadcast

Introduction

In this page you can find the example usage for android.app PendingIntent getBroadcast.

Prototype

public static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, @Flags int flags) 

Source Link

Document

Retrieve a PendingIntent that will perform a broadcast, like calling Context#sendBroadcast(Intent) Context.sendBroadcast() .

Usage

From source file:edu.cmu.mpcs.dashboard.TagViewer.java

private String alarmSetting(String settingString) {
    if (settingString.contains("set alarm")) {
        /** Set Alarm **/

        String hour = settingString.substring(settingString.indexOf("#") + 1, settingString.indexOf("*"));
        String minute = settingString.substring(settingString.indexOf("*") + 1, settingString.indexOf("|"));

        Log.d("timePicker", hour + ":" + minute);

        int hr = Integer.parseInt(hour);
        int min = Integer.parseInt(minute);

        Log.d("Alarm", "hr:" + hr + "min:" + min);

        Calendar cal = Calendar.getInstance();
        // add minutes to the calendar object
        ////from   ww w.j a va  2 s .c  om
        cal.set(Calendar.HOUR_OF_DAY, hr);
        cal.set(Calendar.MINUTE, min);
        cal.set(Calendar.SECOND, 0);
        // cal.add(Calendar.MINUTE, 1);
        Intent alarmintent = new Intent(getApplicationContext(), AlarmReceiver.class);
        alarmintent.putExtra("title", "Alarm for " + hour + ":" + minute);
        alarmintent.putExtra("note", "Touch to turn off Alarm");
        // HELLO_ID is a static variable that must be
        // initialised at the BEGINNING OF CLASS with 1;

        PendingIntent sender = PendingIntent.getBroadcast(getApplicationContext(), HELLO_ID, alarmintent,
                PendingIntent.FLAG_UPDATE_CURRENT | Intent.FILL_IN_DATA);
        // VERY IMPORTANT TO SET FLAG_UPDATE_CURRENT...
        // this will send correct extra's informations
        // to
        // AlarmReceiver Class
        // Get the AlarmManager service

        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);

        am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
        Log.i("Alarm", "AlarmSet" + cal.toString());

        // /** Auto-sync **/
        //
        // if (!ContentResolver.getMasterSyncAutomatically())
        // ContentResolver.setMasterSyncAutomatically(true);
        // else {
        // ContentResolver.setMasterSyncAutomatically(false);
        // }

        return ("AlarmSet for : " + hour + ":" + min + "\n");

    }
    return ("");

}

From source file:it.evilsocket.dsploit.core.UpdateService.java

/**
 * connect to the notification manager and create a notification builder.
 * it also setup the cancellation Intent for get notified when our notification got cancelled.
 */// w  w w  .  jav  a 2s  .c  o  m
private void setupNotification() {
    // get notification manager
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // get notification builder
    mBuilder = new NotificationCompat.Builder(this);
    // create a broadcast receiver to get actions
    // performed on the notification by the user
    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action == null)
                return;
            // user cancelled our notification
            if (action.equals(NOTIFICATION_CANCELLED)) {
                mRunning = false;
                stopSelf();
            }
        }
    };
    // register our receiver
    registerReceiver(mReceiver, new IntentFilter(NOTIFICATION_CANCELLED));
    // set common notification actions
    mBuilder.setDeleteIntent(
            PendingIntent.getBroadcast(this, CANCEL_CODE, new Intent(NOTIFICATION_CANCELLED), 0));
    mBuilder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0));
}

From source file:com.googlecode.mindbell.accessors.ContextAccessor.java

/**
 * Create an intent to be send to UpdateStatusNotification to update notification.
 *///from w  ww  . j  a va2  s. c  o m
private PendingIntent createRefreshBroadcastIntent(int requestCode) {
    return PendingIntent.getBroadcast(context, requestCode,
            new Intent("com.googlecode.mindbell.UPDATE_STATUS_NOTIFICATION"),
            PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:org.csploit.android.core.UpdateService.java

/**
 * connect to the notification manager and create a notification builder.
 * it also setup the cancellation Intent for get notified when our notification got cancelled.
 *//*from  www.  j a va2s  . c  om*/
private void setupNotification() {
    // get notification manager
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // get notification builder
    mBuilder = new NotificationCompat.Builder(this);
    // create a broadcast receiver to get actions
    // performed on the notification by the user
    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action == null)
                return;
            // user cancelled our notification
            if (action.equals(NOTIFICATION_CANCELLED)) {
                mRunning = false;
            }
        }
    };
    // register our receiver
    registerReceiver(mReceiver, new IntentFilter(NOTIFICATION_CANCELLED));
    // set common notification actions
    mBuilder.setDeleteIntent(
            PendingIntent.getBroadcast(this, CANCEL_CODE, new Intent(NOTIFICATION_CANCELLED), 0));
    mBuilder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0));
}

From source file:com.appsimobile.appsii.Appsi.java

Notification createSuspendedNotification() {
    Intent resultIntent = new Intent(ACTION_UNSUSPEND);
    PendingIntent bc = PendingIntent.getBroadcast(this, 0, resultIntent, 0);

    return createNotification(bc, R.string.notification_suspended, R.drawable.appsi_notification_icon_alert)
            .build();//from   www .j  a v a 2  s  .  c om
}

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

private void startPlayback() {
    try {//w ww.  jav  a  2s.  c  o  m
        MediaItem playingItem = null;
        mIsStreaming = false; // playing a locally available song

        playingItem = MusicRetriever.getInstance().getCurrentSong();
        if (playingItem == null) {
            //Get all songs if the current list is empty
            MusicRetriever.getInstance().setSonglist(getAllSongs(), 0);
            MusicRetriever.getInstance().setPlayMode(e_play_mode.e_play_mode_shuffle);

            playingItem = MusicRetriever.getInstance().getCurrentSong();

            if (playingItem == null) {
                processStopRequest(true); // stop everything!
                return;
            }
        }
        mCurrentPlayingItem = playingItem;

        // set the source of the media player a a content URI
        createMediaPlayerIfNeeded();
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mPlayer.setDataSource(getApplicationContext(), playingItem.getURI());

        // starts preparing the media player in the background. When it's done, it will call
        // our OnPreparedListener (that is, the onPrepared() method on this class, since we set
        // the listener to 'this').
        //
        // Until the media player is prepared, we *cannot* call start() on it!
        mPlayer.prepareAsync();

        // If we are streaming from the internet, we want to hold a Wifi lock, which prevents
        // the Wifi radio from going to sleep while the song is playing. If, on the other hand,
        // we are *not* streaming, we want to release the lock if we were holding it before.
        //         if (mIsStreaming) mWifiLock.acquire();
        //         else if (mWifiLock.isHeld()) mWifiLock.release();
    } catch (IOException ex) {
        Log.e(TAG, "IOException playing first song: " + ex.getMessage());
        //ex.printStackTrace();
        Toast.makeText(getApplicationContext(), R.string.invalid_file_track, Toast.LENGTH_LONG).show();
        //Stop Playback
        processStopRequest();
        return;
    }
    //mSongTitle = mCurrentPlayingItem.getTitle();

    //setUpAsForeground(mSongTitle + " (loading)");

    // Use the media button APIs (if available) to register ourselves for media button
    // events

    MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent);

    //
    // Use the remote control APIs (if available) to set the playback state
    //
    if (mRemoteControlClientCompat == null) {
        Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        intent.setComponent(mMediaButtonReceiverComponent);

        mRemoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast(this /*context*/,
                0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/));

        RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat);
    }

    mRemoteControlClientCompat.setTransportControlFlags(
            RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE
                    | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP);

    updateRemoteControlPlayingState();
}

From source file:com.example.nfcreaderorigin.MainActivity.java

/** Called when the activity is first created. */
@Override/*from ww  w .  ja  v a2  s .c o  m*/
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setBlockNumber();
    // Get USB manager
    mManager = (UsbManager) getSystemService(Context.USB_SERVICE);

    // Initialize reader
    mReader = new Reader(mManager);
    mReader.setOnStateChangeListener(new OnStateChangeListener() {

        @Override
        public void onStateChange(int slotNum, int prevState, int currState) {

            if (prevState < Reader.CARD_UNKNOWN || prevState > Reader.CARD_SPECIFIC) {
                prevState = Reader.CARD_UNKNOWN;
            }

            if (currState < Reader.CARD_UNKNOWN || currState > Reader.CARD_SPECIFIC) {
                currState = Reader.CARD_UNKNOWN;
            }

            // Create output string
            final String outputString = "Slot " + slotNum + ": " + stateStrings[prevState] + " -> "
                    + stateStrings[currState];
            final String state = stateStrings[currState];

            // Show output
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    logMsg(outputString);
                    if (state.equals("Present")) {
                        mAuthenticateRead = false;
                        if (mReadMode) {
                            setBlockNumber();
                            try {

                                mTaskReadStart = false;
                                mTaskStart = false;
                                mTaskWriteStart = false;

                                TimeRead = 0;
                                TimeWrite = 0;
                                timeEnd = 0;
                                initStart = 0;
                                nowRead = 0;
                                nowWrite = 0;
                                nowStart = 0;

                                mBlockAuthen = true;
                                mReadMode = true;
                                mWriteMode = false;

                                System.gc();

                                reader();

                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                        }

                    }
                }
            });
        }
    });

    // Register receiver for USB permission
    mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mReceiver, filter);

    sdf = new SimpleDateFormat("mm:ss.SSS");

    mResponseTextView = (TextView) findViewById(R.id.main_text_view_response);
    mResponseTextView.setMovementMethod(new ScrollingMovementMethod());
    mResponseTextView.setMaxLines(MAX_LINES);
    mResponseTextView.setText("");

    mTextType = (TextView) findViewById(R.id.textType);
    mReadTime = (TextView) findViewById(R.id.textViewReadSet);
    mWriteTime = (TextView) findViewById(R.id.textViewWriteSet);
    mEndTime = (TextView) findViewById(R.id.textViewEndSet);

    mWriteType = (EditText) findViewById(R.id.EditText_writeDataType);
    mQty = (EditText) findViewById(R.id.QTY);

    formatter = new DecimalFormat("###,###,###.##");

    mWriteDataBalanceEditText = (EditText) findViewById(R.id.EditText_writeDataBalance);
    mWriteDataIdEditText = (EditText) findViewById(R.id.EditText_writeDataId);

    mTextMode = (TextView) findViewById(R.id.textMode);
    mTextBalance = (TextView) findViewById(R.id.BALANCE);

    mTextId = (TextView) findViewById(R.id.textId);
    // Initialize reader spinner

    for (UsbDevice device : mManager.getDeviceList().values()) {
        if (mReader.isSupported(device)) {
            mReaderAdapterX = device.getDeviceName().toString();
        }
    }
    // Initialize open button
    mOpenButton = (Button) findViewById(R.id.btnStart);
    mOpenButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            getDevices();
            // Disable open button
            mOpenButton.setEnabled(false);

        }
    });

    // Initialize close button
    mCloseButton = (Button) findViewById(R.id.btnStop);
    mCloseButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            // Disable buttons

            mOpenButton.setEnabled(false);
            // Clear slot items

            // Close reader
            logMsg("Closing reader...");
            new CloseTask().execute();
        }
    });

    mWriteData = (Button) findViewById(R.id.btnWrite);
    mWriteData.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mAuthenticateRead == true) {
                mBlockWrite = true;
                setBlockNumber();
                mReadMode = false;
                mWriteMode = true;
                mTextMode.setText("- W R I T E -");
                //               mReadData.setVisibility(View.VISIBLE);
                //               mWriteData.setVisibility(View.GONE);
                try {
                    writer();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } else {
                Toast.makeText(getApplicationContext(), "Please Authenticate first", Toast.LENGTH_SHORT).show();
            }

        }
    });

    mReadData = (Button) findViewById(R.id.btnRead);
    mReadData.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            mBlockAuthen = true;
            setBlockNumber();
            mReadMode = true;
            mWriteMode = false;
            mTextMode.setText("- R E A D -");
            //            mReadData.setVisibility(View.GONE);
            //            mWriteData.setVisibility(View.VISIBLE);

        }
    });

    // PIN verification command (ACOS3)
    byte[] pinVerifyData = { (byte) 0x80, 0x20, 0x06, 0x00, 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
            (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };

    // Initialize PIN verify structure (ACOS3)
    mPinVerify.setTimeOut(0);
    mPinVerify.setTimeOut2(0);
    mPinVerify.setFormatString(0);
    mPinVerify.setPinBlockString(0x08);
    mPinVerify.setPinLengthFormat(0);
    mPinVerify.setPinMaxExtraDigit(0x0408);
    mPinVerify.setEntryValidationCondition(0x03);
    mPinVerify.setNumberMessage(0x01);
    mPinVerify.setLangId(0x0409);
    mPinVerify.setMsgIndex(0);
    mPinVerify.setTeoPrologue(0, 0);
    mPinVerify.setTeoPrologue(1, 0);
    mPinVerify.setTeoPrologue(2, 0);
    mPinVerify.setData(pinVerifyData, pinVerifyData.length);

    // PIN modification command (ACOS3)
    byte[] pinModifyData = { (byte) 0x80, 0x24, 0x00, 0x00, 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
            (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };

    // Initialize PIN modify structure (ACOS3)
    mPinModify.setTimeOut(0);
    mPinModify.setTimeOut2(0);
    mPinModify.setFormatString(0);
    mPinModify.setPinBlockString(0x08);
    mPinModify.setPinLengthFormat(0);
    mPinModify.setInsertionOffsetOld(0);
    mPinModify.setInsertionOffsetNew(0);
    mPinModify.setPinMaxExtraDigit(0x0408);
    mPinModify.setConfirmPin(0x01);
    mPinModify.setEntryValidationCondition(0x03);
    mPinModify.setNumberMessage(0x02);
    mPinModify.setLangId(0x0409);
    mPinModify.setMsgIndex1(0);
    mPinModify.setMsgIndex2(0x01);
    mPinModify.setMsgIndex3(0);
    mPinModify.setTeoPrologue(0, 0);
    mPinModify.setTeoPrologue(1, 0);
    mPinModify.setTeoPrologue(2, 0);
    mPinModify.setData(pinModifyData, pinModifyData.length);

    // Initialize read key option
    mReadKeyOption.setTimeOut(0);
    mReadKeyOption.setPinMaxExtraDigit(0x0408);
    mReadKeyOption.setKeyReturnCondition(0x01);
    mReadKeyOption.setEchoLcdStartPosition(0);
    mReadKeyOption.setEchoLcdMode(0x01);

    // Disable buttons
    //      mCloseButton.setEnabled(false);
    //      mControlButton.setEnabled(false);

    // Hide input window
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:com.dwdesign.tweetings.service.TweetingsService.java

@Override
public void onCreate() {
    super.onCreate();
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mAsyncTaskManager = ((TweetingsApplication) getApplication()).getAsyncTaskManager();
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    mResolver = getContentResolver();/*ww  w. j a va 2  s.  c o m*/
    mPendingRefreshHomeTimelineIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(BROADCAST_REFRESH_HOME_TIMELINE), 0);
    mPendingRefreshMentionsIntent = PendingIntent.getBroadcast(this, 0, new Intent(BROADCAST_REFRESH_MENTIONS),
            0);
    mPendingRefreshDirectMessagesIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(BROADCAST_REFRESH_DIRECT_MESSAGES), 0);
    final IntentFilter filter = new IntentFilter(BROADCAST_REFRESHSTATE_CHANGED);
    filter.addAction(BROADCAST_NOTIFICATION_CLEARED);
    filter.addAction(BROADCAST_REFRESH_HOME_TIMELINE);
    filter.addAction(BROADCAST_REFRESH_MENTIONS);
    filter.addAction(BROADCAST_REFRESH_DIRECT_MESSAGES);
    filter.addAction(Intent.ACTION_BATTERY_LOW);
    filter.addAction(Intent.ACTION_BATTERY_OKAY);
    registerReceiver(mStateReceiver, filter);
    startAutoRefresh();
}

From source file:com.irccloud.android.Notifications.java

@SuppressLint("NewApi")
private android.app.Notification buildNotification(String ticker, int bid, long[] eids, String title,
        String text, Spanned big_text, int count, Intent replyIntent, Spanned wear_text, String network,
        String auto_messages[]) {
    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext());

    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            IRCCloudApplication.getInstance().getApplicationContext())
                    .setContentTitle(title + ((network != null) ? (" (" + network + ")") : ""))
                    .setContentText(Html.fromHtml(text)).setAutoCancel(true).setTicker(ticker)
                    .setWhen(eids[0] / 1000).setSmallIcon(R.drawable.ic_stat_notify)
                    .setColor(IRCCloudApplication.getInstance().getApplicationContext().getResources()
                            .getColor(R.color.dark_blue))
                    .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
                    .setCategory(NotificationCompat.CATEGORY_MESSAGE)
                    .setPriority(NotificationCompat.PRIORITY_HIGH).setOnlyAlertOnce(false);

    if (ticker != null && (System.currentTimeMillis() - prefs.getLong("lastNotificationTime", 0)) > 10000) {
        if (prefs.getBoolean("notify_vibrate", true))
            builder.setDefaults(android.app.Notification.DEFAULT_VIBRATE);
        String ringtone = prefs.getString("notify_ringtone", "content://settings/system/notification_sound");
        if (ringtone != null && ringtone.length() > 0)
            builder.setSound(Uri.parse(ringtone));
    }/* www . j  a  v a  2s  .co  m*/

    int led_color = Integer.parseInt(prefs.getString("notify_led_color", "1"));
    if (led_color == 1) {
        if (prefs.getBoolean("notify_vibrate", true))
            builder.setDefaults(
                    android.app.Notification.DEFAULT_LIGHTS | android.app.Notification.DEFAULT_VIBRATE);
        else
            builder.setDefaults(android.app.Notification.DEFAULT_LIGHTS);
    } else if (led_color == 2) {
        builder.setLights(0xFF0000FF, 500, 500);
    }

    SharedPreferences.Editor editor = prefs.edit();
    editor.putLong("lastNotificationTime", System.currentTimeMillis());
    editor.commit();

    Intent i = new Intent();
    i.setComponent(new ComponentName(IRCCloudApplication.getInstance().getApplicationContext().getPackageName(),
            "com.irccloud.android.MainActivity"));
    i.putExtra("bid", bid);
    i.setData(Uri.parse("bid://" + bid));
    Intent dismiss = new Intent(IRCCloudApplication.getInstance().getApplicationContext().getResources()
            .getString(R.string.DISMISS_NOTIFICATION));
    dismiss.setData(Uri.parse("irccloud-dismiss://" + bid));
    dismiss.putExtra("bid", bid);
    dismiss.putExtra("eids", eids);

    PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(
            IRCCloudApplication.getInstance().getApplicationContext(), 0, dismiss,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(
            PendingIntent.getActivity(IRCCloudApplication.getInstance().getApplicationContext(), 0, i,
                    PendingIntent.FLAG_UPDATE_CURRENT));
    builder.setDeleteIntent(dismissPendingIntent);

    if (replyIntent != null) {
        WearableExtender extender = new WearableExtender();
        PendingIntent replyPendingIntent = PendingIntent.getService(
                IRCCloudApplication.getInstance().getApplicationContext(), bid + 1, replyIntent,
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
        extender.addAction(
                new NotificationCompat.Action.Builder(R.drawable.ic_reply, "Reply", replyPendingIntent)
                        .addRemoteInput(
                                new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build())
                        .build());

        if (count > 1 && wear_text != null)
            extender.addPage(
                    new NotificationCompat.Builder(IRCCloudApplication.getInstance().getApplicationContext())
                            .setContentText(wear_text).extend(new WearableExtender().setStartScrollBottom(true))
                            .build());

        NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(
                title + ((network != null) ? (" (" + network + ")") : ""))
                        .setReadPendingIntent(dismissPendingIntent).setReplyAction(replyPendingIntent,
                                new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build());

        if (auto_messages != null) {
            for (String m : auto_messages) {
                if (m != null && m.length() > 0) {
                    unreadConvBuilder.addMessage(m);
                }
            }
        } else {
            unreadConvBuilder.addMessage(text);
        }
        unreadConvBuilder.setLatestTimestamp(eids[count - 1] / 1000);

        builder.extend(extender)
                .extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConvBuilder.build()));
    }

    if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) {
        i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class);
        i.setData(Uri.parse("irccloud-bid://" + bid));
        i.putExtras(replyIntent);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent quickReplyIntent = PendingIntent.getActivity(
                IRCCloudApplication.getInstance().getApplicationContext(), 0, i,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.ic_action_reply, "Quick Reply", quickReplyIntent);
    }

    android.app.Notification notification = builder.build();

    RemoteViews contentView = new RemoteViews(
            IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), R.layout.notification);
    contentView.setTextViewText(R.id.title, title + " (" + network + ")");
    contentView.setTextViewText(R.id.text,
            (count == 1) ? Html.fromHtml(text) : (count + " unread highlights."));
    contentView.setLong(R.id.time, "setTime", eids[0] / 1000);
    notification.contentView = contentView;

    if (Build.VERSION.SDK_INT >= 16 && big_text != null) {
        RemoteViews bigContentView = new RemoteViews(
                IRCCloudApplication.getInstance().getApplicationContext().getPackageName(),
                R.layout.notification_expanded);
        bigContentView.setTextViewText(R.id.title,
                title + (!title.equals(network) ? (" (" + network + ")") : ""));
        bigContentView.setTextViewText(R.id.text, big_text);
        bigContentView.setLong(R.id.time, "setTime", eids[0] / 1000);
        if (count > 3) {
            bigContentView.setViewVisibility(R.id.more, View.VISIBLE);
            bigContentView.setTextViewText(R.id.more, "+" + (count - 3) + " more");
        } else {
            bigContentView.setViewVisibility(R.id.more, View.GONE);
        }
        if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) {
            bigContentView.setViewVisibility(R.id.actions, View.VISIBLE);
            bigContentView.setViewVisibility(R.id.action_divider, View.VISIBLE);
            i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class);
            i.setData(Uri.parse("irccloud-bid://" + bid));
            i.putExtras(replyIntent);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            PendingIntent quickReplyIntent = PendingIntent.getActivity(
                    IRCCloudApplication.getInstance().getApplicationContext(), 0, i,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            bigContentView.setOnClickPendingIntent(R.id.action_reply, quickReplyIntent);
        }
        notification.bigContentView = bigContentView;
    }

    return notification;
}

From source file:org.metawatch.manager.Monitors.java

static void startAlarmTicker(Context context) {
    if (Preferences.logging)
        Log.d(MetaWatch.TAG, "startAlarmTicker()");
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra("action_update", "update");
    sender = PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, 0, AlarmManager.INTERVAL_HALF_HOUR, sender);
}