Search in sources :

Example 31 with PendingIntent

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

the class BaseStatusBar method startPendingIntentDismissingKeyguard.

public void startPendingIntentDismissingKeyguard(final PendingIntent intent) {
    if (!isDeviceProvisioned())
        return;
    final boolean keyguardShowing = mStatusBarKeyguardViewManager.isShowing();
    final boolean afterKeyguardGone = intent.isActivity() && PreviewInflater.wouldLaunchResolverActivity(mContext, intent.getIntent(), mCurrentUserId);
    dismissKeyguardThenExecute(new OnDismissAction() {

        public boolean onDismiss() {
            new Thread() {

                @Override
                public void run() {
                    try {
                        if (keyguardShowing && !afterKeyguardGone) {
                            ActivityManagerNative.getDefault().keyguardWaitingForActivityDrawn();
                        }
                        // The intent we are sending is for the application, which
                        // won't have permission to immediately start an activity after
                        // the user switches to home.  We know it is safe to do at this
                        // point, so make sure new activity switches are now allowed.
                        ActivityManagerNative.getDefault().resumeAppSwitches();
                    } catch (RemoteException e) {
                    }
                    try {
                        intent.send(null, 0, null, null, null, null, getActivityOptions());
                    } catch (PendingIntent.CanceledException e) {
                        // the stack trace isn't very helpful here.
                        // Just log the exception message.
                        Log.w(TAG, "Sending intent failed: " + e);
                    // TODO: Dismiss Keyguard.
                    }
                    if (intent.isActivity()) {
                        mAssistManager.hideAssist();
                        overrideActivityPendingAppTransition(keyguardShowing && !afterKeyguardGone);
                    }
                }
            }.start();
            // close the shade if it was open
            animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, true, /* force */
            true);
            visibilityChanged(false);
            return true;
        }
    }, afterKeyguardGone);
}
Also used : OnDismissAction(com.android.keyguard.KeyguardHostView.OnDismissAction) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException)

Example 32 with PendingIntent

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

the class GlobalScreenshot method doInBackground.

