Search in sources :

Example 46 with PendingIntent

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

the class StorageNotification method buildForgetPendingIntent.

private PendingIntent buildForgetPendingIntent(VolumeRecord rec) {
    final Intent intent = new Intent();
    intent.setClassName("com.android.settings", "com.android.settings.Settings$PrivateVolumeForgetActivity");
    intent.putExtra(VolumeRecord.EXTRA_FS_UUID, rec.getFsUuid());
    final int requestKey = rec.getFsUuid().hashCode();
    return PendingIntent.getActivityAsUser(mContext, requestKey, intent, PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 47 with PendingIntent

use of android.app.PendingIntent in project Conversations by siacs.

the class PgpDecryptionService method executeApi.

private void executeApi(Message message) {
    synchronized (message) {
        Intent params = new Intent();
        params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
        if (message.getType() == Message.TYPE_TEXT) {
            InputStream is = new ByteArrayInputStream(message.getBody().getBytes());
            final OutputStream os = new ByteArrayOutputStream();
            Intent result = getOpenPgpApi().executeApi(params, is, os);
            switch(result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
                case OpenPgpApi.RESULT_CODE_SUCCESS:
                    try {
                        os.flush();
                        final String body = os.toString();
                        if (body == null) {
                            throw new IOException("body was null");
                        }
                        message.setBody(body);
                        message.setEncryption(Message.ENCRYPTION_DECRYPTED);
                        final HttpConnectionManager manager = mXmppConnectionService.getHttpConnectionManager();
                        if (message.trusted() && message.treatAsDownloadable() != Message.Decision.NEVER && manager.getAutoAcceptFileSize() > 0) {
                            manager.createNewDownloadConnection(message);
                        }
                    } catch (IOException e) {
                        message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
                    }
                    mXmppConnectionService.updateMessage(message);
                    break;
                case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
                    synchronized (PgpDecryptionService.this) {
                        PendingIntent pendingIntent = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
                        messages.addFirst(message);
                        currentMessage = null;
                        storePendingIntent(pendingIntent);
                    }
                    break;
                case OpenPgpApi.RESULT_CODE_ERROR:
                    message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
                    mXmppConnectionService.updateMessage(message);
                    break;
            }
        } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
            try {
                final DownloadableFile inputFile = mXmppConnectionService.getFileBackend().getFile(message, false);
                final DownloadableFile outputFile = mXmppConnectionService.getFileBackend().getFile(message, true);
                outputFile.getParentFile().mkdirs();
                outputFile.createNewFile();
                InputStream is = new FileInputStream(inputFile);
                OutputStream os = new FileOutputStream(outputFile);
                Intent result = getOpenPgpApi().executeApi(params, is, os);
                switch(result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
                    case OpenPgpApi.RESULT_CODE_SUCCESS:
                        URL url = message.getFileParams().url;
                        mXmppConnectionService.getFileBackend().updateFileParams(message, url);
                        message.setEncryption(Message.ENCRYPTION_DECRYPTED);
                        inputFile.delete();
                        mXmppConnectionService.getFileBackend().updateMediaScanner(outputFile);
                        mXmppConnectionService.updateMessage(message);
                        break;
                    case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
                        synchronized (PgpDecryptionService.this) {
                            PendingIntent pendingIntent = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
                            messages.addFirst(message);
                            currentMessage = null;
                            storePendingIntent(pendingIntent);
                        }
                        break;
                    case OpenPgpApi.RESULT_CODE_ERROR:
                        message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
                        mXmppConnectionService.updateMessage(message);
                        break;
                }
            } catch (final IOException e) {
                message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
                mXmppConnectionService.updateMessage(message);
            }
        }
    }
    notifyIfPending(message);
}
Also used : FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) URL(java.net.URL) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) HttpConnectionManager(eu.siacs.conversations.http.HttpConnectionManager) PendingIntent(android.app.PendingIntent) DownloadableFile(eu.siacs.conversations.entities.DownloadableFile)

Example 48 with PendingIntent

use of android.app.PendingIntent in project simplefacebook by androidquery.

the class PostActivity method notify.

private void notify(String ticker, String title, String message, Intent intent) {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    int icon = R.drawable.launcher;
    long when = System.currentTimeMillis();
    Notification notification = new Notification(icon, ticker, when);
    Context context = getApplicationContext();
    CharSequence contentText = message;
    int id = getNotifyId();
    PendingIntent contentIntent = PendingIntent.getActivity(this, id, intent, 0);
    notification.setLatestEventInfo(context, title, contentText, contentIntent);
    mNotificationManager.cancelAll();
    AQUtility.debug("notify id", id);
    mNotificationManager.notify(id, notification);
}
Also used : Context(android.content.Context) NotificationManager(android.app.NotificationManager) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 49 with PendingIntent

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

