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.appsimobile.appsihomeplugins.dashclock.configuration.AppChooserPreference.java

public static Intent getIntentValue(String value, Intent defaultIntent) {
    try {//from w  w w. j  a  v a  2 s . c o  m
        if (TextUtils.isEmpty(value)) {
            return defaultIntent;
        }

        return Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return defaultIntent;
    }
}

From source file:com.eternizedlab.lunarcalendar.AppChooserPreference.java

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_shortcut_default_title);
    }/*  w  w  w. jav a 2 s.  c  om*/

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_shortcut_default_title);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.size() == 0) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

From source file:com.ctrlplusz.dashclock.yr.configuration.AppChooserPreference.java

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_yr_shortcut_default);
    }/*from  w  w w .  jav  a  2  s . co m*/

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_yr_shortcut_default);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.size() == 0) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

From source file:com.google.android.apps.dashclock.configuration.AppChooserPreference.java

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_shortcut_default);
    }/*from  w  ww  .  j ava  2 s .  co m*/

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_shortcut_default);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.isEmpty()) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

From source file:com.appsimobile.appsihomeplugins.dashclock.configuration.AppChooserPreference.java

public static CharSequence getDisplayValue(Context context, String value) {
    if (TextUtils.isEmpty(value)) {
        return context.getString(R.string.pref_shortcut_default);
    }/*from  w  w w. j a  va 2 s.c  om*/

    Intent intent;
    try {
        intent = Intent.parseUri(value, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException e) {
        return context.getString(R.string.pref_shortcut_default);
    }

    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    if (resolveInfos.size() == 0) {
        return null;
    }

    StringBuilder label = new StringBuilder();
    label.append(resolveInfos.get(0).loadLabel(pm));
    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("http")) {
        label.append(": ").append(intent.getDataString());
    }
    return label;
}

From source file:io.v.android.impl.google.services.beam.BeamActivity.java

@Override
public void onResume() {
    super.onResume();
    NdefMessage msgs[] = null;//from  ww  w .  ja v  a  2 s  .c  o m
    Intent intent = getIntent();

    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
        Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        if (rawMsgs != null) {
            msgs = new NdefMessage[rawMsgs.length];
            for (int i = 0; i < rawMsgs.length; i++) {
                msgs[i] = (NdefMessage) rawMsgs[i];
            }
        }
    }
    if (msgs == null) {
        Log.d(TAG, "No ndef messages");
        finish();
        return;
    }
    VBeamManager.Data data = null;
    for (NdefMessage m : msgs) {
        data = VBeamManager.decodeMessage(m);
        if (data != null)
            break;
    }
    if (data == null) {
        Log.w(TAG, "Unable to deserialize data");
        finish();
        return;
    }
    Log.d(TAG, "connecting to " + data.name);
    VContext ctx = V.init(this).withTimeout(Duration.standardSeconds(2));
    Options opts = new Options();

    opts.set(OptionDefs.SERVER_AUTHORIZER, VSecurity.newPublicKeyAuthorizer(data.key));
    IntentBeamerClient client = IntentBeamerClientFactory.getIntentBeamerClient(data.name);
    ListenableFuture<IntentBeamerClient.GetIntentOut> out = client.getIntent(ctx, data.secret, opts);
    Futures.addCallback(out, new FutureCallback<IntentBeamerClient.GetIntentOut>() {
        @Override
        public void onSuccess(IntentBeamerClient.GetIntentOut result) {
            try {
                Log.d(TAG, "got intent " + result.intentUri);
                int flags = 0;
                if (result.intentUri.startsWith("intent:")) {
                    flags = Intent.URI_INTENT_SCHEME;
                } else {
                    flags = Intent.URI_ANDROID_APP_SCHEME;
                }
                Intent resultIntent = Intent.parseUri(result.intentUri, flags);
                resultIntent.putExtra(VBeamManager.EXTRA_VBEAM_PAYLOAD, result.payload);
                startActivity(resultIntent);
                finish();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }

        @Override
        public void onFailure(Throwable t) {
            t.printStackTrace();
            finish();
        }
    });
}

From source file:Main.java

