类android.app.PendingIntent.CanceledException源码实例Demo

下面列出了怎么用android.app.PendingIntent.CanceledException的API类实例代码及写法,或者点击链接到github查看源代码。

@Test
public void testOnStartShouldSignOutIfConfigurationHasChanged() throws CanceledException, JSONException {
    // Create new configuration to change the hash
    Context context = RuntimeEnvironment.application.getApplicationContext();
    new OAuthClientConfiguration(
            context,
            context.getSharedPreferences(OAuthClientConfiguration.PREFS_NAME, MODE_PRIVATE),
            ConfigurationStreams.getOtherConfiguration()
    );

    doNothing().when(mCancelIntent).send();

    OktaManagementActivity activity = Robolectric.buildActivity(
            OktaManagementActivity.class
    ).newIntent(createStartIntent()).create().start().get();

    assertThat(activity.isFinishing()).isTrue();
}
 
@Test
public void testOnStartShouldCompleteIfStateIsAuthorized() throws CanceledException, JSONException {
    Context context = RuntimeEnvironment.application.getApplicationContext();
    AuthStateManager stateManager = AuthStateManager.getInstance(context);
    stateManager.replace(mAuthState);

    when(mAuthState.isAuthorized()).thenReturn(true);
    doNothing().when(mCompleteIntent).send();

    OktaManagementActivity activity = Robolectric.buildActivity(
            OktaManagementActivity.class,
            createStartIntent()
    ).create().start().get();

    assertThat(activity.isFinishing()).isTrue();
}
 
private void handleAuthorizationComplete() {
    Uri responseUri = getIntent().getData();
    Intent responseData = extractResponseData(responseUri);
    if (responseData == null) {
        Logger.error("Failed to extract OAuth2 response from redirect");
        return;
    }
    responseData.setData(responseUri);

    if (mCompleteIntent != null) {
        Logger.debug("Authorization complete - invoking completion intent");
        try {
            mCompleteIntent.send(this, 0, responseData);
        } catch (CanceledException ex) {
            Logger.error("Failed to send completion intent", ex);
        }
    } else {
        setResult(RESULT_OK, responseData);
    }
}
 
private void handleAuthorizationCanceled() {
    Logger.debug("Authorization flow canceled by user");
    Intent cancelData = AuthorizationException.fromTemplate(
            AuthorizationException.GeneralErrors.USER_CANCELED_AUTH_FLOW,
            null)
            .toIntent();
    if (mCancelIntent != null) {
        try {
            mCancelIntent.send(this, 0, cancelData);
        } catch (CanceledException ex) {
            Logger.error("Failed to send cancel intent", ex);
        }
    } else {
        setResult(RESULT_CANCELED, cancelData);
        Logger.debug("No cancel intent set - will return to previous activity");
    }
}
 
源代码5 项目: 365browser   文件: CustomTabIntentDataProvider.java
/**
 * Triggers the client-defined action when the user clicks a custom menu item.
 * @param menuIndex The index that the menu item is shown in the result of
 *                  {@link #getMenuTitles()}
 */
public void clickMenuItemWithUrl(ChromeActivity activity, int menuIndex, String url) {
    Intent addedIntent = new Intent();
    addedIntent.setData(Uri.parse(url));
    try {
        // Media viewers pass in PendingIntents that contain CHOOSER Intents.  Setting the data
        // in these cases prevents the Intent from firing correctly.
        String title = mMenuEntries.get(menuIndex).first;
        PendingIntent pendingIntent = mMenuEntries.get(menuIndex).second;
        pendingIntent.send(
                activity, 0, isMediaViewer() ? null : addedIntent, mOnFinished, null);
        if (shouldEnableEmbeddedMediaExperience()
                && TextUtils.equals(
                           title, activity.getString(R.string.download_manager_open_with))) {
            RecordUserAction.record("CustomTabsMenuCustomMenuItem.DownloadsUI.OpenWith");
        }
    } catch (CanceledException e) {
        Log.e(TAG, "Custom tab in Chrome failed to send pending intent.");
    }
}
 
源代码6 项目: GPT   文件: ActivityManagerTest.java
/**
 * testGetIntentSender
 */
