Example usage for android.content Intent parseUri

List of usage examples for android.content Intent parseUri

Introduction

In this page you can find the example usage for android.content Intent parseUri.

Prototype

public static Intent parseUri(String uri, @UriFlags int flags) throws URISyntaxException 

Source Link

Document

Create an intent from a URI.

Usage

From source file:com.mods.grx.settings.utils.Utils.java

public static String change_extra_value_in_uri_string(String uri, String extra_key, String new_value) {
    Intent intent;//from  ww w . j a  v a  2 s . c o  m
    try {
        intent = Intent.parseUri(uri, 0);
    } catch (URISyntaxException e) {
        return null;
    }

    if (intent != null) {
        intent.putExtra(extra_key, new_value);
        return intent.toUri(0);
    }
    return null;
}

From source file:org.mozilla.gecko.overlays.ui.ShareDialog.java

public void launchBrowser() {
    try {//from   ww  w  .  j a  v a2  s  .c  o  m
        // This can launch in the guest profile. Sorry.
        final Intent i = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
        i.setClassName(AppConstants.ANDROID_PACKAGE_NAME, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
        startActivity(i);
    } catch (URISyntaxException e) {
        // Nothing much we can do.
    } finally {
        slideOut();
    }
}

From source file:com.android.systemui.statusbar.phone.NavigationBarView.java

private ExtensibleKeyButtonView generateKey(boolean landscape, String clickAction, String longpress,
        String iconUri) {/*from  w w  w .  j a  v  a  2  s.c om*/

    final int iconSize = 80;
    ExtensibleKeyButtonView v = new ExtensibleKeyButtonView(mContext, null, clickAction, longpress);
    Log.i("key.ext", "generated ex key: " + clickAction);
    v.setLayoutParams(getLayoutParams(landscape, iconSize));

    boolean drawableSet = false;

    if (iconUri != null) {
        if (iconUri.length() > 0) {
            // custom icon from the URI here
            File f = new File(Uri.parse(iconUri).getPath());
            if (f.exists()) {
                v.setImageDrawable(new BitmapDrawable(getResources(), f.getAbsolutePath()));
                drawableSet = true;
            }
        }
        if (!drawableSet && clickAction != null && !clickAction.startsWith("**")) {
            // here it's not a system action (**action**), so it must be an
            // app intent
            try {
                Drawable d = mContext.getPackageManager().getActivityIcon(Intent.parseUri(clickAction, 0));
                final int[] appIconPadding = getAppIconPadding();
                if (landscape)
                    v.setPaddingRelative(appIconPadding[1], appIconPadding[0], appIconPadding[3],
                            appIconPadding[2]);
                else
                    v.setPaddingRelative(appIconPadding[0], appIconPadding[1], appIconPadding[2],
                            appIconPadding[3]);
                v.setImageDrawable(d);
                drawableSet = true;
            } catch (NameNotFoundException e) {
                e.printStackTrace();
                drawableSet = false;
            } catch (URISyntaxException e) {
                e.printStackTrace();
                drawableSet = false;
            }
        }
    }

    if (!drawableSet) {
        v.setImageDrawable(getNavbarIconImage(landscape, clickAction));
    }

    v.setGlowBackground(landscape ? R.drawable.ic_sysbar_highlight_land : R.drawable.ic_sysbar_highlight);
    return v;
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Deletes a application desktop shortcut icon.
 *
 * Note://from  w w w .j a va 2 s . co m
 *  Manual way.
 *
 *  This method need two additional permissions in the application:
 *
 * <code>
 *  <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
 * </code>
 *
 * @param context   The application context.
 * @param appClass  Shortcut's  activity class.
 */
public static void application_shortcutRemove_method2(Context context, Class appClass, String appName) {
    Intent intent = new Intent();
    String oldShortcutUri = "#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;package="
            + appClass.getPackage().getName() + ";component=" + appClass.getPackage().getName() + "/."
            + appClass.getSimpleName() + ";end";
    try {
        Intent altShortcutIntent = Intent.parseUri(oldShortcutUri, 0);
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, altShortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
        //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    } catch (URISyntaxException e) {
    }
    intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    context.sendBroadcast(intent);
}

From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java

private Uri insertArtwork(@NonNull final Uri uri, final ContentValues values) {
    Context context = getContext();
    if (context == null) {
        return null;
    }//from  w w w . j av a2 s.  c  o  m
    if (values == null) {
        throw new IllegalArgumentException("Invalid ContentValues: must not be null");
    }
    if (!values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)
            || TextUtils.isEmpty(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME))) {
        throw new IllegalArgumentException("Initial values must contain component name: " + values);
    }

    // Check to make sure the component name is valid
    ComponentName componentName = ComponentName
            .unflattenFromString(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME));
    if (componentName == null) {
        throw new IllegalArgumentException("Invalid component name: "
                + values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME));
    }
    // Make sure they are using the short string format
    values.put(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME, componentName.flattenToShortString());

    // Ensure the app inserting the artwork is either Muzei or the same app as the source
    String callingPackageName = getCallingPackage();
    if (!context.getPackageName().equals(callingPackageName)
            && !TextUtils.equals(callingPackageName, componentName.getPackageName())) {
        throw new IllegalArgumentException("Calling package name (" + callingPackageName
                + ") must match the source's package name (" + componentName.getPackageName() + ")");
    }

    if (values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT)) {
        String viewIntentString = values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT);
        Intent viewIntent;
        try {
            if (!TextUtils.isEmpty(viewIntentString)) {
                // Make sure it is a valid Intent URI
                viewIntent = Intent.parseUri(viewIntentString, Intent.URI_INTENT_SCHEME);
                // Make sure we can construct a PendingIntent for the Intent
                PendingIntent.getActivity(context, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            }
        } catch (URISyntaxException e) {
            Log.w(TAG, "Removing invalid View Intent: " + viewIntentString, e);
            values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT);
        } catch (RuntimeException e) {
            // This is actually meant to catch a FileUriExposedException, but you can't
            // have catch statements for exceptions that don't exist at your minSdkVersion
            Log.w(TAG, "Removing invalid View Intent that contains a file:// URI: " + viewIntentString, e);
            values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT);
        }
    }

    // Ensure the related source has been added to the database.
    // This should be true in 99.9% of cases, but the insert will fail if this isn't true
    Cursor sourceQuery = querySource(MuzeiContract.Sources.CONTENT_URI, new String[] { BaseColumns._ID },
            MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?",
            new String[] { componentName.flattenToShortString() }, null);
    if (sourceQuery == null || sourceQuery.getCount() == 0) {
        ContentValues initialValues = new ContentValues();
        initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME,
                componentName.flattenToShortString());
        insertSource(MuzeiContract.Sources.CONTENT_URI, initialValues);
    }
    if (sourceQuery != null) {
        sourceQuery.close();
    }

    values.put(MuzeiContract.Artwork.COLUMN_NAME_DATE_ADDED, System.currentTimeMillis());
    final SQLiteDatabase db = databaseHelper.getWritableDatabase();
    long rowId = db.insert(MuzeiContract.Artwork.TABLE_NAME, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI,
            values);
    // If the insert succeeded, the row ID exists.
    if (rowId > 0) {
        // Creates a URI with the artwork ID pattern and the new row ID appended to it.
        final Uri artworkUri = ContentUris.withAppendedId(MuzeiContract.Artwork.CONTENT_URI, rowId);
        File artwork = getCacheFileForArtworkUri(artworkUri);
        if (artwork != null && artwork.exists()) {
            // The image already exists so we'll notifyChange() to say the new artwork is ready
            // Otherwise, this will be called when the file is written with openFile()
            // using this Uri and the actual artwork is written successfully
            notifyChange(artworkUri);
        }
        return artworkUri;
    }
    // If the insert didn't succeed, then the rowID is <= 0
    throw new SQLException("Failed to insert row into " + uri);
}

