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:com.freeme.filemanager.FileExplorerTabActivity.java

public void showButtonNotify() {
    mBuilder = new Builder(this);
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.view_custom_button);
    if (IsFreemeOs.isFreemeOs()) {
        Bitmap bitMap = getApplicationContext().getPackageManager().getIconBitmapWithThemeBg(
                getResources().getDrawable(R.drawable.notification_clean),
                getApplicationContext().getPackageName(), 0);
        remoteViews.setImageViewBitmap(R.id.filemanager_notification_clean, bitMap);
    } else {//w w  w.  j a  v  a2s  .c om
        remoteViews.setImageViewResource(R.id.filemanager_notification_clean, R.drawable.notification_clean);
    }
    remoteViews.setTextViewText(R.id.tv_custom_title, getString(R.string.fileManager));
    remoteViews.setTextViewText(R.id.tv_custom_text, getString(R.string.clean_text));

    Intent buttonIntent = new Intent(ACTION_BUTTON);
    buttonIntent.putExtra(INTENT_BUTTONID_TAG, BUTTON_CLEAN_ID);
    PendingIntent intent_clean = PendingIntent.getBroadcast(this, 1, buttonIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.btn_custom, intent_clean);

    mBuilder.setContent(remoteViews).setContentIntent(getDefalutIntent(Notification.FLAG_AUTO_CANCEL))
            .setWhen(System.currentTimeMillis()).setPriority(Notification.PRIORITY_DEFAULT).setOngoing(true)
            .setSmallIcon(R.drawable.notification_small_clean);
    notify = mBuilder.build();
    notify.flags = Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify(200, notify);
}

From source file:tcc.iesgo.activity.ClientMapActivity.java

@Override
protected void onPause() {
    super.onPause();
    PendingIntent origPendingIntent = PendingIntent.getBroadcast(getBaseContext(), 0, getIntent(),
            PendingIntent.FLAG_UPDATE_CURRENT);
    lm.removeUpdates(origPendingIntent);
}

From source file:tcc.iesgo.activity.ClientMapActivity.java

@Override
protected void onStop() {
    super.onStop();
    PendingIntent origPendingIntent = PendingIntent.getBroadcast(getBaseContext(), 0, getIntent(),
            PendingIntent.FLAG_UPDATE_CURRENT);
    lm.removeUpdates(origPendingIntent);
    //System.exit(0);
}

From source file:com.android.calendar.alerts.AlarmScheduler.java

/**
 * Schedules an alarm for the EVENT_REMINDER_APP broadcast, for the specified
 * alarm time with a slight delay (to account for the possible duplicate broadcast
 * from the provider).//from ww w  . j a  v  a2  s.c om
 */
private static void scheduleAlarm(Context context, long eventId, long alarmTime, long currentMillis,
        AlarmManagerInterface alarmManager) {
    // Max out the alarm time to 1 day out, so an alert for an event far in the future
    // (not present in our event query results for a limited range) can only be at
    // most 1 day late.
    long maxAlarmTime = currentMillis + MAX_ALARM_ELAPSED_MS;
    if (alarmTime > maxAlarmTime) {
        alarmTime = maxAlarmTime;
    }

    // Add a slight delay (see comments on the member var).
    alarmTime += ALARM_DELAY_MS;

    if (AlertService.DEBUG) {
        Time time = new Time();
        time.set(alarmTime);
        String schedTime = time.format("%a, %b %d, %Y %I:%M%P");
        Log.d(TAG, "Scheduling alarm for EVENT_REMINDER_APP broadcast for event " + eventId + " at " + alarmTime
                + " (" + schedTime + ")");
    }

    // Schedule an EVENT_REMINDER_APP broadcast with AlarmManager.  The extra is
    // only used by AlertService for logging.  It is ignored by Intent.filterEquals,
    // so this scheduling will still overwrite the alarm that was previously pending.
    // Note that the 'setClass' is required, because otherwise it seems the broadcast
    // can be eaten by other apps and we somehow may never receive it.
    Intent intent = new Intent(AlertReceiver.EVENT_REMINDER_APP_ACTION);
    intent.setClass(context, AlertReceiver.class);
    intent.putExtra(CalendarContract.CalendarAlerts.ALARM_TIME, alarmTime);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
    alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}

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

