List of usage examples for android.content Intent parseUri
public static Intent parseUri(String uri, @UriFlags int flags) throws URISyntaxException
From source file:RhodesService.java
/** Opens remote or local URL * @throws URISyntaxException, ActivityNotFoundException */ public static void openExternalUrl(String url) throws URISyntaxException, ActivityNotFoundException { // try // {/*from ww w. j a va 2s . c o m*/ if (url.charAt(0) == '/') url = "file://" + RhoFileApi.absolutePath(url); //FIXME: Use common URI handling Context ctx = RhodesService.getContext(); LocalFileHandler fileHandler = new LocalFileHandler(ctx); if (!fileHandler.handle(url)) { Logger.D(TAG, "Handling URI: " + url); Intent intent = Intent.parseUri(url, 0); ctx.startActivity(Intent.createChooser(intent, "Open in...")); } // } // catch (Exception e) { // Logger.E(TAG, "Can't open url :'" + url + "': " + e.getMessage()); // } }
From source file:org.restcomm.android.sdk.RCDevice.java
void onNotificationIntent(Intent intent) { String intentAction = intent.getAction(); //if (!intentAction.equals(ACTION_NOTIFICATION_MESSAGE_DEFAULT)) { if (intentAction.equals(ACTION_NOTIFICATION_CALL_DEFAULT) || intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_VIDEO) || intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_AUDIO) || intentAction.equals(ACTION_NOTIFICATION_CALL_DECLINE) || intentAction.equals(ACTION_NOTIFICATION_CALL_DELETE)) { // The user has acted on a call notification, let's cancel it String username = intent.getStringExtra(EXTRA_DID).replaceAll(".*?sip:", "").replaceAll("@.*$", ""); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(callNotifications.get(username)); //callNotifications.remove(username); activeCallNotification = false;//from w w w. j a va 2s . c o m } Intent actionIntent = null; /* if (intentAction.equals(ACTION_NOTIFICATION_CALL_OPEN)) { RCConnection connection = getLiveConnection(); if (connection != null) { if (connection.isIncoming()) { callIntent.setAction(ACTION_INCOMING_CALL); } else { callIntent.setAction(ACTION_OUTGOING_CALL); } callIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // don't forget to copy the extras to callIntent callIntent.putExtras(intent); actionIntent = callIntent; } } */ if (intentAction.equals(ACTION_NOTIFICATION_CALL_DEFAULT)) { if (callIntent != null) { callIntent.setAction(ACTION_INCOMING_CALL); // don't forget to copy the extras to callIntent callIntent.putExtras(intent); actionIntent = callIntent; } else { Context context = getApplicationContext(); PackageManager packageManager = context.getPackageManager(); actionIntent = packageManager.getLaunchIntentForPackage(context.getPackageName()); } } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_VIDEO)) { callIntent.setAction(ACTION_INCOMING_CALL_ANSWER_VIDEO); // don't forget to copy the extras callIntent.putExtras(intent); actionIntent = callIntent; } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_AUDIO)) { callIntent.setAction(ACTION_INCOMING_CALL_ANSWER_AUDIO); // don't forget to copy the extras callIntent.putExtras(intent); actionIntent = callIntent; } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_DECLINE) || intentAction.equals(ACTION_NOTIFICATION_CALL_DELETE)) { RCConnection pendingConnection = getPendingConnection(); if (pendingConnection != null) { pendingConnection.reject(); } release(); // if the call has been requested to be declined, we shouldn't do any UI handling return; } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_MUTE_AUDIO)) { RCConnection liveConnection = getLiveConnection(); if (liveConnection != null) { if (liveConnection.isAudioMuted()) { liveConnection.setAudioMuted(false); } else { liveConnection.setAudioMuted(true); } } // if the call has been requested to be muted, we shouldn't do any UI handling return; } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_DISCONNECT)) { RCConnection liveConnection = getLiveConnection(); if (liveConnection != null) { liveConnection.disconnect(); if (!isAttached()) { // if the call has been requested to be disconnected, we shouldn't do any UI handling callIntent.setAction(ACTION_CALL_DISCONNECT); //callIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); actionIntent = callIntent; startActivity(actionIntent); } /* // Important if we just trigger the call intent, then after the call is disconnected we will land to the previous screen in // that Task Stack, which is not what we want. Instead, we want the call activity to be finished and to just remain where // we were. To do that we need to create a new Task Stack were we only place the call activity TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the target Intent to the top of the stack stackBuilder.addNextIntent(actionIntent); // Gets a PendingIntent containing the entire back stack, but with Component as the active Activity PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); try { resultPendingIntent.send(); } catch (PendingIntent.CanceledException e) { throw new RuntimeException("Pending Intent cancelled", e); } */ } return; } else if (intentAction.equals(ACTION_NOTIFICATION_MESSAGE_DEFAULT)) { if (messageIntent == null) { storageManagerPreferences = new StorageManagerPreferences(this); String messageIntentString = storageManagerPreferences .getString(RCDevice.ParameterKeys.INTENT_INCOMING_MESSAGE, null); if (messageIntentString != null) { try { messageIntent = Intent.parseUri(messageIntentString, Intent.URI_INTENT_SCHEME); //service was stopped and user taps on Notification case if (!isInitialized()) { HashMap<String, Object> parameters = StorageUtils.getParams(storageManagerPreferences); try { initialize(null, parameters, null); } catch (RCException e) { RCLogger.e(TAG, e.toString()); } } } catch (URISyntaxException e) { throw new RuntimeException("Failed to handle Notification"); } } } messageIntent.setAction(ACTION_INCOMING_MESSAGE); // don't forget to copy the extras messageIntent.putExtras(intent); actionIntent = messageIntent; //we want to stop foreground (notification is tapped) stopForeground(true); stopRepeatingTask(); } else { throw new RuntimeException("Failed to handle Notification"); } // We need to create a Task Stack to make sure we maintain proper flow at all times TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds either call or message intent's Component in the stack together with all its parent activities (remember that for this to work the App Manifest needs to describe their relationship) stackBuilder.addParentStack(actionIntent.getComponent()); // Adds the target Intent to the top of the stack stackBuilder.addNextIntent(actionIntent); // Gets a PendingIntent containing the entire back stack, but with Component as the active Activity PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); try { resultPendingIntent.send(); } catch (PendingIntent.CanceledException e) { throw new RuntimeException("Pending Intent cancelled", e); } }
From source file:com.codename1.impl.android.AndroidImplementation.java
private Intent createIntentForURL(String url) { Intent intent;/*from ww w . ja v a2 s . c o m*/ Uri uri; try { if (url.startsWith("intent")) { intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); } else { if (url.startsWith("/") || url.startsWith("file:")) { if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, "This is required to open the file")) { return null; } } intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); if (url.startsWith("/")) { File f = new File(url); Uri furi = null; try { furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", f); } catch (Exception ex) { f = makeTempCacheCopy(f); furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", f); } if (Build.VERSION.SDK_INT < 21) { List<ResolveInfo> resInfoList = getContext().getPackageManager() .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; getContext().grantUriPermission(packageName, furi, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); } } uri = furi; intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { if (url.startsWith("file:")) { File f = new File(removeFilePrefix(url)); System.out.println("File size: " + f.length()); Uri furi = null; try { furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", f); } catch (Exception ex) { f = makeTempCacheCopy(f); furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", f); } if (Build.VERSION.SDK_INT < 21) { List<ResolveInfo> resInfoList = getContext().getPackageManager() .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; getContext().grantUriPermission(packageName, furi, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); } } uri = furi; intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { uri = Uri.parse(url); } } String mimeType = getMimeType(url); if (mimeType != null) { intent.setDataAndType(uri, mimeType); } else { intent.setData(uri); } } return intent; } catch (Exception err) { com.codename1.io.Log.e(err); return null; } }
From source file:com.android.launcher2.Workspace.java
void removeItems(final ArrayList<String> packages) { final HashSet<String> packageNames = new HashSet<String>(); packageNames.addAll(packages);/* w w w. j av a 2 s . c om*/ ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); for (final CellLayout layoutParent : cellLayouts) { final ViewGroup layout = layoutParent.getShortcutsAndWidgets(); // Avoid ANRs by treating each screen separately post(new Runnable() { public void run() { final ArrayList<View> childrenToRemove = new ArrayList<View>(); childrenToRemove.clear(); int childCount = layout.getChildCount(); for (int j = 0; j < childCount; j++) { final View view = layout.getChildAt(j); Object tag = view.getTag(); if (tag instanceof ShortcutInfo) { final ShortcutInfo info = (ShortcutInfo) tag; final Intent intent = info.intent; final ComponentName name = intent.getComponent(); if (name != null) { if (packageNames.contains(name.getPackageName())) { LauncherModel.deleteItemFromDatabase(mLauncher, info); childrenToRemove.add(view); } } } else if (tag instanceof FolderInfo) { final FolderInfo info = (FolderInfo) tag; final ArrayList<ShortcutInfo> contents = info.contents; final int contentsCount = contents.size(); final ArrayList<ShortcutInfo> appsToRemoveFromFolder = new ArrayList<ShortcutInfo>(); for (int k = 0; k < contentsCount; k++) { final ShortcutInfo appInfo = contents.get(k); final Intent intent = appInfo.intent; final ComponentName name = intent.getComponent(); if (name != null) { if (packageNames.contains(name.getPackageName())) { appsToRemoveFromFolder.add(appInfo); } } } for (ShortcutInfo item : appsToRemoveFromFolder) { info.remove(item); LauncherModel.deleteItemFromDatabase(mLauncher, item); } } else if (tag instanceof LauncherAppWidgetInfo) { final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) tag; final ComponentName provider = info.providerName; if (provider != null) { if (packageNames.contains(provider.getPackageName())) { LauncherModel.deleteItemFromDatabase(mLauncher, info); childrenToRemove.add(view); } } } } childCount = childrenToRemove.size(); for (int j = 0; j < childCount; j++) { View child = childrenToRemove.get(j); // Note: We can not remove the view directly from CellLayoutChildren as this // does not re-mark the spaces as unoccupied. layoutParent.removeViewInLayout(child); if (child instanceof DropTarget) { mDragController.removeDropTarget((DropTarget) child); } } if (childCount > 0) { layout.requestLayout(); layout.invalidate(); } } }); } // Clean up new-apps animation list final Context context = getContext(); post(new Runnable() { @Override public void run() { String spKey = LauncherApplication.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); Set<String> newApps = sp.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null); // Remove all queued items that match the same package if (newApps != null) { synchronized (newApps) { Iterator<String> iter = newApps.iterator(); while (iter.hasNext()) { try { Intent intent = Intent.parseUri(iter.next(), 0); String pn = ItemInfo.getPackageName(intent); if (packageNames.contains(pn)) { iter.remove(); } // It is possible that we've queued an item to be loaded, yet it has // not been added to the workspace, so remove those items as well. ArrayList<ItemInfo> shortcuts; shortcuts = LauncherModel.getWorkspaceShortcutItemInfosWithIntent(intent); for (ItemInfo info : shortcuts) { LauncherModel.deleteItemFromDatabase(context, info); } } catch (URISyntaxException e) { } } } } } }); }