From source file:uk.co.ashtonbrsc.intentexplode.Explode.java

private Intent cloneIntent(String intentUri) {
    if (intentUri != null) {
        try {/*from   w  w w.  j ava  2 s.  c o m*/
            Intent clone = Intent.parseUri(intentUri, Intent.URI_INTENT_SCHEME);

            // bugfix #14: restore extras that are lost in the intent <-> string conversion
            if (additionalExtras != null) {
                clone.putExtras(additionalExtras);
            }

            return clone;
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:com.freeme.filemanager.view.FileViewFragment.java

@Override
public void onPick(FileInfo f) {
    try {//w w  w .  j a  va 2 s .  co  m
        Intent intent = Intent.parseUri(Uri.fromFile(new File(f.filePath)).toString(), 0);
        mActivity.setResult(Activity.RESULT_OK, intent);
        mActivity.finish();
        return;
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

From source file:tk.eatheat.omnisnitch.ui.SwitchLayout.java

private void updateFavorites() {
    final PackageManager pm = mContext.getPackageManager();
    List<String> validFavorites = new ArrayList<String>();
    mFavoriteIcons = new ArrayList<Drawable>();
    mFavoriteNames = new ArrayList<String>();
    Iterator<String> nextFavorite = mFavoriteList.iterator();
    while (nextFavorite.hasNext()) {
        String favorite = nextFavorite.next();
        Intent intent = null;//from ww  w  .j  av a  2s  .c o  m
        Drawable appIcon = null;
        try {
            intent = Intent.parseUri(favorite, 0);
            appIcon = pm.getActivityIcon(intent);
        } catch (NameNotFoundException e) {
            Log.e(TAG, "NameNotFoundException: [" + favorite + "]");
            continue;
        } catch (URISyntaxException e) {
            Log.e(TAG, "URISyntaxException: [" + favorite + "]");
            continue;
        }
        validFavorites.add(favorite);
        String label = Utils.getActivityLabel(pm, intent);
        if (label == null) {
            label = favorite;
        }
        if (appIcon == null) {
            appIcon = getDefaultActivityIcon();
        }
        mFavoriteIcons.add(Utils.resize(mContext.getResources(), appIcon, mConfiguration.mIconSize,
                mConfiguration.mIconBorder, mConfiguration.mDensity));
        mFavoriteNames.add(label);
    }
    mFavoriteList.clear();
    mFavoriteList.addAll(validFavorites);
}

From source file:org.restcomm.android.sdk.RCDevice.java

/**
 * Initialize RCDevice (if not already initialized) the RCDevice Service with parameters. Notice that this needs to happen after the service has been bound. Remember that
 * once the Service starts in continues to run in the background even if the App doesn't have any activity running
 *
 * @param activityContext Activity context
 * @param parameters      Parameters for the Device entity (prefer using the string constants shown below, i.e. RCDevice.ParameterKeys.*, instead of
 *                        using strings like 'signaling-secure', etc. Possible keys: <br>
 *                        <b>RCDevice.ParameterKeys.SIGNALING_USERNAME</b>: Identity for the client, like <i>'bob'</i> (mandatory) <br>
 *                        <b>RCDevice.ParameterKeys.SIGNALING_PASSWORD</b>: Password for the client (optional for registrar-less scenarios). Be VERY careful to securely handle this inside your App. Never store it statically and in cleartext form in your App before submitting to Google Play Store as you run the risk of any of the folks downloading it figuring it out your credentials <br>
 *                        <b>RCDevice.ParameterKeys.SIGNALING_DOMAIN</b>: Restcomm endpoint to use, like <i>'cloud.restcomm.com'</i>. By default port 5060 will be used for cleartext signaling and 5061 for encrypted signaling. You can override the port by suffixing the domain; for example to use port 5080 instead, use the following: <i>'cloud.restcomm.com:5080'</i>. Don't pass this parameter (or leave empty) for registrar-less mode (optional) <br>
 *                        <b>RCDevice.ParameterKeys.MEDIA_ICE_SERVERS_DISCOVERY_TYPE</b>: Media ICE server discovery type, or how should SDK figure out which the actual set ICE servers to use internally. Use ICE_SERVERS_CONFIGURATION_URL_XIRSYS_V2 to utilize a V2 Xirsys configuration URL to retrieve the ICE servers. Use ICE_SERVERS_CONFIGURATION_URL_XIRSYS_V3 to utilize a V3 Xirsys configuration URL to retrieve the ICE servers. Use ICE_SERVERS_CUSTOM if you don't want to use a configuration URL, but instead provide the set of ICE servers youself to the SDK (i.e. the App needs to have logic to retrieve them and provide them) <br>
 *                        <b>RCDevice.ParameterKeys.MEDIA_ICE_URL</b>: ICE url to use when using a Xirsys configuration URL, like <i>'https://service.xirsys.com/ice'</i> for Xirsys V2 (i.e. ICE_SERVERS_CONFIGURATION_URL_XIRSYS_V2), and <i>https://es.xirsys.com/_turn/</i> for Xirsys V3 (i.e. ICE_SERVERS_CONFIGURATION_URL_XIRSYS_V3). If no Xirsys configuration URL is used (i.e. ICE_SERVERS_CUSTOM) then this key is not applicable shouldn't be passed (optional) <br>
 *                        <b>RCDevice.ParameterKeys.MEDIA_ICE_USERNAME</b>: ICE username for authentication when using a Xirsys configuration URL (optional)  <br>
 *                        <b>RCDevice.ParameterKeys.MEDIA_ICE_PASSWORD</b>: ICE password for authentication when using a Xirsys configuration URL (optional). Be VERY careful to securely handle this inside your App. Never store it statically and in cleartext form in your App before submitting to Google Play Store as you run the risk of any of the folks downloading it figuring it out your credentials  <br>
 *                        <b>RCDevice.ParameterKeys.MEDIA_ICE_DOMAIN</b>: ICE Domain to be used in the ICE configuration URL when using a Xirsys configuration URL. Notice that V2 Domains are called Channels in V3 organization, but we use this same key in both cases (optional) <br>
 *                        <b>RCDevice.ParameterKeys.SIGNALING_SECURE_ENABLED</b>: Should signaling traffic be encrypted? Always set this to true, unless you have a very good reason to use cleartext signaling (like debugging). If this is the case, then a key pair is generated when
 *                        signaling facilities are initialized and added to a custom keystore. Also, added to this custom keystore are all the trusted certificates from
 *                        the System Wide Android CA Store, so that we properly accept only legit server certificates. If not passed (or false) signaling is cleartext (optional) <br>
 *                        <b>RCDevice.ParameterKeys.MEDIA_TURN_ENABLED</b>: Should TURN be enabled for webrtc media? (optional) <br>
 *                        <b>RCDevice.ParameterKeys.SIGNALING_LOCAL_PORT</b>: Local port to use for signaling (optional) <br>
 *                        <b>RCDevice.ParameterKeys.RESOURCE_SOUND_CALLING</b>: The SDK provides the user with default sounds for calling, ringing, busy (declined) and message events, but the user can override them
 *                        by providing their own resource files (i.e. .wav, .mp3, etc) at res/raw passing them here with Resource IDs like R.raw.user_provided_calling_sound. This parameter
 *                        configures the sound you will hear when you make a call and until the call is either replied or you hang up<br>
 *                        <b>RCDevice.ParameterKeys.RESOURCE_SOUND_RINGING</b>: The sound you will hear when you receive a call <br>
 *                        <b>RCDevice.ParameterKeys.RESOURCE_SOUND_DECLINED</b>: The sound you will hear when your call is declined <br>
 *                        <b>RCDevice.ParameterKeys.RESOURCE_SOUND_MESSAGE</b>: The sound you will hear when you receive a message <br>
 *
 *                        //push notification keys
 *                        <b>RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_APPLICATION_NAME</b>: name of the client application
 *                        <b>RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_ACCOUNT_EMAIL</b>: account's email
 *                        <b>RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_ACCOUNT_PASSWORD </b>: password for an account
 *                        <b>RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_ENABLE_PUSH_FOR_ACCOUNT</b>: true if we want to enable push on server for the account, otherwise false
 *                        <b>RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_PUSH_DOMAIN</b>: domain for the push notifications; for example: push.restcomm.com
 *                        <b>RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_HTTP_DOMAIN</b>: Restcomm HTTP domain, like 'cloud.restcomm.com'
 *                        <b>RCDevice.ParameterKeys.PUSH_NOTIFICATIONS_FCM_SERVER_KEY</b>: server hash key for created application in firebase cloud messaging
 *                        <b>RCDevice.ParameterKeys.PUSH_NOTIFICATION_TIMEOUT_MESSAGING_SERVICE</b>: RCDevice will have timer introduced for closing because of the message background logic this is introduced in the design. The timer by default will be 5 seconds; It can be changed by sending parameter with value (in milliseconds)
        /*  www.  ja  v a 2  s . c  om*/
 * @param deviceListener  The listener for upcoming RCDevice events
 * @return True always for now
 * @see RCDevice
 */
public boolean initialize(Context activityContext, HashMap<String, Object> parameters,
        RCDeviceListener deviceListener) throws RCException {
    try {
        if (!isServiceInitialized) {

            isServiceInitialized = true;
            //context = activityContext;
            state = DeviceState.OFFLINE;

            RCLogger.i(TAG, "RCDevice(): " + parameters.toString());

            //this.updateCapabilityToken(capabilityToken);
            this.listener = deviceListener;

            RCUtils.validateDeviceParms(parameters);

            storageManagerPreferences = new StorageManagerPreferences(this);
            StorageUtils.saveParams(storageManagerPreferences, parameters);

            //because intents are saved as uri strings we need to check; do we have an
            //actual intent. If not, we must check is it a string and return an intent
            Object callObj = parameters.get(RCDevice.ParameterKeys.INTENT_INCOMING_CALL);
            Object messageObj = parameters.get(RCDevice.ParameterKeys.INTENT_INCOMING_MESSAGE);

            if (callObj instanceof String && messageObj instanceof String) {
                Intent intentCall;
                Intent intentMessage;

                try {
                    intentCall = Intent.parseUri((String) callObj, Intent.URI_INTENT_SCHEME);
                } catch (URISyntaxException e) {
                    throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_REGISTER_INTENT_CALL_MISSING);
                }

                try {
                    intentMessage = Intent.parseUri((String) messageObj, Intent.URI_INTENT_SCHEME);
                } catch (URISyntaxException e) {
                    throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_REGISTER_INTENT_MESSAGE_MISSING);
                }

                setIntents(intentCall, intentMessage);
            } else if (callObj instanceof Intent && messageObj instanceof Intent) {
                setIntents((Intent) callObj, (Intent) messageObj);
            }

            //set messages timer
            if (parameters.get(ParameterKeys.PUSH_NOTIFICATION_TIMEOUT_MESSAGING_SERVICE) != null) {
                messageTimeOutIntervalLimit = (long) parameters
                        .get(ParameterKeys.PUSH_NOTIFICATION_TIMEOUT_MESSAGING_SERVICE);
            }

            connections = new HashMap<String, RCConnection>();

            //if there is already data for registering to push, dont clear it (onOpenReply is using this parameter)
            // initialize JAIN SIP if we have connectivity
            this.parameters = parameters;

            // initialize registration FSM before we start signaling and push notification registrations
            // important: needs to happen *before* signaling and push registration
            startRegistrationFsm();

            // check if TURN keys are there
            //params.put(RCDevice.ParameterKeys.MEDIA_TURN_ENABLED, prefs.getBoolean(RCDevice.ParameterKeys.MEDIA_TURN_ENABLED, true));
            if (signalingClient == null) {
                signalingClient = new SignalingClient();
                signalingClient.open(this, getApplicationContext(), parameters);
            }

            registerForPushNotifications(false);

            if (audioManager == null) {
                // Create and audio manager that will take care of audio routing,
                // audio modes, audio device enumeration etc.
                audioManager = AppRTCAudioManager.create(getApplicationContext(), new Runnable() {
                    // This method will be called each time the audio state (number and
                    // type of devices) has been changed.
                    @Override
                    public void run() {
                        onAudioManagerChangedState();
                    }
                });

                // Store existing audio settings and change audio mode to
                // MODE_IN_COMMUNICATION for best possible VoIP performance.
                RCLogger.d(TAG, "Initializing the audio manager...");
                audioManager.init(parameters);
            }
        } else {
            throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_ALREADY_INITIALIZED);
        }
        return false;
    } catch (RCException e) {
        isServiceInitialized = false;
        throw e;
    }
}

From source file:com.inmobi.rendering.RenderView.java

public void m1956b(String str, String str2, String str3) {
    try {//from   w w w  .  j a va 2s .  co  m
        Intent parseUri = Intent.parseUri(str3, 0);
        parseUri.setFlags(268435456);
        getContext().startActivity(parseUri);
        getListener().m1907g(this);
        m1946a(str2, "broadcastEvent('" + str + "Successful','" + str3 + "');");
    } catch (URISyntaxException e) {
        m1949a(str2, "Cannot resolve URI (" + str3 + ")", str);
        Logger.m1744a(InternalLogLevel.INTERNAL, f1748a,
                "Error message in processing openExternal: " + e.getMessage());
    } catch (ActivityNotFoundException e2) {
        m1949a(str2, "No app can handle the URI (" + str3 + ")", str);
        Logger.m1744a(InternalLogLevel.INTERNAL, f1748a,
                "Error message in processing openExternal: " + e2.getMessage());
    }
}