Intent toURI - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Intent toURI method.

This code example shows how to use the following methods: getParcelableExtra, putExtra, resolveActivityInfo, toUri
    private void completeSetCustomApp(Intent data) {
        mListener.shortcutPicked(data.toUri(0), getFriendlyActivityName(data, false), true);
    } 
 
    private void completeSetCustomShortcut(Intent data) {
        Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
        /* preserve shortcut name, we want to restore it later */ 
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME));
        String appUri = intent.toUri(0);
        appUri = appUri.replaceAll("com.android.contacts.action.QUICK_CONTACT", "android.intent.action.VIEW");
        mListener.shortcutPicked(appUri, getFriendlyShortcutName(intent), false);
    } 
 
    private String getFriendlyActivityName(Intent intent, boolean labelOnly) {
        PackageManager pm = mParent.getPackageManager();
        ActivityInfo ai = intent.resolveActivityInfo(pm, PackageManager.GET_ACTIVITIES);
        String friendlyName = null;
 
        if (ai != null) {
            friendlyName = ai.loadLabel(pm).toString();

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getStringExtra, resolveActivityInfo, toUri
        mListener.shortcutPicked(appUri, getFriendlyShortcutName(intent), bmp, false);
    } 
 
    private String getFriendlyActivityName(Intent intent, boolean labelOnly) {
        PackageManager pm = mParent.getActivity().getPackageManager();
        ActivityInfo ai = intent.resolveActivityInfo(pm, PackageManager.GET_ACTIVITIES);
        String friendlyName = null;
 
        if (ai != null) {
            friendlyName = ai.loadLabel(pm).toString();
            if (friendlyName == null && !labelOnly) {
                friendlyName = ai.name;
            } 
        } 
 
        return friendlyName != null || labelOnly ? friendlyName : intent.toUri(0);
    } 
 
    private String getFriendlyShortcutName(Intent intent) {
        String activityName = getFriendlyActivityName(intent, true);

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: addFlags, setPackage, toUri
     * Ask the current default engine to launch the matching INSTALL_TTS_DATA activity 
     * so the required TTS files are properly installed. 
     */ 
    private void installVoiceData() { 
        if (TextUtils.isEmpty(getEngineName())) return;
        Intent intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setPackage(getEngineName());
        try { 
            Log.v(TAG, "Installing voice data: " + intent.toUri(0));
            startActivity(intent);
        } catch (ActivityNotFoundException ex) {
            Log.e(TAG, "Failed to install TTS data, no acitivty found for " + intent + ")");
        } 
    } 
 
    @Override 
    public boolean onPreferenceClick(Preference preference) {
        if (preference == mInstallVoicesPreference) {
            installVoiceData(); 
Full Snippet Info
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: toUri
 
    } 
 
    private void launchIntent(Intent intent) {
        try { 
            Log.i(TAG, "Launching intent: " + intent.toUri(0));
            startActivity(intent);
        } catch (ActivityNotFoundException ex) {
            Log.w(TAG, "No activity found to handle: " + intent);
        } 
    } 
 
    private boolean launchPendingIntent(PendingIntent pending, Intent fillIn) {
        try { 
            pending.send(this, Activity.RESULT_OK, fillIn);
            return true; 
        } catch (PendingIntent.CanceledException ex) {
            Log.i(TAG, "Pending intent cancelled: " + pending);
            return false; 
        } 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getStringExtra, resolveActivityInfo, toUri
        } 
    } 
 
    private static String getFriendlyActivityName(Context mContext, Intent intent) {
        PackageManager pm = mContext.getPackageManager();
        ActivityInfo ai = intent.resolveActivityInfo(pm, PackageManager.GET_ACTIVITIES);
        String friendlyName = null;
 
        if (ai != null) {
            friendlyName = ai.loadLabel(pm).toString();
            if (friendlyName == null) {
                friendlyName = ai.name;
            } 
        } 
 
        return (friendlyName != null) ? friendlyName : intent.toUri(0);
    } 
 
    private static String getFriendlyShortcutName(Context mContext, Intent intent) {
        String activityName = getFriendlyActivityName(mContext, intent);

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getItemCount, getIcon
 
    private void stash(ClipData clipping) {
        mClipping = clipping;
        if (mClipping != null) {
            setVisibility(View.VISIBLE);
            Bitmap icon = mClipping.getIcon();
//            mDescription.setText(mClipping.getDescription().getLabel()); 
            if (icon != null) {
                setImageBitmap(icon);
            } else { 
                if (mClipping.getItemCount() > 0) {
                    // TODO: figure out how to visualize every kind of ClipData! 
                    //mAltText.setText(mClipping.getItemAt(0).coerceToText(getContext())); 
                } 
            } 
        } else { 
            setVisibility(View.GONE);
        } 
    } 
 
Full Snippet Info
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
                            target.getType()
                    }; 
                } else { 
                    mimeTypes = new String[]{};
                } 
                targetClipData = new ClipData(null, mimeTypes, item);
            } 
            if (targetClipData != null) {
                intent.setClipData(targetClipData);
                intent.addFlags(permFlags);
            } 
        } 
        return intent;
    } 
 
    private IntentCompat() { 
    } 
} 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getItemAt
     
    if (clip==null) {
      Toast.makeText(this, "There is no clip!", Toast.LENGTH_LONG).show();
    } 
    else { 
      ClipData.Item item=clip.getItemAt(0);
      Uri song=item.getUri();
       
      if (song!=null &&
          getContentResolver().getType(song).startsWith("audio/")) {
        startActivity(new Intent(Intent.ACTION_VIEW, song));
      } 
      else { 
        Toast.makeText(this, "There is no song!", Toast.LENGTH_LONG).show();
      } 
    } 
  } 
} 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getItemCount, getIcon
    } 
 
    private void stash(ClipData clipping) {
        mClipping = clipping;
        if (mClipping != null) {
            setVisibility(View.VISIBLE);
            Bitmap icon = mClipping.getIcon();
//            mDescription.setText(mClipping.getDescription().getLabel()); 
            if (icon != null) {
                setImageBitmap(icon);
            } else { 
                if (mClipping.getItemCount() > 0) {
                    // TODO: figure out how to visualize every kind of ClipData! 
                    //mAltText.setText(mClipping.getItemAt(0).coerceToText(getContext())); 
                } 
            } 
        } else { 
            setVisibility(View.GONE);
        } 
    } 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getItemAt, getItemCount
	} 
 
	public CharSequence getText() {
		ClipData cp = cbV11.getPrimaryClip();
		if (cp != null) {
			if (cp.getItemCount() > 0) {
				Item cpi = cp.getItemAt(0);
				return cpi.coerceToText(mAppContext);
			} 
		} 
 
		return null; 
	} 
 
} 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Intent toURI Questions & Answers:

toURI Method Overview
This method was deprecated in API level 4. Use toUri(int) instead.
See Code Examples for other Android Intent Methods: