Search in sources :

Example 51 with PendingIntent

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

the class AlarmImpl method setAlarmAndWait.

@Override
public int setAlarmAndWait(long timeoutMills) throws RemoteException {
    // calculate when device should be waken up
    long atTime = SystemClock.elapsedRealtime() + timeoutMills;
    AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    Intent wakupIntent = new Intent(WakeUpCall.WAKEUP_CALL);
    PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, wakupIntent, 0);
    // set alarm, which will be delivered in form of the wakeupIntent
    am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, atTime, pi);
    Log.d(LOG_TAG, String.format("Alarm set: %d, giving up wake lock", atTime));
    Object lock = WakeUpController.getController().getWakeSync();
    // release wakelock and wait for the lock to be poked from the broadcast receiver
    WakeUpController.getController().getWakeLock().release();
    // does not really matter if device enters suspend before we start waiting on lock
    synchronized (lock) {
        try {
            lock.wait();
        } catch (InterruptedException e) {
        }
    }
    Log.d(LOG_TAG, String.format("Alarm triggered, done waiting"));
    return 0;
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 52 with PendingIntent

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

the class WakeLoopService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // get wakeup interval from intent
    long wakeupInterval = intent.getLongExtra(WAKEUP_INTERNAL, 0);
    long maxLoop = intent.getLongExtra(MAX_LOOP, 0);
    if (wakeupInterval == 0) {
        // stop and error
        Log.e(LOG_TAG, "No wakeup interval specified, not starting the service");
        stopSelf();
        return START_NOT_STICKY;
    }
    FileUtil.get().writeDateToFile(new File(Environment.getExternalStorageDirectory(), "wakeup-loop-start.txt"));
    Log.d(LOG_TAG, String.format("WakeLoop: STARTED interval = %d, total loop = %d", wakeupInterval, maxLoop));
    // calculate when device should be waken up
    long atTime = SystemClock.elapsedRealtime() + wakeupInterval;
    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent wakupIntent = new Intent(WakeUpCall.WAKEUP_CALL).putExtra(WAKEUP_INTERNAL, wakeupInterval).putExtra(MAX_LOOP, maxLoop).putExtra(THIS_LOOP, 0L).putExtra(STOP_CALLBACK, new Messenger(mHandler));
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, wakupIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    // set alarm, which will be delivered in form of the wakeupIntent
    am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, atTime, pi);
    return START_NOT_STICKY;
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Messenger(android.os.Messenger) PendingIntent(android.app.PendingIntent) File(java.io.File)

Example 53 with PendingIntent

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

the class ActivityManagerService method sendIntentSender.

@Override
public int sendIntentSender(IIntentSender target, int code, Intent intent, String resolvedType, IIntentReceiver finishedReceiver, String requiredPermission, Bundle options) {
    if (target instanceof PendingIntentRecord) {
        return ((PendingIntentRecord) target).sendWithResult(code, intent, resolvedType, finishedReceiver, requiredPermission, options);
    } else {
        if (intent == null) {
            // Weird case: someone has given us their own custom IIntentSender, and now
            // they have someone else trying to send to it but of course this isn't
            // really a PendingIntent, so there is no base Intent, and the caller isn't
            // supplying an Intent... but we never want to dispatch a null Intent to
            // a receiver, so um...  let's make something up.
            Slog.wtf(TAG, "Can't use null intent with direct IIntentSender call");
            intent = new Intent(Intent.ACTION_MAIN);
        }
        try {
            target.send(code, intent, resolvedType, null, requiredPermission, options);
        } catch (RemoteException e) {
        }
        // report the finish immediately.
        if (finishedReceiver != null) {
            try {
                finishedReceiver.performReceive(intent, 0, null, null, false, false, UserHandle.getCallingUserId());
            } catch (RemoteException e) {
            }
        }
        return 0;
    }
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Example 54 with PendingIntent

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

the class InputManagerService method showMissingKeyboardLayoutNotification.

// Must be called on handler.
private void showMissingKeyboardLayoutNotification(InputDevice device) {
    if (!mKeyboardLayoutNotificationShown) {
        final Intent intent = new Intent(Settings.ACTION_HARD_KEYBOARD_SETTINGS);
        if (device != null) {
            intent.putExtra(Settings.EXTRA_INPUT_DEVICE_IDENTIFIER, device.getIdentifier());
        }
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        final PendingIntent keyboardLayoutIntent = PendingIntent.getActivityAsUser(mContext, 0, intent, 0, null, UserHandle.CURRENT);
        Resources r = mContext.getResources();
        Notification notification = new Notification.Builder(mContext).setContentTitle(r.getString(R.string.select_keyboard_layout_notification_title)).setContentText(r.getString(R.string.select_keyboard_layout_notification_message)).setContentIntent(keyboardLayoutIntent).setSmallIcon(R.drawable.ic_settings_language).setPriority(Notification.PRIORITY_LOW).setColor(mContext.getColor(com.android.internal.R.color.system_notification_accent_color)).build();
        mNotificationManager.notifyAsUser(null, R.string.select_keyboard_layout_notification_title, notification, UserHandle.ALL);
        mKeyboardLayoutNotificationShown = true;
    }
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Resources(android.content.res.Resources) Notification(android.app.Notification)

Example 55 with PendingIntent

use of android.app.PendingIntent in project plaid by nickbutcher.

the class DesignerNewsStory method getCustomTabIntent.

public static CustomTabsIntent.Builder getCustomTabIntent(@NonNull Context context, @NonNull Story story, @Nullable CustomTabsSession session) {
    Intent upvoteStory = new Intent(context, UpvoteStoryService.class);
    upvoteStory.setAction(UpvoteStoryService.ACTION_UPVOTE);
    upvoteStory.putExtra(UpvoteStoryService.EXTRA_STORY_ID, story.id);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, upvoteStory, 0);
    return new CustomTabsIntent.Builder(session).setToolbarColor(ContextCompat.getColor(context, R.color.designer_news)).setActionButton(ImageUtils.vectorToBitmap(context, R.drawable.ic_upvote_filled_24dp_white), context.getString(R.string.upvote_story), pendingIntent, false).setShowTitle(true).enableUrlBarHiding().addDefaultShareMenuItem();
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

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