private void testGetIntentSender() {
    Intent intent = new Intent();
    intent.setClass(this, AnimationAlphaActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this, 100, intent, 0);

    try {
        pi.send();
    } catch (CanceledException e) {
        if (DEBUG) {
            e.printStackTrace();
        }
    }
}
 
源代码7 项目: delion   文件: CustomTabIntentDataProvider.java
/**
 * Triggers the client-defined action when the user clicks a custom menu item.
 * @param menuIndex The index that the menu item is shown in the result of
 *                  {@link #getMenuTitles()}
 */
public void clickMenuItemWithUrl(ChromeActivity activity, int menuIndex, String url) {
    Intent addedIntent = new Intent();
    addedIntent.setData(Uri.parse(url));
    try {
        PendingIntent pendingIntent = mMenuEntries.get(menuIndex).second;
        pendingIntent.send(activity, 0, addedIntent, mOnFinished, null);
    } catch (CanceledException e) {
        Log.e(TAG, "Custom tab in Chrome failed to send pending intent.");
    }
}
 
源代码8 项目: delion   文件: CustomTabIntentDataProvider.java
/**
 * Sends the pending intent for the custom button on toolbar with the given url as data.
 * @param context The context to use for sending the {@link PendingIntent}.
 * @param url The url to attach as additional data to the {@link PendingIntent}.
 */
public void sendButtonPendingIntentWithUrl(Context context, String url) {
    Intent addedIntent = new Intent();
    addedIntent.setData(Uri.parse(url));
    try {
        getCustomButtonOnToolbar().getPendingIntent().send(context, 0, addedIntent, mOnFinished,
                null);
    } catch (CanceledException e) {
        Log.e(TAG, "CanceledException while sending pending intent in custom tab");
    }
}
 
源代码9 项目: delion   文件: CustomTabBottomBarDelegate.java
private static void sendPendingIntentWithUrl(PendingIntent pendingIntent, Intent extraIntent,
        ChromeActivity activity) {
    Intent addedIntent = extraIntent == null ? new Intent() : new Intent(extraIntent);
    Tab tab = activity.getActivityTab();
    if (tab != null) addedIntent.setData(Uri.parse(tab.getUrl()));
    try {
        pendingIntent.send(activity, 0, addedIntent, null, null);
    } catch (CanceledException e) {
        Log.e(TAG, "CanceledException when sending pending intent.");
    }
}
 
/**
 * Triggers the client-defined action when the user clicks a custom menu item.
 * @param menuIndex The index that the menu item is shown in the result of
 *                  {@link #getMenuTitles()}
 */
public void clickMenuItemWithUrl(ChromeActivity activity, int menuIndex, String url) {
    Intent addedIntent = new Intent();
    addedIntent.setData(Uri.parse(url));
    try {
        // Media viewers pass in PendingIntents that contain CHOOSER Intents.  Setting the data
        // in these cases prevents the Intent from firing correctly.
        PendingIntent pendingIntent = mMenuEntries.get(menuIndex).second;
        pendingIntent.send(
                activity, 0, isMediaViewer() ? null : addedIntent, mOnFinished, null);
    } catch (CanceledException e) {
        Log.e(TAG, "Custom tab in Chrome failed to send pending intent.");
    }
}
 
/**
 * Sends the pending intent for the custom button on toolbar with the given url as data.
 * @param context The context to use for sending the {@link PendingIntent}.
 * @param url The url to attach as additional data to the {@link PendingIntent}.
 */
public void sendButtonPendingIntentWithUrl(Context context, String url) {
    Intent addedIntent = new Intent();
    addedIntent.setData(Uri.parse(url));
    try {
        getCustomButtonOnToolbar().getPendingIntent().send(context, 0, addedIntent, mOnFinished,
                null);
    } catch (CanceledException e) {
        Log.e(TAG, "CanceledException while sending pending intent in custom tab");
    }
}
 
private static void sendPendingIntentWithUrl(PendingIntent pendingIntent, Intent extraIntent,
        ChromeActivity activity) {
    Intent addedIntent = extraIntent == null ? new Intent() : new Intent(extraIntent);
    Tab tab = activity.getActivityTab();
    if (tab != null) addedIntent.setData(Uri.parse(tab.getUrl()));
    try {
        pendingIntent.send(activity, 0, addedIntent, null, null);
    } catch (CanceledException e) {
        Log.e(TAG, "CanceledException when sending pending intent.");
    }
}
 
