Java Code Examples for android.content.Intent.ACTION_GET_CONTENT

The following are Jave code examples for showing how to use ACTION_GET_CONTENT 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: Quicksend   File: CVFragment.java   View Source Code Vote up 9 votes
private void chooseFile() {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        try {
            getActivity().startActivityForResult(
                    Intent.createChooser(intent, "Select a File to Upload"),
                    FILE_SELECT_CODE);

        } catch (android.content.ActivityNotFoundException ex) {
            // Potentially direct the user to the Market with a Dialog
            Toast.makeText(getActivity(), "Please install a File Manager.",
                    Toast.LENGTH_SHORT).show();
        }

//        Intent intent = new Intent(getActivity(), NormalFilePickActivity.class);
//        intent.putExtra(Constant.MAX_NUMBER, 1);
//        intent.putExtra(NormalFilePickActivity.SUFFIX, new String[] {"xlsx", "xls", "doc", "docx", "ppt", "pptx", "pdf"});
//        startActivityForResult(intent, Constant.REQUEST_CODE_PICK_FILE);


    }
 
Example 2
Project: AdaptiveTableLayout   File: CsvPickerFragment.java   View Source Code Vote up 8 votes
private void pickCsvFile() {

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);

        intent.setType("*/*");
        String[] mimetypes = {"text/comma-separated-values", "text/csv"};
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            intent.putExtra(EXTRA_MIME_TYPES, mimetypes);
        }

        startActivityForResult(Intent.createChooser(intent, getString(R.string.pick_file)), REQUEST_CODE_PICK_CSV);
    }
 
Example 3
Project: fruit   File: ObjectCardActivity.java   View Source Code Vote up 8 votes
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
{
    if (requestCode == MY_PERMISSIONS_REQUEST_CALL_PHONE2)
    {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
        {
            Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("image/*");
            startActivityForResult(intent,PICK_PHOTO);
        } else
        {
            // Permission Denied
            Toast.makeText(ObjectCardActivity.this, "Permission Denied", Toast.LENGTH_SHORT).show();
        }
    }
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
 
Example 4
Project: Camera-Roll-Android-App   File: IntentReceiver.java   View Source Code Vote up 8 votes
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    switch (getIntent().getAction()) {
        case "com.android.camera.action.REVIEW":
        case Intent.ACTION_VIEW:
            view(getIntent());
            this.finish();
            break;
        case Intent.ACTION_PICK:
            pick(getIntent());
            break;
        case Intent.ACTION_GET_CONTENT:
            pick(getIntent());
            break;
        case Intent.ACTION_EDIT:
            edit(getIntent());
            break;
        default:
            break;
    }
}
 
Example 5
Project: ElephantAsia   File: PhotoAppsAdapter.java   View Source Code Vote up 7 votes
public PhotoAppsAdapter(Context context, File captureFile, int captureCode, int importCode) {
  page = 0;
  this.context = context;
  this.captureFile = captureFile;
  this.captureCode = captureCode;
  this.importCode = importCode;
  packageManager = context.getPackageManager();

  Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", captureFile);
  captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
  //captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(captureFile));

  importIntent = new Intent(Intent.ACTION_GET_CONTENT);
  importIntent.setType("image/jpg");
  importList = packageManager.queryIntentActivities(importIntent, PackageManager.MATCH_DEFAULT_ONLY);
}
 
Example 6
Project: PreviewSeekBar   File: MainActivity.java   View Source Code Vote up 7 votes
@Override
public boolean onMenuItemClick(MenuItem item) {
    if (item.getItemId() == R.id.action_local) {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("video/*.mp4");
        startActivityForResult(intent, PICK_FILE_REQUEST_CODE);
    } else if (item.getItemId() == R.id.action_toggle) {
        if (previewTimeBarLayout.isShowingPreview()) {
            previewTimeBarLayout.hidePreview();
            exoPlayerManager.stopPreview();
        } else {
            previewTimeBarLayout.showPreview();
            exoPlayerManager.loadPreview(previewTimeBar.getProgress(),
                    previewTimeBar.getDuration());
        }
    } else {
        startActivity(new Intent(this, LocalActivity.class));
    }
    return true;
}
 
Example 7
Project: TripBuyer   File: SetActivity.java   View Source Code Vote up 7 votes
/**
     * 启动手机相册
     */
    private void fromGallery() {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("image/*");
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), IMAGE_NAME)));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            startActivityForResult(intent, GALLERY_KITKAT_REQUEST);
        } else {
            startActivityForResult(intent, GALLERY_REQUEST);
        }

//        Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//        intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
//        startActivityForResult(intent, 103);103
    }
 
Example 8
Project: MyFire   File: CaptureActivity.java   View Source Code Vote up 7 votes
@Override
public void onClick(View v) {
	final int id = v.getId();
	if(id==R.id.capture_scan_photo){
		// 打开手机中的相册
		Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT); // "android.intent.action.GET_CONTENT"
		innerIntent.setType("image/*");
		Intent wrapperIntent = Intent.createChooser(innerIntent,
				"选择二维码图片");
		this.startActivityForResult(wrapperIntent, REQUEST_CODE);
	}else if(id==R.id.capture_flashlight){
		if (isFlashlightOpen) {
			cameraManager.setTorch(false); // 关闭闪光灯
			isFlashlightOpen = false;
		}
		else {
			cameraManager.setTorch(true); // 打开闪光灯
			isFlashlightOpen = true;
		}
	}
}
 
Example 9
Project: Paper-Melody   File: UpdateUserInfoFragment.java   View Source Code Vote up 6 votes
private void chooseImg() {
    try {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("image/*");
        intent.putExtra("crop", true);
        intent.putExtra("return-data", true);
        startActivityForResult(intent, LOAD_PIC);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 10
Project: GitHub   File: MyWebChromeClient.java   View Source Code Vote up 6 votes
private void openFileChooserImplForAndroid5(ValueCallback<Uri[]> uploadMsg) {
    mUploadMessageForAndroid5 = uploadMsg;
    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
    contentSelectionIntent.setType("image/*");

    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
    chooserIntent.putExtra(Intent.EXTRA_TITLE, "图片选择");

    mActivity.startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE_FOR_ANDROID_5);
}
 
Example 11
Project: AndroidSdrRtlTuner   File: FileUtils.java   View Source Code Vote up 6 votes
/**
 * Get the Intent for selecting content to be used in an Intent Chooser.
 *
 * @return The intent for opening a file with Intent.createChooser()
 * @author paulburke
 */
public static Intent createGetContentIntent() {
	// Implicitly allow the user to select a particular kind of data
	final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
	// The MIME data type filter
	intent.setType("*/*");
	// Only return URIs that can be opened with ContentResolver
	intent.addCategory(Intent.CATEGORY_OPENABLE);
	return intent;
}
 
Example 12
Project: fruit   File: FruitCard.java   View Source Code Vote up 6 votes
public void openAlbumC(View v){
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED)
    {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                MY_PERMISSIONS_REQUEST_CALL_PHONE2);
    }
    else {
    Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    startActivityForResult(intent,PICK_PHOTO);}
}
 
Example 13
Project: MyDemo   File: MyWebChromeClient.java   View Source Code Vote up 6 votes
private void openFileChooserImplForAndroid5(ValueCallback<Uri[]> uploadMsg) {
    mUploadMessageForAndroid5 = uploadMsg;
    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
    contentSelectionIntent.setType("image/*");

    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
    chooserIntent.putExtra(Intent.EXTRA_TITLE, "图片选择");

    mActivity.startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE_FOR_ANDROID_5);
}
 
Example 14
Project: diary   File: Diary.java   View Source Code Vote up 6 votes
public void addMedia()
{
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(WILD_WILD);
    startActivityForResult(Intent.createChooser(intent, null), ADD_MEDIA);
}
 
Example 15
Project: CatchSpy   File: ImportMethod.java   View Source Code Vote up 5 votes
public static void selectFile(Activity mActivity, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("file/*");
    mActivity.startActivityForResult(intent, requestCode);
}
 
Example 16
Project: Kids-Portal-Android   File: Fragment_Browser.java   View Source Code Vote up 5 votes
public boolean onShowFileChooser(
        WebView webView, ValueCallback<Uri[]> filePathCallback,
        FileChooserParams fileChooserParams) {
    if (mFilePathCallback != null) {
        mFilePathCallback.onReceiveValue(null);
    }
    mFilePathCallback = filePathCallback;

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = helper_browser.createImageFile();
            takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
        } catch (IOException e) {
            // Error occurred while creating the File
            Log.e(TAG, "Unable to create Image File", e);
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
        } else {
            takePictureIntent = null;
        }
    }

    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
    contentSelectionIntent.setType("*/*");

    Intent[] intentArray;
    if (takePictureIntent != null) {
        intentArray = new Intent[]{takePictureIntent};
    } else {
        intentArray = new Intent[0];
    }

    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
    chooserIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.app_share_file));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

    startActivityForResult(chooserIntent, REQUEST_CODE_LOLLIPOP);

    return true;
}
 
Example 17
Project: Orin   File: AbsTagEditorActivity.java   View Source Code Vote up 5 votes
private void startImagePicker() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    startActivityForResult(Intent.createChooser(intent, getString(R.string.pick_from_local_storage)), REQUEST_CODE_SELECT_IMAGE);
}
 
Example 18
Project: quickblox-android   File: ImageUtils.java   View Source Code Vote up 5 votes
public static void startImagePicker(Activity activity) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType(MimeType.IMAGE_MIME);
    activity.startActivityForResult(Intent.createChooser(intent, activity.getString(R.string.dlg_choose_image_from)), GALLERY_REQUEST_CODE);
}
 
Example 19
Project: Xndroid   File: BrowserActivity.java   View Source Code Vote up 5 votes
@Override
public void showFileChooser(ValueCallback<Uri[]> filePathCallback) {
    if (mFilePathCallback != null) {
        mFilePathCallback.onReceiveValue(null);
    }
    mFilePathCallback = filePathCallback;

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(this.getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = Utils.createImageFile();
            takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
        } catch (IOException ex) {
            // Error occurred while creating the File
            Log.e(TAG, "Unable to create Image File", ex);
        }

        // Continue only if the File was successfully created
        if (photoFile != null) {
            mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
        } else {
            takePictureIntent = null;
        }
    }

    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
    contentSelectionIntent.setType("*/*");

    Intent[] intentArray;
    if (takePictureIntent != null) {
        intentArray = new Intent[]{takePictureIntent};
    } else {
        intentArray = new Intent[0];
    }

    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
    chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

    startActivityForResult(chooserIntent, 1);
}
 
Example 20
Project: AliZhiBoHao   File: WebActivity.java   View Source Code Vote up 5 votes
private void openImageChooserActivity() {
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("image/*");
    startActivityForResult(Intent.createChooser(i, "Image Chooser"), FILECHOOSER_RESULTCODE);
}