@Override
protected Void doInBackground(Void... params) {
    if (isCancelled()) {
        return null;
    }
    // By default, AsyncTask sets the worker thread to have background thread priority, so bump
    // it back up so that we save a little quicker.
    Process.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND);
    Context context = mParams.context;
    Bitmap image = mParams.image;
    Resources r = context.getResources();
    try {
        // Create screenshot directory if it doesn't exist
        mScreenshotDir.mkdirs();
        // media provider uses seconds for DATE_MODIFIED and DATE_ADDED, but milliseconds
        // for DATE_TAKEN
        long dateSeconds = mImageTime / 1000;
        // Save
        OutputStream out = new FileOutputStream(mImageFilePath);
        image.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
        // Save the screenshot to the MediaStore
        ContentValues values = new ContentValues();
        ContentResolver resolver = context.getContentResolver();
        values.put(MediaStore.Images.ImageColumns.DATA, mImageFilePath);
        values.put(MediaStore.Images.ImageColumns.TITLE, mImageFileName);
        values.put(MediaStore.Images.ImageColumns.DISPLAY_NAME, mImageFileName);
        values.put(MediaStore.Images.ImageColumns.DATE_TAKEN, mImageTime);
        values.put(MediaStore.Images.ImageColumns.DATE_ADDED, dateSeconds);
        values.put(MediaStore.Images.ImageColumns.DATE_MODIFIED, dateSeconds);
        values.put(MediaStore.Images.ImageColumns.MIME_TYPE, "image/png");
        values.put(MediaStore.Images.ImageColumns.WIDTH, mImageWidth);
        values.put(MediaStore.Images.ImageColumns.HEIGHT, mImageHeight);
        values.put(MediaStore.Images.ImageColumns.SIZE, new File(mImageFilePath).length());
        Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        // Create a share intent
        String subjectDate = DateFormat.getDateTimeInstance().format(new Date(mImageTime));
        String subject = String.format(SCREENSHOT_SHARE_SUBJECT_TEMPLATE, subjectDate);
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("image/png");
        sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        // Create a share action for the notification
        PendingIntent chooseAction = PendingIntent.getBroadcast(context, 0, new Intent(context, GlobalScreenshot.TargetChosenReceiver.class), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        Intent chooserIntent = Intent.createChooser(sharingIntent, null, chooseAction.getIntentSender()).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent shareAction = PendingIntent.getActivity(context, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        Notification.Action.Builder shareActionBuilder = new Notification.Action.Builder(R.drawable.ic_screenshot_share, r.getString(com.android.internal.R.string.share), shareAction);
        mNotificationBuilder.addAction(shareActionBuilder.build());
        // Create a delete action for the notification
        PendingIntent deleteAction = PendingIntent.getBroadcast(context, 0, new Intent(context, GlobalScreenshot.DeleteScreenshotReceiver.class).putExtra(GlobalScreenshot.SCREENSHOT_URI_ID, uri.toString()), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        Notification.Action.Builder deleteActionBuilder = new Notification.Action.Builder(R.drawable.ic_screenshot_delete, r.getString(com.android.internal.R.string.delete), deleteAction);
        mNotificationBuilder.addAction(deleteActionBuilder.build());
        mParams.imageUri = uri;
        mParams.image = null;
        mParams.errorMsgResId = 0;
    } catch (Exception e) {
        // IOException/UnsupportedOperationException may be thrown if external storage is not
        // mounted
        mParams.clearImage();
        mParams.errorMsgResId = R.string.screenshot_failed_to_save_text;
    }
    // Recycle the bitmap data
    if (image != null) {
        image.recycle();
    }
    return null;
}
Also used : Context(android.content.Context) ContentValues(android.content.ContentValues) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Uri(android.net.Uri) Date(java.util.Date) Notification(android.app.Notification) ContentResolver(android.content.ContentResolver) Bitmap(android.graphics.Bitmap) FileOutputStream(java.io.FileOutputStream) Resources(android.content.res.Resources) PendingIntent(android.app.PendingIntent) File(java.io.File)

Example 33 with PendingIntent

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

the class UserSwitcherController method showGuestNotification.

private void showGuestNotification(int guestUserId) {
    boolean canSwitchUsers = mUserManager.canSwitchUsers();
    // Disable 'Remove guest' action if cannot switch users right now
    PendingIntent removeGuestPI = canSwitchUsers ? PendingIntent.getBroadcastAsUser(mContext, 0, new Intent(ACTION_REMOVE_GUEST), 0, UserHandle.SYSTEM) : null;
    Notification.Builder builder = new Notification.Builder(mContext).setVisibility(Notification.VISIBILITY_SECRET).setPriority(Notification.PRIORITY_MIN).setSmallIcon(R.drawable.ic_person).setContentTitle(mContext.getString(R.string.guest_notification_title)).setContentText(mContext.getString(R.string.guest_notification_text)).setContentIntent(removeGuestPI).setShowWhen(false).addAction(R.drawable.ic_delete, mContext.getString(R.string.guest_notification_remove_action), removeGuestPI);
    SystemUI.overrideNotificationAppName(mContext, builder);
    NotificationManager.from(mContext).notifyAsUser(TAG_REMOVE_GUEST, ID_REMOVE_GUEST, builder.build(), new UserHandle(guestUserId));
}
Also used : UserHandle(android.os.UserHandle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 34 with PendingIntent

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

the class MediaSessionService method rememberMediaButtonReceiverLocked.

private void rememberMediaButtonReceiverLocked(MediaSessionRecord record) {
    PendingIntent receiver = record.getMediaButtonReceiver();
    UserRecord user = mUserRecords.get(record.getUserId());
    if (receiver != null && user != null) {
        user.mLastMediaButtonReceiver = receiver;
        ComponentName component = receiver.getIntent().getComponent();
        if (component != null && record.getPackageName().equals(component.getPackageName())) {
            Settings.Secure.putStringForUser(mContentResolver, Settings.System.MEDIA_BUTTON_RECEIVER, component.flattenToString(), record.getUserId());
        }
    }
}
Also used : ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent)

Example 35 with PendingIntent

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

the class GeofenceManager method sendIntentEnter.

private void sendIntentEnter(PendingIntent pendingIntent) {
    if (D) {
        Slog.d(TAG, "sendIntentEnter: pendingIntent=" + pendingIntent);
    }
    Intent intent = new Intent();
    intent.putExtra(LocationManager.KEY_PROXIMITY_ENTERING, true);
    sendIntent(pendingIntent, intent);
}
Also used : 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