Java Code Examples for com.facebook.internal.Utility#isFileUri()

The following examples show how to use com.facebook.internal.Utility#isFileUri() . 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: VideoUploader.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
private void initialize()
        throws FileNotFoundException {
    ParcelFileDescriptor fileDescriptor = null;
    try {
        if (Utility.isFileUri(videoUri)) {
            fileDescriptor = ParcelFileDescriptor.open(
                    new File(videoUri.getPath()),
                    ParcelFileDescriptor.MODE_READ_ONLY);
            videoSize = fileDescriptor.getStatSize();
            videoStream = new ParcelFileDescriptor.AutoCloseInputStream(fileDescriptor);
        } else if (Utility.isContentUri(videoUri)) {
            videoSize = Utility.getContentSize(videoUri);
            videoStream = FacebookSdk
                    .getApplicationContext()
                    .getContentResolver()
                    .openInputStream(videoUri);
        } else {
            throw new FacebookException("Uri must be a content:// or file:// uri");
        }
    } catch (FileNotFoundException e) {
        Utility.closeQuietly(videoStream);

        throw e;
    }
}
 
Example 2
Source File: ShareContentValidation.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private static void validateVideo(ShareVideo video, Validator validator) {
    if (video == null) {
        throw new FacebookException("Cannot share a null ShareVideo");
    }

    Uri localUri = video.getLocalUrl();
    if (localUri == null) {
        throw new FacebookException("ShareVideo does not have a LocalUrl specified");
    }

    if (!Utility.isContentUri(localUri) && !Utility.isFileUri(localUri)) {
        throw new FacebookException("ShareVideo must reference a video that is on the device");
    }
}
 
Example 3
Source File: ShareInternalUtility.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new Request configured to upload an image to create a staging resource. Staging
 * resources allow you to post binary data such as images, in preparation for a post of an Open
 * Graph object or action which references the image. The URI returned when uploading a staging
 * resource may be passed as the image property for an Open Graph object or action.
 *
 * @param accessToken the access token to use, or null
 * @param imageUri    the file:// or content:// Uri pointing to the image to upload
 * @param callback    a callback that will be called when the request is completed to handle
 *                    success or error conditions
 * @return a Request that is ready to execute
 * @throws FileNotFoundException
 */
public static GraphRequest newUploadStagingResourceWithImageRequest(
        AccessToken accessToken,
        Uri imageUri,
        Callback callback
) throws FileNotFoundException {
    if (Utility.isFileUri(imageUri)) {
        return newUploadStagingResourceWithImageRequest(
                accessToken,
                new File(imageUri.getPath()),
                callback);
    } else if (!Utility.isContentUri(imageUri)) {
        throw new FacebookException("The image Uri must be either a file:// or content:// Uri");
    }

    GraphRequest.ParcelableResourceWithMimeType<Uri> resourceWithMimeType =
            new GraphRequest.ParcelableResourceWithMimeType<>(imageUri, "image/png");
    Bundle parameters = new Bundle(1);
    parameters.putParcelable(STAGING_PARAM, resourceWithMimeType);

    return new GraphRequest(
            accessToken,
            MY_STAGING_RESOURCES,
            parameters,
            HttpMethod.POST,
            callback);
}