源代码13 项目: BigApp_Discuz_Android   文件: GPSUtils.java
/**
 * <p>
 * GPS开关
 * <p>
 * 当前若关则打开
 * <p>
 * 当前若开则关闭
 */
public static void toggleGPS(Context context) {
	Intent gpsIntent = new Intent();
	gpsIntent.setClassName("com.android.settings",
			"com.android.settings.widget.SettingsAppWidgetProvider");
	gpsIntent.addCategory("android.intent.category.ALTERNATIVE");
	gpsIntent.setData(Uri.parse("custom:3"));
	try {
		PendingIntent.getBroadcast(context, 0, gpsIntent, 0).send();
	} catch (CanceledException e) {
		e.printStackTrace();
	}
}
 
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    BrowserActionItem menuItem = mMenuItems.get(position);
    if (menuItem.getAction() != null) {
        try {
            menuItem.getAction().send();
        } catch (CanceledException e) {
            Log.e(TAG, "Failed to send custom item action", e);
        }
    } else if (menuItem.getRunnableAction() != null) {
        menuItem.getRunnableAction().run();
    }
    mBrowserActionsDialog.dismiss();
}
 
源代码15 项目: 365browser   文件: CustomTabIntentDataProvider.java
/**
 * Sends the pending intent for the custom button on toolbar with the given url as data.
 * @param context The context to use for sending the {@link PendingIntent}.
 * @param url The url to attach as additional data to the {@link PendingIntent}.
 */
public void sendButtonPendingIntentWithUrl(Context context, String url) {
    Intent addedIntent = new Intent();
    addedIntent.setData(Uri.parse(url));
    try {
        getCustomButtonOnToolbar().getPendingIntent().send(context, 0, addedIntent, mOnFinished,
                null);
    } catch (CanceledException e) {
        Log.e(TAG, "CanceledException while sending pending intent in custom tab");
    }
}
 
源代码16 项目: 365browser   文件: CustomTabBottomBarDelegate.java
private static void sendPendingIntentWithUrl(PendingIntent pendingIntent, Intent extraIntent,
        ChromeActivity activity) {
    Intent addedIntent = extraIntent == null ? new Intent() : new Intent(extraIntent);
    Tab tab = activity.getActivityTab();
    if (tab != null) addedIntent.setData(Uri.parse(tab.getUrl()));
    try {
        pendingIntent.send(activity, 0, addedIntent, null, null);
    } catch (CanceledException e) {
        Log.e(TAG, "CanceledException when sending pending intent.");
    }
}
 
/**
 * Called when a custom item of Browser action menu is selected.
 * @param action The PendingIntent action to be launched.
 */
public void onCustomItemSelected(PendingIntent action) {
    try {
        action.send();
    } catch (CanceledException e) {
        Log.e(TAG, "Browser Action in Chrome failed to send pending intent.");
    }
}
 
源代码18 项目: 365browser   文件: AndroidListenerIntents.java
/**
 * Given an authorization token request intent and authorization information ({@code authToken}
 * and {@code authType}) issues a response.
 */
static void issueAuthTokenResponse(Context context, PendingIntent pendingIntent, String authToken,
    String authType) {
  Intent responseIntent = new Intent()
      .putExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN, authToken)
      .putExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN_TYPE, authType);
  try {
    pendingIntent.send(context, 0, responseIntent);
  } catch (CanceledException exception) {
    logger.warning("Canceled auth request: %s", exception);
  }
}
 
源代码19 项目: android-picturepassword   文件: SetupIntro.java
private void saveData()
{
	if ( !PicturePasswordUtils.saveUnlockData( this, mBitmap, mGridSize, mRandomize, mChosenNumber, mUnlockPosition ) )
	{
		// uh oh
		finish();
	}
	else
	{
		PendingIntent requestedIntent = getIntent().getParcelableExtra( "PendingIntent" );
		
		boolean ok = false;
		if ( requestedIntent != null )
		{
			try
			{
				requestedIntent.send();
				ok = true;
			}
			catch ( CanceledException e )
			{
				ok = false;
			}
		}
		else
		{
			Log.e( "PicturePassword", "PendingIntent was null or canceled! This is probably bad!" );
			Intent chooseIntent = new Intent();
			chooseIntent.setClassName( "com.android.settings", "com.android.settings.ChooseLockGeneric" );
			chooseIntent.putExtra( "lockscreen.biometric_weak_fallback", true );
			startActivity( chooseIntent );
		}
		finish();
	}
}
 