private static Intent intentFromString(StringBuilder s) {
    CharSequence prefix = extract(s);
    Intent intent = null;/*  ww w  .  ja  v  a  2 s  .  c  o m*/
    if (prefix != null) {
        try {
            String action = toString(extract(s));
            String uri = toString(extract(s));
            intent = Intent.parseUri(uri, Intent.URI_INTENT_SCHEME);
            intent.setAction(action);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
    return intent;
}

From source file:com.battlelancer.seriesguide.api.Action.java

/**
 * Deserializes a {@link Bundle} into a {@link Action} object.
 *//*w w w.j ava2  s.com*/
public static Action fromBundle(Bundle bundle) {
    String title = bundle.getString(KEY_TITLE);
    if (TextUtils.isEmpty(title)) {
        return null;
    }
    int entityIdentifier = bundle.getInt(KEY_ENTITY_IDENTIFIER);
    if (entityIdentifier <= 0) {
        return null;
    }
    Builder builder = new Builder(title, entityIdentifier);

    try {
        String viewIntent = bundle.getString(KEY_VIEW_INTENT);
        if (!TextUtils.isEmpty(viewIntent)) {
            builder.viewIntent(Intent.parseUri(viewIntent, Intent.URI_INTENT_SCHEME));
        }
    } catch (URISyntaxException ignored) {
    }

    return builder.build();
}

From source file:com.andernity.launcher2.InstallShortcutReceiver.java

private static ArrayList<PendingInstallShortcutInfo> getAndClearInstallQueue(SharedPreferences sharedPrefs) {
    synchronized (sLock) {
        Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null);
        if (strings == null) {
            return new ArrayList<PendingInstallShortcutInfo>();
        }//from w w w  . j a v  a 2s  . co m
        ArrayList<PendingInstallShortcutInfo> infos = new ArrayList<PendingInstallShortcutInfo>();
        for (String json : strings) {
            try {
                JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
                Intent data = Intent.parseUri(object.getString(DATA_INTENT_KEY), 0);
                Intent launchIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);
                String name = object.getString(NAME_KEY);
                String iconBase64 = object.optString(ICON_KEY);
                String iconResourceName = object.optString(ICON_RESOURCE_NAME_KEY);
                String iconResourcePackageName = object.optString(ICON_RESOURCE_PACKAGE_NAME_KEY);
                if (iconBase64 != null && !iconBase64.isEmpty()) {
                    byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT);
                    Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length);
                    data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b);
                } else if (iconResourceName != null && !iconResourceName.isEmpty()) {
                    Intent.ShortcutIconResource iconResource = new Intent.ShortcutIconResource();
                    iconResource.resourceName = iconResourceName;
                    iconResource.packageName = iconResourcePackageName;
                    data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
                }
                data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
                PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, launchIntent);
                infos.add(info);
            } catch (org.json.JSONException e) {
                Log.d("InstallShortcutReceiver", "Exception reading shortcut to add: " + e);
            } catch (java.net.URISyntaxException e) {
                Log.d("InstallShortcutReceiver", "Exception reading shortcut to add: " + e);
            }
        }
        sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL, new HashSet<String>()).commit();
        return infos;
    }
}

From source file:cc.flydev.launcher.InstallShortcutReceiver.java

public static void removeFromInstallQueue(SharedPreferences sharedPrefs, ArrayList<String> packageNames) {
    synchronized (sLock) {
        Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null);
        if (DBG) {
            Log.d(TAG, "APPS_PENDING_INSTALL: " + strings + ", removing packages: " + packageNames);
        }/* w w  w. j  a  v a2 s . c  om*/
        if (strings != null) {
            Set<String> newStrings = new HashSet<String>(strings);
            Iterator<String> newStringsIter = newStrings.iterator();
            while (newStringsIter.hasNext()) {
                String json = newStringsIter.next();
                try {
                    JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
                    Intent launchIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);
                    String pn = launchIntent.getPackage();
                    if (pn == null) {
                        pn = launchIntent.getComponent().getPackageName();
                    }
                    if (packageNames.contains(pn)) {
                        newStringsIter.remove();
                    }
                } catch (org.json.JSONException e) {
                    Log.d(TAG, "Exception reading shortcut to remove: " + e);
                } catch (java.net.URISyntaxException e) {
                    Log.d(TAG, "Exception reading shortcut to remove: " + e);
                }
            }
            sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL, new HashSet<String>(newStrings)).commit();
        }
    }
}