Java Code Examples for android.content.Intent.getClipData()

The following are Jave code examples for showing how to use getClipData() of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Android.Media.Uploader   File: Helper.java   View Source Code Vote up 7 votes
public static ArrayList<String> GetAllPath(final Context context, Intent data) {


        ArrayList<String> Paths = new ArrayList<>();

        if (data.getClipData() != null) {
            int count = data.getClipData().getItemCount();
            for (int i = 0; i < count; i++) {
                Paths.add(
                        getRealPath(context, data.getClipData().getItemAt(i).getUri())
                );
            }
        }

        if (data.getData() != null) {
            Paths.add(
                    getRealPath(context, data.getData())
            );
        }

        return Paths;
    }
 
Example 2
Project: AgentWeb   File: FileUpLoadChooserImpl.java   View Source Code Vote up 7 votes
private Uri[] processData(Intent data) {

        Uri[] datas = null;
        if (data == null) {
            return datas;
        }
        String target = data.getDataString();
        if (!TextUtils.isEmpty(target)) {
            return datas = new Uri[]{Uri.parse(target)};
        }
        ClipData mClipData = data.getClipData();
        if (mClipData != null && mClipData.getItemCount() > 0) {
            datas = new Uri[mClipData.getItemCount()];
            for (int i = 0; i < mClipData.getItemCount(); i++) {

                ClipData.Item mItem = mClipData.getItemAt(i);
                datas[i] = mItem.getUri();

            }
        }
        return datas;


    }
 
Example 3
Project: androidnative.pri   File: VideoPicker.java   View Source Code Vote up 7 votes
static private void importVideo(Intent data) {
    Uri uri = data.getData();

    Log.d(TAG,"importVideo: uri:" + uri);
    Log.d(TAG,"importVideo: type: " + data.getType());

    if (data.getClipData() != null) {
        importVideoFromClipData(data);
    } else if (uri != null ) {
        if (uri.getScheme().equals("file")) {
            importVideoFromFileUri(uri);
        } else {
            importVideoFromContentUri(uri);
        }
    }

}
 
Example 4
Project: androidnative.pri   File: VideoPicker.java   View Source Code Vote up 7 votes
private static void importVideoFromClipData(Intent data) {
    ClipData clipData = data.getClipData();

    Log.d(TAG,"Video importFromClipData");

    if (clipData.getItemCount() == 0)
        return;

    ArrayList<Uri> uris = new ArrayList(clipData.getItemCount());

    for (int i = 0 ; i < clipData.getItemCount() ; i++ ){
        Uri uri = clipData.getItemAt(i).getUri();
        uris.add(resolveUri(uri));
    }
    importVideoFromFileUri(uris);
}
 
Example 5
Project: androidnative.pri   File: ImagePicker.java   View Source Code Vote up 7 votes
static private void importImage(Intent data) {
    Uri uri = data.getData();

    Log.d(TAG,"importImage: uri:" + uri);
    Log.d(TAG,"importImage: type: " + data.getType());

    if (data.getClipData() != null) {
        importImageFromClipData(data);
    } else if (uri != null ) {
        if (uri.getScheme().equals("file")) {
            importImageFromFileUri(uri);
        } else {
            importImageFromContentUri(uri);
        }
    }

}
 
Example 6
Project: androidnative.pri   File: ImagePicker.java   View Source Code Vote up 7 votes
private static void importImageFromClipData(Intent data) {
    ClipData clipData = data.getClipData();

    Log.d(TAG,"importFromClipData");

    if (clipData.getItemCount() == 0)
        return;

    ArrayList<Uri> uris = new ArrayList(clipData.getItemCount());

    for (int i = 0 ; i < clipData.getItemCount() ; i++ ){
        Uri uri = clipData.getItemAt(i).getUri();
        uris.add(resolveUri(uri));
    }
    importImageFromFileUri(uris);
}
 
Example 7
Project: AliZhiBoHao   File: WebActivity.java   View Source Code Vote up 7 votes
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void onActivityResultAboveL(int requestCode, int resultCode, Intent intent) {
    if (requestCode != FILECHOOSER_RESULTCODE || mUploadCallbackAboveL == null)
        return;
    Uri[] results = null;
    if (resultCode == Activity.RESULT_OK) {
        if (intent != null) {
            String dataString = intent.getDataString();
            ClipData clipData = intent.getClipData();
            if (clipData != null) {
                results = new Uri[clipData.getItemCount()];
                for (int i = 0; i < clipData.getItemCount(); i++) {
                    ClipData.Item item = clipData.getItemAt(i);
                    results[i] = item.getUri();
                }
            }
            if (dataString != null)
                results = new Uri[]{Uri.parse(dataString)};
        }
    }
    mUploadCallbackAboveL.onReceiveValue(results);
    mUploadCallbackAboveL = null;
}
 
Example 8
Project: WebViewInputSample   File: FileChooserWebChromeClient.java   View Source Code Vote up 7 votes
/**
 * カメラやギャラリーから戻ってきたときの処理 (onActivityResultで呼ぶ)
 */