源代码20 项目: PressureNet   文件: WidgetProvider.java
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
	mContext = context;
	RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.small_widget_layout);
	Intent intent = new Intent(context, WidgetButtonService.class);
	intent.putExtra("msg", mReading + "");
	intent.putExtra("widget", "yes");
	intent.setAction(ACTION_UPDATEUI);
	
	Intent clickIntent = new Intent(context, BarometerNetworkActivity.class);
	PendingIntent clickPI = PendingIntent.getActivity(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
	remoteViews.setOnClickPendingIntent(R.id.widgetSmallText, clickPI);
	remoteViews.setOnClickPendingIntent(R.id.widget_tendency_image_down, clickPI);
	remoteViews.setOnClickPendingIntent(R.id.widget_tendency_image_steady, clickPI);
	remoteViews.setOnClickPendingIntent(R.id.widget_tendency_image_up, clickPI);
	
	PendingIntent actionPendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
	
	remoteViews.setOnClickPendingIntent(R.id.widgetSmallSubmitButton, actionPendingIntent);
	
	try {
		actionPendingIntent.send();
	} catch(CanceledException ce) {
		//log(ce.getMessage());
	}
	
	appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
	
	super.onUpdate(context, appWidgetManager, appWidgetIds);
}
 
源代码21 项目: codeexamples-android   文件: IntentActivityFlags.java
public void onClick(View v) {
    Context context = IntentActivityFlags.this;

    PendingIntent pi = PendingIntent.getActivities(context, 0,
            buildIntentsToViewsLists(), PendingIntent.FLAG_UPDATE_CURRENT);

    try {
        pi.send();
    } catch (CanceledException e) {
        Log.w("IntentActivityFlags", "Failed sending PendingIntent", e);
    }
}
 
源代码22 项目: android-chromium   文件: AndroidListenerIntents.java
/**
 * Given an authorization token request intent and authorization information ({@code authToken}
 * and {@code authType}) issues a response.
 */
static void issueAuthTokenResponse(Context context, PendingIntent pendingIntent, String authToken,
    String authType) {
  Intent responseIntent = new Intent()
      .putExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN, authToken)
      .putExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN_TYPE, authType);
  try {
    pendingIntent.send(context, 0, responseIntent);
  } catch (CanceledException exception) {
    logger.warning("Canceled auth request: %s", exception);
  }
}
 
源代码23 项目: android-chromium   文件: AndroidListenerIntents.java
/**
 * Given an authorization token request intent and authorization information ({@code authToken}
 * and {@code authType}) issues a response.
 */
static void issueAuthTokenResponse(Context context, PendingIntent pendingIntent, String authToken,
    String authType) {
  Intent responseIntent = new Intent()
      .putExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN, authToken)
      .putExtra(AuthTokenConstants.EXTRA_AUTH_TOKEN_TYPE, authType);
  try {
    pendingIntent.send(context, 0, responseIntent);
  } catch (CanceledException exception) {
    logger.warning("Canceled auth request: %s", exception);
  }
}
 
源代码24 项目: BarcodeEye   文件: ResultsActivity.java
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
        long id) {
    CardPresenter cardPresenter = mCardPresenters.get(position);
    PendingIntent pendingIntent = cardPresenter.getPendingIntent();
    if (pendingIntent != null) {
        try {
            pendingIntent.send();
        } catch (CanceledException e) {
            Log.w(TAG, e.getMessage());
        }
    } else {
        Log.w(TAG, "No PendingIntent attached to card!");
    }
}
 
private void finish(int startId, PendingIntent pendingIntent, int result) {
	if (pendingIntent != null) {
		try {
			pendingIntent.send(result);
		} catch (CanceledException e) {
			// Ignore this. If they don't want their result, they don't get it.
		}
	}
	this.stopSelfResult(startId);
}
 
 类所在包
 类方法
 同包方法