Example usage for android.content Intent getDataString

List of usage examples for android.content Intent getDataString

Introduction

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

Prototype

public @Nullable String getDataString() 

Source Link

Document

The same as #getData() , but returns the URI as an encoded String.

Usage

From source file:Main.java

/**
 * Converts an {@link android.content.Intent} object to a {@code String}.
 *
 * @param intent The converted intent.// w w  w  . ja v a 2s  .  c  om
 * @return The string representation of the intent.
 */
@SuppressWarnings("PMD.ConsecutiveLiteralAppends")
@NonNull
public static String toString(@Nullable final Intent intent) {
    if (intent == null) {
        return "null";
    }

    final StringBuilder stringBuilder = new StringBuilder("Intent{action=\"").append(intent.getAction())
            .append('"').append(ITEM_DIVIDER).append("data=\"").append(intent.getDataString()).append('"')
            .append(ITEM_DIVIDER).append("component=\"").append(intent.getComponent()).append('"')
            .append(ITEM_DIVIDER);

    final Bundle extras = intent.getExtras();
    stringBuilder.append("extras=").append(extras == null ? null : toString(extras)).append('}');
    return stringBuilder.toString();
}

From source file:com.fanfou.app.opensource.util.IntentHelper.java

public static void logIntent(final String tag, final Intent intent) {
    if (intent == null) {
        return;//from  w w w.  j av  a2 s . c o  m
    }
    final StringBuffer sb = new StringBuffer();
    sb.append("\nAction:" + intent.getAction());
    sb.append("\nData:" + intent.getData());
    sb.append("\nDataStr:" + intent.getDataString());
    sb.append("\nScheme:" + intent.getScheme());
    sb.append("\nType:" + intent.getType());
    final Bundle extras = intent.getExtras();
    if ((extras != null) && !extras.isEmpty()) {
        for (final String key : extras.keySet()) {
            final Object value = extras.get(key);
            sb.append("\nEXTRA: {" + key + "::" + value + "}");
        }
    } else {
        sb.append("\nNO EXTRAS");
    }
    Log.i(tag, sb.toString());
}

From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java

private static JSONObject buildJsonIntent(Intent data) throws JSONException {
    JSONObject result = new JSONObject();
    result.put("data", data.getDataString());
    result.put("type", data.getType());
    result.put("extras", build(data.getExtras()));
    result.put("categories", build(data.getCategories()));
    result.put("action", data.getAction());
    ComponentName component = data.getComponent();
    if (component != null) {
        result.put("packagename", component.getPackageName());
        result.put("classname", component.getClassName());
    }//from   w  ww .j  av a  2  s  .c o m
    result.put("flags", data.getFlags());
    return result;
}

From source file:com.android.launcher3.InstallShortcutReceiver.java

/**
 * Returns true if the intent is a valid launch intent for a shortcut.
 * This is used to identify shortcuts which are different from the ones exposed by the
 * applications' manifest file./* w  ww  . j  a  v  a 2 s . co m*/
 *
 * When DISABLE_ALL_APPS is true, shortcuts exposed via the app's manifest should never be
 * duplicated or removed(unless the app is un-installed).
 *
 * @param launchIntent The intent that will be launched when the shortcut is clicked.
 */
static boolean isValidShortcutLaunchIntent(Intent launchIntent) {
    if (launchIntent != null && Intent.ACTION_MAIN.equals(launchIntent.getAction())
            && launchIntent.getComponent() != null && launchIntent.getCategories() != null
            && launchIntent.getCategories().size() == 1 && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
            && launchIntent.getExtras() == null && TextUtils.isEmpty(launchIntent.getDataString())) {
        return false;
    }
    return true;
}

From source file:org.chromium.ChromeSystemStorage.java

private static BackgroundEventHandler<ChromeSystemStorage> createEventHandler() {

    return new BackgroundEventHandler<ChromeSystemStorage>() {

        @Override//from   w w w.  j  ava  2  s.c om
        public BackgroundEventInfo mapBroadcast(Context context, Intent intent) {

            String action = intent.getAction();
            if (!(Intent.ACTION_MEDIA_MOUNTED.equals(action) || Intent.ACTION_MEDIA_BAD_REMOVAL.equals(action)
                    || Intent.ACTION_MEDIA_REMOVED.equals(action) || Intent.ACTION_MEDIA_SHARED.equals(action)
                    || Intent.ACTION_MEDIA_UNMOUNTED.equals(action))) {
                // Ignore any other actions
                return null;
            }

            BackgroundEventInfo event = new BackgroundEventInfo(action);
            event.getData().putString(DATA_STORAGE_PATH, intent.getDataString());

            return event;
        }

        @Override
        public void mapEventToMessage(BackgroundEventInfo event, JSONObject message) throws JSONException {
            boolean attached = Intent.ACTION_MEDIA_MOUNTED.equals(event.action);

            // Sanitize the path provided with the event
            String storagePath = getBaseStoragePath(
                    Uri.parse(event.getData().getString(DATA_STORAGE_PATH)).getPath());

            ChromeSystemStorage plugin = getCurrentPlugin();

            // The attached/detached events may fire before the client has a chance to call getInfo().
            // Thus, must initialize the external storage here (if not already done), to ensure that
            // unit ids are consistent across calls to getInfo, and subsequent attach/detach events.
            StorageFile[] directories = plugin.initializeExternalStorageDirectories();

            String unitId = plugin.getExternalStorageId(storagePath);
            StorageFile attachedStorage = null;
            if (attached) {
                attachedStorage = plugin.getExternalStorageDirectoryByPath(storagePath, directories);
            } else {
                // If the detached event causes initialization, the unit id may not be found
                // as it won't be reported in the list of directories.  We can safely generate
                // a random id, as the client won't have called getInfo yet.
                if (unitId == null) {
                    unitId = UUID.randomUUID().toString();
                }
            }

            message.put("action", attached ? "attached" : "detached");
            message.put("id", unitId);
            if (attached) {
                JSONObject storageUnit = plugin.buildExternalStorageUnitInfo(attachedStorage);

                message.put("info", storageUnit);
            }
        }
    };
}

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  . ja  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_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:org.jitsi.android.gui.call.CallContactActivity.java

/**
 * Called when the activity is starting. Initializes the corresponding
 * call interface./* w  w  w. ja va  2s.c  o m*/
 *
 * @param savedInstanceState If the activity is being re-initialized after
 * previously being shut down then this Bundle contains the data it most
 * recently supplied in onSaveInstanceState(Bundle).
 * Note: Otherwise it is null.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // There's no need to create fragment if the Activity is being restored.
    if (savedInstanceState == null) {
        //Create new call contact fragment
        String phoneNumber = null;
        Intent intent = getIntent();
        if (intent.getDataString() != null)
            phoneNumber = PhoneNumberUtils.getNumberFromIntent(intent, this);
        Fragment ccFragment = CallContactFragment.newInstance(phoneNumber);
        getSupportFragmentManager().beginTransaction().add(android.R.id.content, ccFragment).commit();
    }
}

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   www .j ava  2 s  .com*/

    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);
    }// ww w  .  j  a  va 2 s  .c o 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.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.syng.activity.MainActivity.java

private void processIntent(Intent intent) {
    if (intent.getDataString() != null && intent.getDataString().indexOf("dapp://") == 0) {
        WebViewFragment wvF = new WebViewFragment();
        Bundle args = new Bundle();
        args.putString("url", intent.getDataString());
        wvF.setArguments(args);/*w  w w .j a va2s  . c  o m*/
        replaceFragment(wvF);
        closeDrawer();
    }
}