public void cleanUpOnBackFromFileChooser(Context context, int resultCode, Intent intent) {
    if (filePathCallback == null) {
        return;
    }
    if (resultCode != Activity.RESULT_OK) {
        // 画像選択をキャンセルした場合
        deletePhotoFile(context);
        filePathCallback.onReceiveValue(null);
        return;
    }
    if (intent != null) {
        // ギャラリーで選択した場合
        // 画像を1枚選択した場合、intent.getData()に選択した画像のURIが入ってくる
        Uri onlyOneSelectedImageUri = intent.getData();
        // 画像を複数枚選択した場合(複数枚選択モード時)、intent.getClipData()に複数枚選択した画像のURIが入ってくる
        ClipData multipleSelectedImageUriData = intent.getClipData();
        // 複数枚選択した場合、intent.getData()に画像URIが入ってくるので、先にintent.getClipData()を判定している
        if (multipleSelectedImageUriData != null) {
            final int selectedFilesCount = multipleSelectedImageUriData.getItemCount();
            Uri[] results = new Uri[selectedFilesCount];
            for (int i = 0; i < selectedFilesCount; i++) {
                results[i] = multipleSelectedImageUriData.getItemAt(i).getUri();
            }
            filePathCallback.onReceiveValue(results);
        } else if (onlyOneSelectedImageUri != null) {
            filePathCallback.onReceiveValue(new Uri[]{onlyOneSelectedImageUri});
        } else {
            receivePhotoFileForCamera(context);
        }
    } else {
        // https://stackoverflow.com/questions/12564112/android-camera-onactivityresult-intent-is-null-if-it-had-extras
        receivePhotoFileForCamera(context);
    }
    filePathCallback = null;
}
 
Example 9
Project: stynico   File: x5_MainActivity.java   View Source Code Vote up 6 votes
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
   private void onActivityResultAboveL(int requestCode, int resultCode, Intent intent)
{
       if (requestCode != FILE_CHOOSER_RESULT_CODE || uploadMessageAboveL == null)
           return;
       Uri[] results = null;
       if (resultCode == Activity.RESULT_OK)
	{
           if (intent != null)
		{
               String dataString = intent.getDataString();
               ClipData clipData = intent.getClipData();
               if (clipData != null)
			{
                   results = new Uri[clipData.getItemCount()];
                   for (int i = 0; i < clipData.getItemCount(); i++)
				{
                       ClipData.Item item = clipData.getItemAt(i);
                       results[i] = item.getUri();
                   }
               }
               if (dataString != null)
                   results = new Uri[]{Uri.parse(dataString)};
           }
       }
       uploadMessageAboveL.onReceiveValue(results);
       uploadMessageAboveL = null;
   }
 
Example 10
Project: buildAPKsSamples   File: ReceiveShare.java   View Source Code Vote up 6 votes
static Uri getShareUri(Intent intent) {
    Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
    if (uri == null) {
        ClipData clip = intent.getClipData();
        if (clip != null && clip.getItemCount() > 0) {
            uri = clip.getItemAt(0).getUri();
        }
    }
    return uri;
}
 
Example 11
Project: boohee_v5.6   File: RemoteInputCompatJellybean.java   View Source Code Vote up 6 votes
static Bundle getResultsFromIntent(Intent intent) {
    ClipData clipData = intent.getClipData();
    if (clipData == null) {
        return null;
    }
    ClipDescription clipDescription = clipData.getDescription();
    if (clipDescription.hasMimeType("text/vnd.android.intent") && clipDescription.getLabel().equals("android.remoteinput.results")) {
        return (Bundle) clipData.getItemAt(0).getIntent().getExtras().getParcelable("android.remoteinput.resultsData");
    }
    return null;
}
 
Example 12
Project: RxGallery   File: RxGalleryActivity.java   View Source Code Vote up 6 votes
private ArrayList<Uri> handleGallery(Intent data) {
    ArrayList<Uri> uris = new ArrayList<>();
    if (data.getData() != null) { // Single select
        uris.add(data.getData());
    } else { // Multi select
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            ClipData clipData = data.getClipData();
            for (int i = 0; i < clipData.getItemCount(); i++) {
                uris.add(clipData.getItemAt(i).getUri());
            }
        }
    }
    return uris;
}
 
Example 13
Project: react-native-udesk   File: UdeskWebChromeClient.java   View Source Code Vote up 6 votes
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void onActivityResultAboveL(int requestCode, int resultCode, Intent intent) {
    try {
        if (requestCode != FILE_CHOOSER_RESULT_CODE || uploadMessageAboveL == null){
            return;
        }
        Uri[] results = null;
        if (resultCode == Activity.RESULT_OK) {
            if (intent != null) {
                String dataString = intent.getDataString();
                ClipData clipData = intent.getClipData();
                if (clipData != null) {
                    results = new Uri[clipData.getItemCount()];
                    for (int i = 0; i < clipData.getItemCount(); i++) {
                        ClipData.Item item = clipData.getItemAt(i);
                        results[i] = item.getUri();
                    }
                }
                if (dataString != null)
                    results = new Uri[]{Uri.parse(dataString)};
            }
        }
        uploadMessageAboveL.onReceiveValue(results);
        uploadMessageAboveL = null;
    } catch (Exception e) {
        e.printStackTrace();
    }
}