private void checkMDD(String addr) {

    if (MDDVer == null)
        return;//from w  w  w  .  j  av a2 s . c om

    Version currentVer;
    try {
        currentVer = new Version(MDDManager.getVersion(addr), null);
    } catch (NumberFormatException e) {
        ErrUtil.logErr(e);
        return;
    } catch (IOException e) {
        ErrUtil.logErr(e);
        return;
    }

    if (currentVer.compareTo(MDDVer) >= 0) {
        LogUtil.debug("MDD on " + addr + " is already the latest version" //$NON-NLS-1$ //$NON-NLS-2$
        );
        return;
    }

    LogUtil.debug("MDD ver " + MDDVer.toString() + " is available (current ver on " + //$NON-NLS-1$ //$NON-NLS-2$
            addr + " is " + currentVer.toString() + ")" //$NON-NLS-1$ //$NON-NLS-2$
    );

    if (MDVer != null && MDVer.compareTo(MDDVer) != 0) {
        LogUtil.warn("Version mismatch:" + " MythDroid is " + MDVer.toString() + //$NON-NLS-1$ //$NON-NLS-2$
                ", MDD on " + addr + " is " + MDDVer.toString() //$NON-NLS-1$ //$NON-NLS-2$ 
        );
    }

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

    final Notification notification = new Notification(R.drawable.logo,
            Messages.getString("UpdateService.0") + "MDD" + //$NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("UpdateService.1"), //$NON-NLS-1$
            System.currentTimeMillis());

    notification.flags = Notification.FLAG_AUTO_CANCEL;

    final Intent intent = new Intent(MDDACTION);
    intent.putExtra(ADDR, addr);
    intent.putExtra(VER, MDDVer.toString());
    intent.putExtra(URL, MDDVer.url.toString());

    notification.setLatestEventInfo(getApplicationContext(), "MDD" + Messages.getString("UpdateService.2"), //$NON-NLS-1$ //$NON-NLS-2$
            MDDVer.toString() + Messages.getString("UpdateService.1") + //$NON-NLS-1$ 
                    Messages.getString("UpdateService.3"), //$NON-NLS-1$
            PendingIntent.getBroadcast(this, 0, intent, 0));

    nm.notify(CHECKMDD, notification);

}

From source file:com.Duo.music.player.Services.AudioPlaybackService.java

/**
 * Initializes remote control clients for this service session. 
 * Currently used for lockscreen controls.
 *///from   w  w w  .j ava 2 s  . co m
public void initRemoteControlClient() {
    if (mRemoteControlClientCompat == null) {
        Intent remoteControlIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        remoteControlIntent.setComponent(mMediaButtonReceiverComponent);

        mRemoteControlClientCompat = new RemoteControlClientCompat(
                PendingIntent.getBroadcast(mContext, 0, remoteControlIntent, 0));
        RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat);

    }

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

}

From source file:com.smarthome.deskclock.Alarms.java

/**
 * Sets alert in AlarmManger and StatusBar.  This is what will
 * actually launch the alert when the alarm triggers.
 *
 * @param alarm Alarm./*  w  ww .  ja  v  a2 s  .  c om*/
 * @param atTimeInMillis milliseconds since epoch
 */
