List of usage examples for android.content Intent setDataAndType
public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type)
From source file:com.example.shinelon.ocrcamera.MainActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { //???//from w w w. java2 s . c o m case REQUEST_CAMERA: if (resultCode == RESULT_OK) { //?????? Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(mUri, "image/*"); intent.putExtra(MediaStore.EXTRA_OUTPUT, mUri); startActivityForResult(intent, CAMERA_CROP); } break; //?? case CAMERA_CROP: if (resultCode == RESULT_OK) { setImage(mUri); mCropButton.setEnabled(true); } break; case SELECT: if (data != null) { Uri uri = data.getData(); crop(uri); } break; case CROP: break; default: break; } }
From source file:com.example.de.taomi2.mediachooser.fragment.ImageFragment.java
private void setAdapter(Cursor imagecursor) { if (imagecursor.getCount() > 0) { mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < imagecursor.getCount(); i++) { imagecursor.moveToPosition(i); int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); MediaModel galleryModel = new MediaModel(imagecursor.getString(dataColumnIndex).toString(), false); mGalleryModelList.add(galleryModel); }//from w w w.jav a 2 s. co m mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false); mImageGridView.setAdapter(mImageAdapter); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } mImageGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/*"); startActivity(intent); return true; } }); mImageGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), false); if (size != 0) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.file_size_exeeded) + " " + MediaChooserConstants.SELECTED_IMAGE_SIZE_IN_MB + " " + getActivity().getResources().getString(R.string.mb), Toast.LENGTH_SHORT).show(); return; } /* if((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)){ if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show(); return; } } */ } /* // inverse the status galleryModel.status = ! galleryModel.status; adapter.notifyDataSetChanged(); */ int i = 0; for (; i < adapter.getCount(); i++) { if (i != position) { adapter.getItem(i).status = false; } } galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); mSelectedItems.clear(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); //MediaChooserConstants.SELECTED_MEDIA_COUNT ++; } else { //mSelectedItems.remove(galleryModel.url.toString().trim()); //MediaChooserConstants.SELECTED_MEDIA_COUNT --; } if (mCallback != null) { mCallback.onImageSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VideoObj.java
private void startViewer(Context context, Uri contentUri) { Log.d(TAG, "Launching viewer for " + contentUri); Intent i = new Intent(Intent.ACTION_VIEW); if (!(context instanceof Activity)) { i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); }/*from w w w .j a va 2s . co m*/ i.setDataAndType(contentUri, "video/*"); context.startActivity(i); }
From source file:com.mercandalli.android.apps.files.file.image.FileImageActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_file_picture); final Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar); if (toolbar != null) { setSupportActionBar(toolbar);//from www. j a v a2s .c o m ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } } // Translucent notification bar getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); // Get views mProgressBar = (ProgressBar) this.findViewById(R.id.progressBar); mCircle = (ImageButton) this.findViewById(R.id.circle); mTitleTextView = (TextView) this.findViewById(R.id.title); mProgressTextView = (TextView) this.findViewById(R.id.progress_tv); mProgressBar.setProgress(0); Bundle extras = getIntent().getExtras(); if (extras == null) { Log.e("" + getClass().getName(), "extras == null"); finish(); overridePendingTransition(R.anim.right_in, R.anim.right_out); return; } else { mId = extras.getInt("ID"); mTitle = extras.getString("TITLE"); mUrl = extras.getString("URL_FILE"); online = extras.getBoolean("CLOUD"); sizeFile = extras.getLong("SIZE_FILE"); date_creation = (Date) extras.getSerializable("DATE_FILE"); if (mTitle != null) { mTitleTextView.setText(mTitle); } if (ImageUtils.isImage(this, this.mId)) { mBitmap = ImageUtils.loadImage(this, this.mId); ((ImageView) this.findViewById(R.id.tab_icon)).setImageBitmap(mBitmap); int bgColor = ColorUtils.getMutedColor(mBitmap); if (bgColor != 0) { mTitleTextView.setBackgroundColor(bgColor); mTitleTextView.setTextColor(ColorUtils.colorText(bgColor)); RippleDrawable cir = ImageUtils.getPressedColorRippleDrawable(bgColor, ColorUtils.getDarkMutedColor(mBitmap)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mCircle.setBackground(cir); } } mProgressBar.setVisibility(View.GONE); mProgressTextView.setVisibility(View.GONE); } else if (this.mId != 0) { mProgressBar.setVisibility(View.VISIBLE); mProgressTextView.setVisibility(View.VISIBLE); (new TaskGetDownloadImage(this, mUrl, mId, sizeFile, -1, new IBitmapListener() { @Override public void execute(Bitmap bitmap) { ((ImageView) findViewById(R.id.tab_icon)).setImageBitmap(bitmap); int bgColor = ColorUtils.getMutedColor(bitmap); if (bgColor != 0) { mTitleTextView.setBackgroundColor(bgColor); mTitleTextView.setTextColor(ColorUtils.colorText(bgColor)); RippleDrawable cir = ImageUtils.getPressedColorRippleDrawable(bgColor, ColorUtils.getDarkMutedColor(bitmap)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mCircle.setBackground(cir); } } mProgressBar.setVisibility(View.GONE); mProgressTextView.setVisibility(View.GONE); } }, new ILongListener() { @Override public void execute(long text) { mProgressBar.setProgress((int) text); mProgressTextView.setText(text + "%"); } })).execute(); } } mCircle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent picIntent = new Intent(); picIntent.setAction(Intent.ACTION_VIEW); picIntent.setDataAndType(Uri.parse("file://" + (new File(FileImageActivity.this.getFilesDir() + "/file_" + mId)).getAbsolutePath()), "image/*"); FileImageActivity.this.startActivity(picIntent); } }); }
From source file:de.nico.asura.Main.java
private void setList() { ListView list = (ListView) findViewById(R.id.listView_main); ListAdapter adapter = new SimpleAdapter(this, downloadList, android.R.layout.simple_list_item_1, new String[] { TAG_NAME }, new int[] { android.R.id.text1 }); list.setAdapter(adapter);//from w w w. j ava 2s . c om // Do nothing when there is no Internet if (!(Utils.isNetworkAvailable(this))) { return; } // React when user click on item in the list list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int pos, long id) { Uri downloadUri = Uri.parse(downloadList.get(pos).get(TAG_URL)); String title = downloadList.get(pos).get(TAG_NAME); file = new File(Environment.getExternalStorageDirectory() + "/" + localLoc + "/" + downloadList.get(pos).get(TAG_FILENAME) + ".pdf"); Uri dest = Uri.fromFile(file); if (file.exists()) { Intent pdfIntent = new Intent(Intent.ACTION_VIEW); pdfIntent.setDataAndType(dest, "application/pdf"); pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(pdfIntent); } catch (ActivityNotFoundException e) { Utils.makeLongToast(Main.this, noPDF); Log.e("ActivityNotFoundException", e.toString()); } return; } // Download PDF Request request = new Request(downloadUri); request.setTitle(title).setDestinationUri(dest); downloadID = downloadManager.enqueue(request); } }); }
From source file:com.filepager.afilechooser.FileListFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { // TODO Auto-generated method stub AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); FileListAdapter adapter = (FileListAdapter) getListView().getAdapter(); File file = (File) adapter.getItem(info.position); switch (item.getItemId()) { case 0:/*ww w.j av a 2 s . co m*/ if (adapter != null) { FilesHolder fh = adapter.getFH(); mPath = file.getAbsolutePath(); ((FileChooserActivity) getActivity()).onFileSelected(file); } break; case 1: Intent intent123 = new Intent(Intent.ACTION_VIEW); intent123.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri123 = Uri.fromFile(file); intent123.setDataAndType(uri123, Utils.getMimeType(file.getAbsolutePath())); try { getActivity().startActivity(intent123); } catch (Exception e) { Toast.makeText(getActivity(), R.string.file_type_not_supported, Toast.LENGTH_SHORT).show(); } break; default: break; } return super.onContextItemSelected(item); }
From source file:com.itbooks.app.activities.BaseActivity.java
/** * Handler for {@link com.itbooks.bus.DownloadOpenEvent}. * * @param e/*from w ww. j av a 2 s . c om*/ * Event {@link com.itbooks.bus.DownloadOpenEvent}. */ public void onEvent(DownloadOpenEvent e) { File pdf = e.getFile(); try { Intent openFileIntent = new Intent(Intent.ACTION_VIEW); openFileIntent.setDataAndType(Uri.fromFile(pdf), "application/pdf"); openFileIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(openFileIntent); } catch (Exception ex) { //Download pdf-reader. showDialogFragment(new DialogFragment() { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( getActivity()); builder.setTitle(R.string.application_name).setMessage(R.string.msg_no_reader) .setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String pdfReader = "com.adobe.reader"; try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pdfReader))); } catch (android.content.ActivityNotFoundException exx) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "https://play.google.com/store/apps/details?id=" + pdfReader))); } } }).setNegativeButton(R.string.btn_not_yet_load, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User cancelled the dialog } }); // Create the AlertDialog object and return it return builder.create(); } }, null); } }
From source file:com.firesoft.member.Activity.F9_SettingActivity.java
private String startPhotoZoom(Uri uri) { if (mFileZoomDir == null) { mFileZoomDir = new File(MemberAppConst.FILEPATH + "img/"); if (!mFileZoomDir.exists()) { mFileZoomDir.mkdirs();//from w w w .j av a2s . co m } } String fileName; fileName = "/temp.jpg"; String filePath = mFileZoomDir + fileName; File loadingFile = new File(filePath); Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); intent.putExtra("crop", "true"); intent.putExtra("aspectX", 400); intent.putExtra("aspectY", 400); intent.putExtra("output", Uri.fromFile(loadingFile));// intent.putExtra("outputFormat", "PNG");// ? intent.putExtra("noFaceDetection", true); // ? intent.putExtra("return-data", false); // ??Intent startActivityForResult(intent, REQUEST_PHOTOZOOM); return filePath; }
From source file:com.insthub.O2OMobile.Activity.F9_SettingActivity.java
private String startPhotoZoom(Uri uri) { if (mFileZoomDir == null) { mFileZoomDir = new File(O2OMobileAppConst.FILEPATH + "img/"); if (!mFileZoomDir.exists()) { mFileZoomDir.mkdirs();/* w w w . j ava2s .c o m*/ } } String fileName; fileName = "/temp.jpg"; String filePath = mFileZoomDir + fileName; File loadingFile = new File(filePath); Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); intent.putExtra("crop", "true"); intent.putExtra("aspectX", 400); intent.putExtra("aspectY", 400); intent.putExtra("output", Uri.fromFile(loadingFile));// intent.putExtra("outputFormat", "PNG");// ? intent.putExtra("noFaceDetection", true); // ? intent.putExtra("return-data", false); // ??Intent startActivityForResult(intent, REQUEST_PHOTOZOOM); return filePath; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.MusicObj.java
@Override public void activate(Context context, SignedObj obj) { JSONObject content = obj.getJson();//from w ww. j a va2s . c o m if (content.has(URL)) { Intent view = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse(content.optString(URL)); String type = "audio/x-mpegurl"; if (content.has(MIME_TYPE)) { type = content.optString(MIME_TYPE); } view.setDataAndType(uri, type); if (!(context instanceof Activity)) { view.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } context.startActivity(view); } }