the class NotificationBuilderTest method makeContentIntent.

private PendingIntent makeContentIntent(int id) {
    Intent intent = new Intent(this, ConfirmationActivity.class);
    intent.setData(Uri.fromParts("content", "//status_bar_test/content/" + id, null));
    intent.putExtra(ConfirmationActivity.EXTRA_TITLE, "Content intent");
    intent.putExtra(ConfirmationActivity.EXTRA_TEXT, "id: " + id);
    return PendingIntent.getActivity(this, 0, intent, 0);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 50 with PendingIntent

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

the class ConnectivityServiceTest method testNetworkRequestMaximum.

@SmallTest
public void testNetworkRequestMaximum() {
    final int MAX_REQUESTS = 100;
    // Test that the limit is enforced when MAX_REQUESTS simultaneous requests are added.
    NetworkRequest networkRequest = new NetworkRequest.Builder().build();
    ArrayList<NetworkCallback> networkCallbacks = new ArrayList<NetworkCallback>();
    try {
        for (int i = 0; i < MAX_REQUESTS; i++) {
            NetworkCallback networkCallback = new NetworkCallback();
            mCm.requestNetwork(networkRequest, networkCallback);
            networkCallbacks.add(networkCallback);
        }
        fail("Registering " + MAX_REQUESTS + " NetworkRequests did not throw exception");
    } catch (IllegalArgumentException expected) {
    }
    for (NetworkCallback networkCallback : networkCallbacks) {
        mCm.unregisterNetworkCallback(networkCallback);
    }
    networkCallbacks.clear();
    try {
        for (int i = 0; i < MAX_REQUESTS; i++) {
            NetworkCallback networkCallback = new NetworkCallback();
            mCm.registerNetworkCallback(networkRequest, networkCallback);
            networkCallbacks.add(networkCallback);
        }
        fail("Registering " + MAX_REQUESTS + " NetworkCallbacks did not throw exception");
    } catch (IllegalArgumentException expected) {
    }
    for (NetworkCallback networkCallback : networkCallbacks) {
        mCm.unregisterNetworkCallback(networkCallback);
    }
    networkCallbacks.clear();
    ArrayList<PendingIntent> pendingIntents = new ArrayList<PendingIntent>();
    try {
        for (int i = 0; i < MAX_REQUESTS + 1; i++) {
            PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, new Intent("a" + i), 0);
            mCm.requestNetwork(networkRequest, pendingIntent);
            pendingIntents.add(pendingIntent);
        }
        fail("Registering " + MAX_REQUESTS + " PendingIntent NetworkRequests did not throw exception");
    } catch (IllegalArgumentException expected) {
    }
    for (PendingIntent pendingIntent : pendingIntents) {
        mCm.unregisterNetworkCallback(pendingIntent);
    }
    pendingIntents.clear();
    try {
        for (int i = 0; i < MAX_REQUESTS + 1; i++) {
            PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, new Intent("a" + i), 0);
            mCm.registerNetworkCallback(networkRequest, pendingIntent);
            pendingIntents.add(pendingIntent);
        }
        fail("Registering " + MAX_REQUESTS + " PendingIntent NetworkCallbacks did not throw exception");
    } catch (IllegalArgumentException expected) {
    }
    for (PendingIntent pendingIntent : pendingIntents) {
        mCm.unregisterNetworkCallback(pendingIntent);
    }
    pendingIntents.clear();
    mService.waitForIdle(5000);
    // Test that the limit is not hit when MAX_REQUESTS requests are added and removed.
    for (int i = 0; i < MAX_REQUESTS; i++) {
        NetworkCallback networkCallback = new NetworkCallback();
        mCm.requestNetwork(networkRequest, networkCallback);
        mCm.unregisterNetworkCallback(networkCallback);
    }
    mService.waitForIdle();
    for (int i = 0; i < MAX_REQUESTS; i++) {
        NetworkCallback networkCallback = new NetworkCallback();
        mCm.registerNetworkCallback(networkRequest, networkCallback);
        mCm.unregisterNetworkCallback(networkCallback);
    }
    mService.waitForIdle();
    for (int i = 0; i < MAX_REQUESTS; i++) {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, new Intent("b" + i), 0);
        mCm.requestNetwork(networkRequest, pendingIntent);
        mCm.unregisterNetworkCallback(pendingIntent);
    }
    mService.waitForIdle();
    for (int i = 0; i < MAX_REQUESTS; i++) {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, new Intent("c" + i), 0);
        mCm.registerNetworkCallback(networkRequest, pendingIntent);
        mCm.unregisterNetworkCallback(pendingIntent);
    }
}
Also used : NetworkRequest(android.net.NetworkRequest) ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) NetworkCallback(android.net.ConnectivityManager.NetworkCallback) SmallTest(android.test.suitebuilder.annotation.SmallTest)

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