Java Code Examples for android.content.ClipData#addItem()

The following examples show how to use android.content.ClipData#addItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CopyToClipboardTask.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
public static ClipData makeClipData(Context context, Location location, Iterable<Path> paths)
{
	Iterator<Path> pi = paths.iterator();
	if(!pi.hasNext())
		return null;
	Path path = pi.next();
	ContentResolver cr = context.getContentResolver();
	ClipData clip = ClipData.newUri(
			cr,
			path.getPathString(),
			MainContentProvider.getContentUriFromLocation(location, path)
	);
	while(pi.hasNext())
	{
		path = pi.next();
		clip.addItem(
				new ClipData.Item(
						MainContentProvider.getContentUriFromLocation(
								location,
								path
						)
				)
		);
	}
	return clip;
}
 
Example 2
Source File: StandaloneActivity.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private void onFinished(Uri... uris) {
    Log.d(TAG, "onFinished() " + Arrays.toString(uris));
    final Intent intent = new Intent();
    if (uris.length == 1) {
        intent.setData(uris[0]);
    } else if (uris.length > 1) {
        final ClipData clipData = new ClipData(
                null, mState.acceptMimes, new ClipData.Item(uris[0]));
        for (int i = 1; i < uris.length; i++) {
            clipData.addItem(new ClipData.Item(uris[i]));
        }
        if(Utils.hasJellyBean()){
            intent.setClipData(clipData);
        }
        else{
            intent.setData(uris[0]);
        }
    }
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
            | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    setResult(Activity.RESULT_OK, intent);
    finish();
}
 
Example 3
Source File: StandaloneActivity.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private void onFinished(Uri... uris) {
    Log.d(TAG, "onFinished() " + Arrays.toString(uris));
    final Intent intent = new Intent();
    if (uris.length == 1) {
        intent.setData(uris[0]);
    } else if (uris.length > 1) {
        final ClipData clipData = new ClipData(
                null, mState.acceptMimes, new ClipData.Item(uris[0]));
        for (int i = 1; i < uris.length; i++) {
            clipData.addItem(new ClipData.Item(uris[i]));
        }
        if(Utils.hasJellyBean()){
            intent.setClipData(clipData);
        }
        else{
            intent.setData(uris[0]);
        }
    }
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
            | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    setResult(Activity.RESULT_OK, intent);
    finish();
}
 
Example 4
Source File: StandaloneActivity.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private void onFinished(Uri... uris) {
    Log.d(TAG, "onFinished() " + Arrays.toString(uris));
    final Intent intent = new Intent();
    if (uris.length == 1) {
        intent.setData(uris[0]);
    } else if (uris.length > 1) {
        final ClipData clipData = new ClipData(
                null, mState.acceptMimes, new ClipData.Item(uris[0]));
        for (int i = 1; i < uris.length; i++) {
            clipData.addItem(new ClipData.Item(uris[i]));
        }
        if(Utils.hasJellyBean()){
            intent.setClipData(clipData);
        }
        else{
            intent.setData(uris[0]);
        }
    }
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
            | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    setResult(Activity.RESULT_OK, intent);
    finish();
}
 
Example 5
Source File: DocumentsActivity.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void onFinished(Uri... uris) {
    Log.d(TAG, "onFinished() " + Arrays.toString(uris));

    final Intent intent = new Intent();
    if (uris.length == 1) {
        intent.setData(uris[0]);
    } else if (uris.length > 1) {
        final ClipData clipData = new ClipData(
                null, mState.acceptMimes, new ClipData.Item(uris[0]));
        for (int i = 1; i < uris.length; i++) {
            clipData.addItem(new ClipData.Item(uris[i]));
        }
        if(Utils.hasJellyBean()){
            intent.setClipData(clipData);	
        }
        else{
        	intent.setData(uris[0]);
        }
    }

    if (mState.action == DocumentsActivity.State.ACTION_GET_CONTENT) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } else if (mState.action == ACTION_OPEN_TREE) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
                | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
    } else {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    }

    setResult(Activity.RESULT_OK, intent);
    finish();
}
 
Example 6
Source File: DocumentsActivity.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void onFinished(Uri... uris) {
    Log.d(TAG, "onFinished() " + Arrays.toString(uris));

    final Intent intent = new Intent();
    if (uris.length == 1) {
        intent.setData(uris[0]);
    } else if (uris.length > 1) {
        final ClipData clipData = new ClipData(
                null, mState.acceptMimes, new ClipData.Item(uris[0]));
        for (int i = 1; i < uris.length; i++) {
            clipData.addItem(new ClipData.Item(uris[i]));
        }
        if(Utils.hasJellyBean()){
            intent.setClipData(clipData);	
        }
        else{
        	intent.setData(uris[0]);
        }
    }

    if (mState.action == DocumentsActivity.State.ACTION_GET_CONTENT) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } else if (mState.action == ACTION_OPEN_TREE) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
                | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
    } else {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    }

    setResult(Activity.RESULT_OK, intent);
    finish();
}
 
Example 7
Source File: DocumentsActivity.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void onFinished(Uri... uris) {
    Log.d(TAG, "onFinished() " + Arrays.toString(uris));

    final Intent intent = new Intent();
    if (uris.length == 1) {
        intent.setData(uris[0]);
    } else if (uris.length > 1) {
        final ClipData clipData = new ClipData(
                null, mState.acceptMimes, new ClipData.Item(uris[0]));
        for (int i = 1; i < uris.length; i++) {
            clipData.addItem(new ClipData.Item(uris[i]));
        }
        if(Utils.hasJellyBean()){
            intent.setClipData(clipData);	
        }
        else{
        	intent.setData(uris[0]);
        }
    }

    if (mState.action == DocumentsActivity.State.ACTION_GET_CONTENT) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } else if (mState.action == ACTION_OPEN_TREE) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
                | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
    } else {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    }

    setResult(Activity.RESULT_OK, intent);
    finish();
}
 
Example 8
Source File: AlbumActivity.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
private ClipData createClipData(AlbumItem[] items) {
    String[] mimeTypes = new String[items.length];
    for (int i = 0; i < items.length; i++) {
        mimeTypes[i] = MediaType.getMimeType(this, items[i].getUri(this));
    }

    ClipData clipData =
            new ClipData("Images", mimeTypes,
                    new ClipData.Item(items[0].getUri(this)));
    for (int i = 1; i < items.length; i++) {
        clipData.addItem(new ClipData.Item(items[i].getUri(this)));
    }
    return clipData;
}
 
Example 9
Source File: BrowserServiceFileProvider.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
/**
 * Grant the read permission to a list of {@link Uri} sent through a {@link Intent}.
 * @param intent The sending Intent which holds a list of Uri.
 * @param uris A list of Uri generated by generateUri(Context, Bitmap, String, int,
 *             List<String>).
 * @param context The context requests to grant the permission.
 */
public static void grantReadPermission(Intent intent, List<Uri> uris, Context context) {
    if (uris == null || uris.size() == 0) return;
    ContentResolver resolver = context.getContentResolver();
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    ClipData clipData = ClipData.newUri(resolver, CLIP_DATA_LABEL, uris.get(0));
    for (int i = 1; i < uris.size(); i++) {
        clipData.addItem(new ClipData.Item(uris.get(i)));
    }
    intent.setClipData(clipData);
}