private static void enableAlert(Context context, final Alarm alarm, final long atTimeInMillis) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    if (Log.LOGV) {
        Log.v("** setAlert id " + alarm.id + " atTime " + atTimeInMillis);
    }

    Intent intent = new Intent(ALARM_ALERT_ACTION);

    // XXX: This is a slight hack to avoid an exception in the remote
    // AlarmManagerService process. The AlarmManager adds extra data to
    // this Intent which causes it to inflate. Since the remote process
    // does not know about the Alarm class, it throws a
    // ClassNotFoundException.
    //
    // To avoid this, we marshall the data ourselves and then parcel a plain
    // byte[] array. The AlarmReceiver class knows to build the Alarm
    // object from the byte[] array.
    Parcel out = Parcel.obtain();
    alarm.writeToParcel(out, 0);
    out.setDataPosition(0);
    intent.putExtra(ALARM_RAW_DATA, out.marshall());

    PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender);

    setStatusBarIcon(context, true);

    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(atTimeInMillis);
    String timeString = formatDayAndTime(context, c);
    saveNextAlarm(context, timeString);
}

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

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void buildForLollipopAndAbove(MediaInfo info, Bitmap bitmap, boolean isPlaying)
        throws CastException, TransientNetworkDisconnectionException, NoConnectionException {

    // Playback PendingIntent
    Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK);
    playbackIntent.setPackage(getPackageName());
    PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(this, 0, playbackIntent, 0);

    // Disconnect PendingIntent
    Intent stopIntent = new Intent(ACTION_STOP);
    stopIntent.setPackage(getPackageName());
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0);

    // Main Content PendingIntent
    Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation());
    Intent contentIntent = new Intent(this, mTargetActivity);
    contentIntent.putExtra("media", mediaWrapper);

    // Media metadata
    MediaMetadata mm = info.getMetadata();
    String castingTo = getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName());
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(mTargetActivity);
    stackBuilder.addNextIntent(contentIntent);
    if (stackBuilder.getIntentCount() > 1) {
        stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper);
    }/*from   ww  w .j a va 2  s  .  c o m*/
    PendingIntent contentPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mNotification = new Notification.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification)
            .setContentTitle(mm.getString(MediaMetadata.KEY_TITLE)).setContentText(castingTo)
            .setContentIntent(contentPendingIntent).setLargeIcon(bitmap)
            .addAction(isPlaying ? R.drawable.ic_pause_white_48dp : R.drawable.ic_play_arrow_white_48dp,
                    getString(R.string.pause), playbackPendingIntent)
            .addAction(R.drawable.ic_clear_white_24dp, getString(R.string.disconnect), stopPendingIntent)
            .setStyle(new Notification.MediaStyle().setShowActionsInCompactView(new int[] { 0, 1 }))
            .setOngoing(true).setShowWhen(false).setVisibility(Notification.VISIBILITY_PUBLIC).build();

}

From source file:com.aero2.android.DefaultActivities.SmogMapActivity.java

public void setupAlarm(int hourOfDay) {
    //Alarm has been called
    ALARM_NOT_CALLED = false;/*from w  w  w  .ja  v  a 2  s.c  om*/

    //Setup what the alarm has to do when it goes off.
    Intent alarmIntent = new Intent(SmogMapActivity.this, AirAzureDownloadService.AlarmReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(SmogMapActivity.this, 0, alarmIntent,
            PendingIntent.FLAG_ONE_SHOT);//getBroadcast(context, 0, i, 0);
    Log.v("OnCreate", "Alarm Intent Created");

    //Set the AlarmManager to wake up the system every day at 6 a.m.
    AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
    long timeEveryDay = calendar.getTimeInMillis();
    long currentTime = System.currentTimeMillis();
    long oneMin = 60 * 1000;
    am.setInexactRepeating(AlarmManager.RTC_WAKEUP, timeEveryDay, AlarmManager.INTERVAL_DAY, pi);
    if ((currentTime + oneMin) < timeEveryDay) {
        Log.v(LOG_TAG, "First time download and time is before 6 a.m.");
        Intent firstTimeDownloadIntent = new Intent(getApplicationContext(), AirAzureDownloadService.class);
        startService(firstTimeDownloadIntent);
    }
}