List of usage examples for android.content ActivityNotFoundException ActivityNotFoundException
public ActivityNotFoundException()
From source file:org.alfresco.mobile.android.application.managers.ActionUtils.java
public static void actionView(FragmentActivity context, File myFile, String mimeType, ActionManagerListener listener) { Intent intent = new Intent(Intent.ACTION_VIEW); Uri data = Uri.fromFile(myFile);//from w ww . ja v a 2s . co m intent.setDataAndType(data, mimeType.toLowerCase()); try { if (intent.resolveActivity(context.getPackageManager()) == null) { if (listener != null) { throw new ActivityNotFoundException(); } AlfrescoNotificationManager.getInstance(context).showAlertCrouton(context, context.getString(R.string.feature_disable)); return; } context.startActivity(intent); } catch (ActivityNotFoundException e) { if (listener != null) { listener.onActivityNotFoundException(e); } } }
From source file:com.ruesga.rview.misc.ActivityHelper.java
@SuppressWarnings("Convert2streamapi") public static void openUri(Context ctx, Uri uri, boolean excludeRview) { try {/*from w w w . j a va 2s. c o m*/ Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.putExtra(Constants.EXTRA_FORCE_SINGLE_PANEL, true); intent.putExtra(Constants.EXTRA_SOURCE, ctx.getPackageName()); if (excludeRview) { // Use a different url to find all the browsers activities Intent test = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.es")); PackageManager pm = ctx.getPackageManager(); List<ResolveInfo> activities = pm.queryIntentActivities(test, PackageManager.MATCH_DEFAULT_ONLY); List<Intent> targetIntents = new ArrayList<>(); for (ResolveInfo ri : activities) { if (!ri.activityInfo.packageName.equals(ctx.getPackageName())) { Intent i = new Intent(Intent.ACTION_VIEW, uri); i.setPackage(ri.activityInfo.packageName); i.putExtra(Constants.EXTRA_SOURCE, ctx.getPackageName()); i.putExtra(Constants.EXTRA_FORCE_SINGLE_PANEL, true); targetIntents.add(i); } } if (targetIntents.size() == 0) { throw new ActivityNotFoundException(); } else if (targetIntents.size() == 1) { ctx.startActivity(targetIntents.get(0)); } else { Intent chooserIntent = Intent.createChooser(intent, ctx.getString(R.string.action_open_with)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetIntents.toArray(new Parcelable[] {})); ctx.startActivity(chooserIntent); } } else { ctx.startActivity(intent); } } catch (ActivityNotFoundException ex) { // Fallback to default browser String msg = ctx.getString(R.string.exception_browser_not_found, uri.toString()); Toast.makeText(ctx, msg, Toast.LENGTH_SHORT).show(); } }
From source file:com.gh4a.activities.FileViewerActivity.java
private void openUnsuitableFileAndFinish() { String url = String.format(Locale.US, RAW_URL_FORMAT, mRepoOwner, mRepoName, mRef, mPath); String mime = FileUtils.getMimeTypeFor(FileUtils.getFileName(mPath)); Intent intent = IntentUtils.createViewerOrBrowserIntent(this, Uri.parse(url), mime); if (intent == null) { handleLoadFailure(new ActivityNotFoundException()); findViewById(R.id.retry_button).setVisibility(View.GONE); } else {//from w w w . j av a 2 s . c om startActivity(intent); finish(); } }
From source file:net.openid.appauth.AuthorizationService.java
/** * Sends an authorization request to the authorization service, using a * [custom tab](https://developer.chrome.com/multidevice/android/customtabs). * The parameters of this request are determined by both the authorization service * configuration and the provided {@link AuthorizationRequest request object}. Upon completion * of this request, the provided {@link PendingIntent completion PendingIntent} will be invoked. * If the user cancels the authorization request, the provided * {@link PendingIntent cancel PendingIntent} will be invoked. * * @param customTabsIntent//from w w w . ja v a 2 s. c o m * The intent that will be used to start the custom tab. It is recommended that this intent * be created with the help of {@link #createCustomTabsIntentBuilder(Uri[])}, which will * ensure that a warmed-up version of the browser will be used, minimizing latency. * * @throws android.content.ActivityNotFoundException if no suitable browser is available to * perform the authorization flow. */ public void performAuthorizationRequest(@NonNull AuthorizationRequest request, @NonNull PendingIntent completedIntent, @Nullable PendingIntent canceledIntent, @NonNull CustomTabsIntent customTabsIntent) { checkNotDisposed(); if (mBrowser == null) { throw new ActivityNotFoundException(); } Uri requestUri = request.toUri(); Intent intent; if (mBrowser.useCustomTab) { intent = customTabsIntent.intent; } else { intent = new Intent(Intent.ACTION_VIEW); } intent.setPackage(mBrowser.packageName); intent.setData(requestUri); Logger.debug("Using %s as browser for auth, custom tab = %s", intent.getPackage(), mBrowser.useCustomTab.toString()); intent.putExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE); Logger.debug("Initiating authorization request to %s", request.configuration.authorizationEndpoint); mContext.startActivity(AuthorizationManagementActivity.createStartIntent(mContext, request, intent, completedIntent, canceledIntent)); }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachAgent.java
/** * Try to notify the content to the user. * @param content reach content.//from w w w .j a va2 s .com * @param replaySystemNotifications true iff system notifications must be replayed. * @throws RuntimeException if an error occurs. */ private void notifyContent(final CapptainReachContent content, boolean replaySystemNotifications) throws RuntimeException { /* Check expiry */ final long localId = content.getLocalId(); if (content.hasExpired()) { /* Delete */ deleteContent(content); return; } /* If datapush, just broadcast, can be done in parallel with another content */ final Intent intent = content.getIntent(); if (content instanceof CapptainDataPush) { /* If it's a datapush it may already be in the process of broadcasting. */ if (!mPendingDataPushes.add(localId)) return; /* Broadcast intent */ final CapptainDataPush dataPush = (CapptainDataPush) content; intent.setPackage(mContext.getPackageName()); mContext.sendOrderedBroadcast(intent, null, new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { /* The last broadcast receiver to set a defined result wins (to determine which result). */ switch (getResultCode()) { case RESULT_OK: dataPush.actionContent(context); break; case RESULT_CANCELED: dataPush.exitContent(context); break; default: dataPush.dropContent(context); } /* Clean broadcast state */ mPendingDataPushes.remove(localId); } }, null, RESULT_UNDEFINED, null, null); /* Datapush processed */ return; } /* Don't notify in-app if we are already notifying in app or showing a content */ if (mState != State.IDLE && !content.isSystemNotification()) return; /* Don't process again a pending notification */ if (mPendingNotifications.contains(localId)) return; /* Not an interactive content, exit (but there is no other type left, this is just a cast guard) */ if (!(content instanceof CapptainReachInteractiveContent)) return; CapptainReachInteractiveContent iContent = (CapptainReachInteractiveContent) content; /* Don't replay system notification unless told otherwise. */ if (!replaySystemNotifications && iContent.isSystemNotification() && iContent.getNotificationLastDisplayedDate() != null && iContent.getNotificationLastDisplayedDate() > mAppLastUpdateTime) return; /* Check if the content can be notified in the current context (behavior) */ if (!iContent.canNotify(sActivityManager.getCurrentActivityAlias())) return; /* If there is a show intent */ if (intent != null) { /* Filter intent for the target package name */ filterIntent(intent); /* If the intent could not be resolved */ if (intent.getComponent() == null) { /* If there was no category */ if (intent.getCategories() == null) /* Notification cannot be done */ throw new ActivityNotFoundException(); /* Remove categories */ Collection<String> categories = new HashSet<String>(intent.getCategories()); for (String category : categories) intent.removeCategory(category); /* Try filtering again */ filterIntent(intent); /* Notification cannot be done, skip content */ if (intent.getComponent() == null) throw new ActivityNotFoundException(); } } /* Delegate notification */ Boolean notifierResult = getNotifier(content).handleNotification(iContent); /* Check if notifier rejected content notification for now */ if (Boolean.FALSE.equals(notifierResult)) /* The notifier rejected the content, nothing more to do */ return; /* Cache content if accepted, it will most likely be used again soon for the next steps. */ mContentCache.put(localId, content); /* * If notifier did not return null (e.g. returned true, meaning actually accepted the content), * we assume the notification is correctly displayed. */ if (Boolean.TRUE.equals(notifierResult)) { /* Report displayed feedback */ iContent.displayNotification(mContext); /* Track in-app content life cycle: one at a time */ if (!iContent.isSystemNotification()) mState = State.NOTIFYING_IN_APP; } /* Track pending notifications to avoid re-processing them every time we change activity. */ if (notifierResult == null) mPendingNotifications.add(localId); }
From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java
/** * Filter the intent to a single activity so a chooser won't pop up. If not found, it tries to * resolve intent by falling back to default category. * @param intent intent to filter./*from w ww. j ava 2s. co m*/ */ private void filterIntentWithCategory(final Intent intent) { /* Filter intent for the target package name */ filterIntent(intent); /* If the intent could not be resolved */ if (intent.getComponent() == null) { /* If there was no category */ if (intent.getCategories() == null) /* Notification cannot be done */ throw new ActivityNotFoundException(); /* Remove categories */ Collection<String> categories = new HashSet<String>(intent.getCategories()); for (String category : categories) intent.removeCategory(category); /* Try filtering again */ filterIntent(intent); /* Notification cannot be done, skip content */ if (intent.getComponent() == null) throw new ActivityNotFoundException(); } }
From source file:com.klinker.android.launcher.launcher3.Launcher.java
@Override public void startIntentSenderForResult(IntentSender intent, int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) { onStartForResult(requestCode);/*from w ww .j a v a2s . c om*/ try { super.startIntentSenderForResult(intent, requestCode, fillInIntent, flagsMask, flagsValues, extraFlags, options); } catch (IntentSender.SendIntentException e) { throw new ActivityNotFoundException(); } }
From source file:com.android.launcher3.Launcher.java
@Override public void startIntentSenderForResult(IntentSender intent, int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) { try {//w ww. j a v a 2s.co m super.startIntentSenderForResult(intent, requestCode, fillInIntent, flagsMask, flagsValues, extraFlags, options); } catch (IntentSender.SendIntentException e) { throw new ActivityNotFoundException(); } }