Search in sources :

Example 31 with CanceledException

use of android.app.PendingIntent.CanceledException in project robolectric by robolectric.

the class ShadowUsageStatsManager method triggerRegisteredAppUsageObserver.

/**
 * Triggers a currently registered {@link AppUsageObserver} with {@code observerId}.
 *
 * <p>The observer will be no longer registered afterwards.
 */
public void triggerRegisteredAppUsageObserver(int observerId, long timeUsedInMillis) {
    AppUsageObserver observer = appUsageObserversById.remove(observerId);
    long timeLimitInMillis = observer.getTimeUnit().toMillis(observer.getTimeLimit());
    Intent intent = new Intent().putExtra(UsageStatsManager.EXTRA_OBSERVER_ID, observerId).putExtra(UsageStatsManager.EXTRA_TIME_LIMIT, timeLimitInMillis).putExtra(UsageStatsManager.EXTRA_TIME_USED, timeUsedInMillis);
    try {
        observer.getCallbackIntent().send(RuntimeEnvironment.getApplication(), 0, intent);
    } catch (CanceledException e) {
        throw new RuntimeException(e);
    }
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 32 with CanceledException

use of android.app.PendingIntent.CanceledException in project robolectric by robolectric.

the class ShadowUsageStatsManager method triggerRegisteredSessionStepObserver.

/**
 * Triggers a currently registered {@link UsageSessionObserver} with {@code observerId}.
 *
 * <p>The observer SHOULD be registered afterwards.
 */
public void triggerRegisteredSessionStepObserver(int observerId, long timeUsedInMillis) {
    UsageSessionObserver observer = usageSessionObserversById.get(observerId);
    long sessionStepTimeInMillis = observer.getSessionStepDuration().toMillis();
    Intent intent = new Intent().putExtra(UsageStatsManager.EXTRA_OBSERVER_ID, observerId).putExtra(UsageStatsManager.EXTRA_TIME_LIMIT, sessionStepTimeInMillis).putExtra(UsageStatsManager.EXTRA_TIME_USED, timeUsedInMillis);
    try {
        observer.getSessionStepTriggeredIntent().send(RuntimeEnvironment.getApplication(), 0, intent);
    } catch (CanceledException e) {
        throw new RuntimeException(e);
    }
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 33 with CanceledException

use of android.app.PendingIntent.CanceledException in project robolectric by robolectric.

the class ShadowUsageStatsManager method triggerRegisteredSessionEndedObserver.

/**
 * Triggers a currently registered {@link UsageSessionObserver} with {@code observerId}.
 *
 * <p>The observer SHOULD be registered afterwards.
 */
public void triggerRegisteredSessionEndedObserver(int observerId) {
    UsageSessionObserver observer = usageSessionObserversById.get(observerId);
    Intent intent = new Intent().putExtra(UsageStatsManager.EXTRA_OBSERVER_ID, observerId);
    try {
        observer.getSessionEndedIntent().send(RuntimeEnvironment.getApplication(), 0, intent);
    } catch (CanceledException e) {
        throw new RuntimeException(e);
    }
}
Also used : CanceledException(android.app.PendingIntent.CanceledException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Aggregations

CanceledException (android.app.PendingIntent.CanceledException)33 PendingIntent (android.app.PendingIntent)26 Intent (android.content.Intent)26 AlertDialog (android.app.AlertDialog)3 Bundle (android.os.Bundle)3 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)3 KeyEvent (android.view.KeyEvent)3 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 AsyncResult (android.os.AsyncResult)2 RecognizerIntent (android.speech.RecognizerIntent)2 SmsMessage (android.telephony.SmsMessage)2 ArrayList (java.util.ArrayList)2 NonNull (android.annotation.NonNull)1 ActivityThread (android.app.ActivityThread)1 FLAG_CANCEL_CURRENT (android.app.PendingIntent.FLAG_CANCEL_CURRENT)1 FLAG_IMMUTABLE (android.app.PendingIntent.FLAG_IMMUTABLE)1 FLAG_NO_CREATE (android.app.PendingIntent.FLAG_NO_CREATE)1 FLAG_ONE_SHOT (android.app.PendingIntent.FLAG_ONE_SHOT)1 FLAG_UPDATE_CURRENT (android.app.PendingIntent.FLAG_UPDATE_CURRENT)1