Example usage for android.content ClipData newUri

List of usage examples for android.content ClipData newUri

Introduction

In this page you can find the example usage for android.content ClipData newUri.

Prototype

static public ClipData newUri(ContentResolver resolver, CharSequence label, Uri uri) 

Source Link

Document

Create a new ClipData holding a URI.

Usage

From source file:Main.java

public static void copyUri(Uri uri, Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newUri(context.getContentResolver(), "uri", uri));
}

From source file:Main.java

/**
 * Copy uri to Clipboard//ww  w  .  j  a  va2  s  .  co  m
 *
 * @param context
 * @param uri
 */
public static void copy(Context context, Uri uri) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newUri(context.getContentResolver(), null, uri));
}

From source file:com.commonsware.android.camcon.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState == null) {
        output = new File(new File(getFilesDir(), PHOTOS), FILENAME);

        if (output.exists()) {
            output.delete();/* w w  w  .j  a  va  2s .c o  m*/
        } else {
            output.getParentFile().mkdirs();
        }

        Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        Uri outputUri = FileProvider.getUriForFile(this, AUTHORITY, output);

        i.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            ClipData clip = ClipData.newUri(getContentResolver(), "A photo", outputUri);

            i.setClipData(clip);
            i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else {
            List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(i,
                    PackageManager.MATCH_DEFAULT_ONLY);

            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                grantUriPermission(packageName, outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            }
        }

        try {
            startActivityForResult(i, CONTENT_REQUEST);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(this, R.string.msg_no_camera, Toast.LENGTH_LONG).show();
            finish();
        }
    } else {
        output = (File) savedInstanceState.getSerializable(EXTRA_FILENAME);
    }
}

From source file:com.commonsware.android.camcon.CameraContentDemoActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    if (savedInstanceState == null) {
        output = new File(new File(getFilesDir(), PHOTOS), FILENAME);

        if (output.exists()) {
            output.delete();/*from  ww w  .  j  ava2s .  co  m*/
        } else {
            output.getParentFile().mkdirs();
        }
    } else {
        output = (File) savedInstanceState.getSerializable(EXTRA_FILENAME);
    }

    outputUri = FileProvider.getUriForFile(this, AUTHORITY, output);

    if (savedInstanceState == null) {
        i.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            ClipData clip = ClipData.newUri(getContentResolver(), "A photo", outputUri);

            i.setClipData(clip);
            i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else {
            List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(i,
                    PackageManager.MATCH_DEFAULT_ONLY);

            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                grantUriPermission(packageName, outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            }
        }

        startActivityForResult(i, CONTENT_REQUEST);
    }
}

From source file:com.ultramegasoft.flavordex2.util.PhotoUtils.java

/**
 * Get an Intent to capture a photo./*  w  ww.j av a 2 s  . co  m*/
 *
 * @return Image capture Intent
 */
@Nullable
public static Intent getTakePhotoIntent(@NonNull Context context) {
    try {
        final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        final Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider",
                getOutputMediaFile());
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            intent.setClipData(ClipData.newUri(context.getContentResolver(), null, uri));
            intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        } else {
            final List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent,
                    PackageManager.MATCH_DEFAULT_ONLY);
            for (ResolveInfo activity : activities) {
                final String name = activity.activityInfo.packageName;
                context.grantUriPermission(name, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            }
        }

        return intent;
    } catch (IOException e) {
        Log.e(TAG, "Failed to create new file", e);
    }
    return null;
}

From source file:com.espian.library.about.AbsAboutActivity.java

public void copy(String type, Uri uri, String backup) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        ClipboardManager newCm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        newCm.setPrimaryClip(ClipData.newUri(getContentResolver(), type, uri));

    } else {//w w w. j  av a2  s.co  m

        android.text.ClipboardManager oldCm = (android.text.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        oldCm.setText(backup);

    }
    Toast.makeText(this, getString(R.string.copy_to_clip, backup), Toast.LENGTH_SHORT).show();

}

From source file:com.android.browser.UploadHandler.java

private Intent createCameraIntent(Uri contentUri) {
    if (contentUri == null)
        throw new IllegalArgumentException();
    mCapturedMedia = contentUri;//from   www.  j a va 2  s . c  om
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedMedia);
    intent.setClipData(ClipData.newUri(mController.getActivity().getContentResolver(), FILE_PROVIDER_AUTHORITY,
            mCapturedMedia));
    return intent;
}

From source file:com.afwsamples.testdpc.SetupManagementFragment.java

private void specifyLogoUri(Intent intent) {
    intent.putExtra(EXTRA_PROVISIONING_LOGO_URI, mLogoUri);
    if (mLogoUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.setClipData(ClipData.newUri(getActivity().getContentResolver(), "", mLogoUri));
    }// ww  w.  jav a 2  s .  c o m
}

From source file:org.kontalk.ui.AbstractComposeFragment.java

/** Starts an activity for shooting a picture. */
void selectPhotoAttachment() {
    try {//  w w w  . j  a v a 2s.co  m
        // check if camera is available
        final PackageManager packageManager = getActivity().getPackageManager();
        final Intent intent = SystemUtils.externalIntent(MediaStore.ACTION_IMAGE_CAPTURE);
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (list.size() <= 0)
            throw new UnsupportedOperationException();

        mCurrentPhoto = MediaStorage.getOutgoingPhotoFile();
        Uri uri = Uri.fromFile(mCurrentPhoto);
        Intent take = SystemUtils.externalIntent(MediaStore.ACTION_IMAGE_CAPTURE);
        take.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            take.setClipData(ClipData.newUri(getContext().getContentResolver(), "Picture path", uri));
        }

        startActivityForResult(take, SELECT_ATTACHMENT_PHOTO);
    } catch (UnsupportedOperationException ue) {
        Toast.makeText(getActivity(), R.string.chooser_error_no_camera_app, Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        Log.e(TAG, "error creating temp file", e);
        Toast.makeText(getActivity(), R.string.chooser_error_no_camera, Toast.LENGTH_LONG).show();
    }
}

From source file:org.kontalk.ui.ComposeMessageFragment.java

/** Starts an activity for shooting a picture. */
private void selectPhotoAttachment() {
    try {/* w  ww .  ja v a  2s  .  com*/
        // check if camera is available
        final PackageManager packageManager = getActivity().getPackageManager();
        final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (list.size() <= 0)
            throw new UnsupportedOperationException();

        mCurrentPhoto = MediaStorage.getOutgoingImageFile();
        Uri uri = Uri.fromFile(mCurrentPhoto);
        Intent take = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        take.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            take.setClipData(ClipData.newUri(getContext().getContentResolver(), "Picture path", uri));
        }

        startActivityForResult(take, SELECT_ATTACHMENT_PHOTO);
    } catch (UnsupportedOperationException ue) {
        Toast.makeText(getActivity(), R.string.chooser_error_no_camera_app, Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        Log.e(TAG, "error creating temp file", e);
        Toast.makeText(getActivity(), R.string.chooser_error_no_camera, Toast.LENGTH_LONG).show();
    }
}