Search in sources :

Example 71 with PendingIntent

use of android.app.PendingIntent in project platform_frameworks_base by android.

the class AudioManager method registerMediaButtonEventReceiver.

//====================================================================
// Remote Control
/**
     * Register a component to be the sole receiver of MEDIA_BUTTON intents.
     * @param eventReceiver identifier of a {@link android.content.BroadcastReceiver}
     *      that will receive the media button intent. This broadcast receiver must be declared
     *      in the application manifest. The package of the component must match that of
     *      the context you're registering from.
     * @deprecated Use {@link MediaSession#setMediaButtonReceiver(PendingIntent)} instead.
     */
@Deprecated
public void registerMediaButtonEventReceiver(ComponentName eventReceiver) {
    if (eventReceiver == null) {
        return;
    }
    if (!eventReceiver.getPackageName().equals(getContext().getPackageName())) {
        Log.e(TAG, "registerMediaButtonEventReceiver() error: " + "receiver and context package names don't match");
        return;
    }
    // construct a PendingIntent for the media button and register it
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    //     the associated intent will be handled by the component being registered
    mediaButtonIntent.setComponent(eventReceiver);
    PendingIntent pi = PendingIntent.getBroadcast(getContext(), 0, /*requestCode, ignored*/
    mediaButtonIntent, 0);
    registerMediaButtonIntent(pi, eventReceiver);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 72 with PendingIntent

use of android.app.PendingIntent in project platform_frameworks_base by android.

the class CarrierDefaultReceiverTest method testOnReceiveRedirection.

@Test
public void testOnReceiveRedirection() {
    // carrier action idx list includes 4(portal notification) & 1(disable metered APNs)
    // upon redirection signal
    PersistableBundle b = new PersistableBundle();
    b.putStringArray(CarrierConfigManager.KEY_CARRIER_DEFAULT_ACTIONS_ON_REDIRECTION_STRING_ARRAY, new String[] { "4,1" });
    doReturn(b).when(mCarrierConfigMgr).getConfig();
    Intent intent = new Intent(TelephonyIntents.ACTION_CARRIER_SIGNAL_REDIRECTED);
    intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
    Rlog.d(TAG, "OnReceive redirection intent");
    mReceiver.onReceive(mContext, intent);
    mContext.waitForMs(100);
    Rlog.d(TAG, "verify carrier action: showPortalNotification");
    verify(mNotificationMgr, times(1)).notify(mString.capture(), mInt.capture(), mNotification.capture());
    assertEquals(PORTAL_NOTIFICATION_ID, (int) mInt.getValue());
    assertEquals(PORTAL_NOTIFICATION_TAG, mString.getValue());
    PendingIntent pendingIntent = mNotification.getValue().contentIntent;
    assertNotNull(pendingIntent);
    Rlog.d(TAG, "verify carrier action: disable all metered apns");
    verify(mTelephonyMgr).carrierActionSetMeteredApnsEnabled(eq(subId), eq(false));
}
Also used : PersistableBundle(android.os.PersistableBundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Test(org.junit.Test)

Example 73 with PendingIntent

use of android.app.PendingIntent in project platform_frameworks_base by android.

the class CarrierActionUtils method onShowCaptivePortalNotification.

private static void onShowCaptivePortalNotification(Intent intent, Context context) {
    logd("onShowCaptivePortalNotification");
    final NotificationManager notificationMgr = context.getSystemService(NotificationManager.class);
    Intent portalIntent = new Intent(context, CaptivePortalLoginActivity.class);
    portalIntent.putExtras(intent);
    portalIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, portalIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Notification notification = getNotification(context, R.string.portal_notification_id, R.string.portal_notification_detail, pendingIntent);
    try {
        notificationMgr.notify(PORTAL_NOTIFICATION_TAG, PORTAL_NOTIFICATION_ID, notification);
    } catch (NullPointerException npe) {
        loge("setNotificationVisible: " + npe);
    }
}
Also used : NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 74 with PendingIntent

use of android.app.PendingIntent in project platform_frameworks_base by android.

the class MainActivity method sendNotification.

private void sendNotification(int count) {
    Notification.Builder builder = new Notification.Builder(this).setContentTitle(String.format("%s OSU available", count)).setContentText("Choose one to connect").setSmallIcon(android.R.drawable.ic_dialog_info).setAutoCancel(false);
    Intent resultIntent = new Intent(this, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, builder.build());
}
Also used : NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.app.TaskStackBuilder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) Notification(android.app.Notification)

Example 75 with PendingIntent

use of android.app.PendingIntent in project platform_frameworks_base by android.

the class BugreportProgressService method newCancelIntent.

/**
     * Creates a {@link PendingIntent} for a notification action used to cancel a bugreport.
     */
private static PendingIntent newCancelIntent(Context context, BugreportInfo info) {
    final Intent intent = new Intent(INTENT_BUGREPORT_CANCEL);
    intent.setClass(context, BugreportProgressService.class);
    intent.putExtra(EXTRA_ID, info.id);
    return PendingIntent.getService(context, info.id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Aggregations

PendingIntent (android.app.PendingIntent)1243 Intent (android.content.Intent)1043 Notification (android.app.Notification)233 NotificationCompat (android.support.v4.app.NotificationCompat)184 NotificationManager (android.app.NotificationManager)160 AlarmManager (android.app.AlarmManager)153 Bundle (android.os.Bundle)78 RemoteViews (android.widget.RemoteViews)67 RemoteException (android.os.RemoteException)64 Resources (android.content.res.Resources)63 Bitmap (android.graphics.Bitmap)62 Context (android.content.Context)59 ComponentName (android.content.ComponentName)56 Uri (android.net.Uri)45 Test (org.junit.Test)44 IntentFilter (android.content.IntentFilter)43 SharedPreferences (android.content.SharedPreferences)38 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)34 UserHandle (android.os.UserHandle)31 IOException (java.io.IOException)30