List of usage examples for android.content Intent setType
public @NonNull Intent setType(@Nullable String type)
From source file:com.snappy.CameraCropActivity.java
private void getImageIntents() { /*//from www. ja va2 s . c om * if (getIntent().hasExtra("trio")) { _trio = true; _groupId = * getIntent().getStringExtra("groupId"); _planner = * getIntent().getBooleanExtra("planner", false); } else { _trio = * false; _planner = false; _groupId = ""; } */ if (getIntent().getStringExtra("type").equals("gallery")) { //this is used to solve the selected path for android 19, kitkat o superior if (Build.VERSION.SDK_INT < 19) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); this.startActivityForResult(intent, GALLERY); } else { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); this.startActivityForResult(intent, GALLERY); } mIsCamera = false; } else { try { startCamera(); mIsCamera = true; } catch (UnsupportedOperationException ex) { ex.printStackTrace(); Toast.makeText(getBaseContext(), "UnsupportedOperationException", Toast.LENGTH_SHORT).show(); } } if (getIntent().getBooleanExtra("profile", false) == true) { mForProfile = true; } else { mForProfile = false; } if (getIntent().getBooleanExtra("createGroup", false) == true) { mForGroup = true; } else { mForGroup = false; } if (getIntent().getBooleanExtra("groupUpdate", false) == true) { mForGroupUpdate = true; } else { mForGroupUpdate = false; } }
From source file:com.zhihuigu.sosoOffice.RegisterThirdActivity.java
@Override public void onClick(View v) { if (v == backBtn) { Intent intent = new Intent(this, LoginActivity.class); startActivity(intent);//from www. ja v a 2s . c o m finish(); } else if (v == submitBtn) { if (textValidate()) { new Thread(runnable).start(); } } else if (v == linearGetImage) { int height = MyApplication.getInstance(this).getScreenHeight(); if (photo_tag) { shareBtn3.setVisibility(View.VISIBLE); if (height == 1280) { chazhi = 670; } else if (height == 800) { chazhi = 340; } else if (height == 960) { chazhi = 500; } else if (height == 854) { chazhi = 400; } else if (height == 480) { chazhi = 175; } } else { shareBtn3.setVisibility(View.GONE); if (height == 1280) { chazhi = 800; } else if (height == 800) { chazhi = 440; } else if (height == 960) { chazhi = 600; } else if (height == 854) { chazhi = 492; } else if (height == 480) { chazhi = 240; } } CommonUtils.hideSoftKeyboard(this);// new Thread(runnableForShowDialog).start(); } else if (v == shareBtn1) { dismiss(); Intent openCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); fileName = CommonUtils.getFileName(); MyApplication.getInstance(this).setFileName(fileName); File file = new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD); if (!file.exists()) { file.mkdirs(); } if (CommonUtils.isHasSdcard()) { openCamera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD, fileName))); } startActivityForResult(openCamera, REQUEST_CODE_TAKE_PICTURE); } else if (v == shareBtn2) { dismiss(); Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT); getAlbum.setType(IMAGE_TYPE); startActivityForResult(getAlbum, IMAGE_CODE); } else if (v == shareBtn3) { dismiss(); // Intent intent = new Intent(this,ImagePreViewActivity.class); // intent.putExtra("path", path); // startActivityForResult(intent, 6); ArrayList<String> al = new ArrayList<String>(); al.clear(); al.add(path); Intent it = new Intent(this, ImageSwitcher.class); it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); it.putStringArrayListExtra("pathes", al); it.putExtra("index", 0); startActivity(it); } else if (v == cancleBtn) { dismiss(); } super.onClick(v); }
From source file:com.example.zf_android.activity.MerchantEdit.java
private void show3Dialog(int type, final String uri) { AlertDialog.Builder builder = new AlertDialog.Builder(MerchantEdit.this); final String[] items = getResources().getStringArray(R.array.apply_detail_view); MerchantEdit.this.type = type; builder.setItems(items, new DialogInterface.OnClickListener() { @Override/*from w w w.j a v a 2 s . co m*/ public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: { AlertDialog.Builder build = new AlertDialog.Builder(MerchantEdit.this); LayoutInflater factory = LayoutInflater.from(MerchantEdit.this); final View textEntryView = factory.inflate(R.layout.show_view, null); build.setView(textEntryView); final ImageView view = (ImageView) textEntryView.findViewById(R.id.imag); // ImageCacheUtil.IMAGE_CACHE.get(uri, view); ImageLoader.getInstance().displayImage(uri, view, options); build.create().show(); break; } case 1: { Intent intent; if (Build.VERSION.SDK_INT < 19) { intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); } else { intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); } startActivityForResult(intent, REQUEST_UPLOAD_IMAGE); break; } case 2: { String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File outDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); if (!outDir.exists()) { outDir.mkdirs(); } File outFile = new File(outDir, System.currentTimeMillis() + ".jpg"); photoPath = outFile.getAbsolutePath(); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outFile)); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); startActivityForResult(intent, REQUEST_TAKE_PHOTO); } else { CommonUtil.toastShort(MerchantEdit.this, getString(R.string.toast_no_sdcard)); } break; } } } }); builder.show(); }
From source file:com.abc.driver.TruckActivity.java
private void doCrop() { Log.d(TAG, "doCrop()"); final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>(); Intent intent = new Intent("com.android.camera.action.CROP"); intent.setType("image/*"); List<ResolveInfo> list = this.getPackageManager().queryIntentActivities(intent, 0); int size = list.size(); if (size == 0) { Log.d(TAG, " Crop activity is not found. List size is zero."); Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null); trcukLicenseBmp = Bitmap.createScaledBitmap(tmpBmp, IMAGE_WIDTH, IMAGE_HEIGHT, false); mTLPiv.setImageBitmap(trcukLicenseBmp); isPortraitChanged = true;/* w w w .jav a2 s .c om*/ Log.d(TAG, "set bitmap"); return; } else { Log.d(TAG, "found the crop activity."); intent.setData(imageUri); intent.putExtra("outputX", IMAGE_WIDTH); intent.putExtra("outputY", IMAGE_HEIGHT); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("scale", true); intent.putExtra("return-data", true); if (size == 1) { Log.d(TAG, "Just one as choose it as crop activity."); Intent i = new Intent(intent); ResolveInfo res = list.get(0); i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); startActivityForResult(i, CellSiteConstants.CROP_PICTURE); } else { Log.d(TAG, "More that one activity for crop is found . will chooose one"); for (ResolveInfo res : list) { final CropOption co = new CropOption(); co.title = getPackageManager().getApplicationLabel(res.activityInfo.applicationInfo); co.icon = getPackageManager().getApplicationIcon(res.activityInfo.applicationInfo); co.appIntent = new Intent(intent); co.appIntent .setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); cropOptions.add(co); } CropOptionAdapter adapter = new CropOptionAdapter(getApplicationContext(), cropOptions); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Choose Crop App"); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { startActivityForResult(cropOptions.get(item).appIntent, CellSiteConstants.CROP_PICTURE); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { // @Override public void onCancel(DialogInterface dialog) { if (imageUri != null) { getContentResolver().delete(imageUri, null, null); imageUri = null; isPortraitChanged = false; } } }); AlertDialog alert = builder.create(); alert.show(); } } }
From source file:com.farmerbb.notepad.fragment.NoteListFragment.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override//from w ww. j ava 2 s.c o m public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_start_selection: listener.startMultiSelect(); return true; case R.id.action_settings: Intent intentSettings = new Intent(getActivity(), SettingsActivity.class); startActivity(intentSettings); return true; case R.id.action_import: Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "text/plain", "text/html", "text/x-markdown" }); intent.setType("*/*"); try { getActivity().startActivityForResult(intent, MainActivity.IMPORT); } catch (ActivityNotFoundException e) { showToast(R.string.error_importing_notes); } return true; case R.id.action_about: DialogFragment aboutFragment = new AboutDialogFragment(); aboutFragment.show(getFragmentManager(), "about"); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.google.zxing.client.android.result.ResultHandler.java
final void sendEmailFromUri(String uri, String email, String subject, String body) { Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse(uri)); if (email != null) { intent.putExtra(Intent.EXTRA_EMAIL, new String[] { email }); }//from w ww. ja v a 2 s.c om putExtra(intent, Intent.EXTRA_SUBJECT, subject); putExtra(intent, Intent.EXTRA_TEXT, body); intent.setType("text/plain"); launchIntent(intent); }
From source file:com.MustacheMonitor.MustacheMonitor.StacheCam.java
/** * Get image from photo library./*from www .j ava 2 s .c o m*/ * * @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality) * @param srcType The album to get image from. * @param returnType Set the type of image to return. */ // TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do! public void getImage(int srcType, int returnType) { Intent intent = new Intent(); String title = GET_PICTURE; if (this.mediaType == PICTURE) { intent.setType("image/*"); } else if (this.mediaType == VIDEO) { intent.setType("video/*"); title = GET_VIDEO; } else if (this.mediaType == ALLMEDIA) { // I wanted to make the type 'image/*, video/*' but this does not work on all versions // of android so I had to go with the wildcard search. intent.setType("*/*"); title = GET_All; } intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); if (this.cordova != null) { this.cordova.startActivityForResult((Plugin) this, Intent.createChooser(intent, new String(title)), (srcType + 1) * 16 + returnType + 1); } }
From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java
private void addImage() { // when clicking attack the user should at first select an application to // choose the image with and then choose an image. // this intent is for getting the image Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT); getIntent.setType("image/*"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) getIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); // and this for getting the application to get the image with Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); pickIntent.setType("image/*"); // and this finally is for opening the chooserIntent for opening the // getIntent for returning the image uri. Yep, thanks android Intent chooserIntent = Intent.createChooser(getIntent, getResources().getString(R.string.select_image)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { pickIntent }); startActivityForResult(chooserIntent, ADD_PHOTO_CLICKED); // nope I don't want to be asked for a pwd when selected the image getActivity().getSharedPreferences(Constants.PREFERENCES, 0).edit().putBoolean(Constants.PWD_REQUEST, false) .apply();/* w w w . jav a2 s .c om*/ }
From source file:com.grass.caishi.cc.activity.AdAddActivity.java
/** * ?//from ww w.j ava 2 s.c o m */ public void selectPicFromLocal() { Intent intent; if (Build.VERSION.SDK_INT < 19) { intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); } else { intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); } startActivityForResult(intent, REQUEST_CODE_IMAGES); }
From source file:com.xorcode.andtweet.TweetListActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { super.onContextItemSelected(item); AdapterView.AdapterContextMenuInfo info; try {// w ww . j av a 2 s. com info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); } catch (ClassCastException e) { Log.e(TAG, "bad menuInfo", e); return false; } mCurrentId = info.id; Uri uri; Cursor c; switch (item.getItemId()) { case CONTEXT_MENU_ITEM_REPLY: uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id); c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID }, null, null, null); try { c.moveToFirst(); String reply = "@" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)) + " "; long replyId = c.getLong(c.getColumnIndex(Tweets._ID)); mTweetEditor.startEditing(reply, replyId); } catch (Exception e) { Log.e(TAG, "onContextItemSelected: " + e.toString()); return false; } finally { if (c != null && !c.isClosed()) c.close(); } return true; case CONTEXT_MENU_ITEM_RETWEET: uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id); c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID, Tweets.MESSAGE }, null, null, null); try { c.moveToFirst(); StringBuilder message = new StringBuilder(); String reply = "RT @" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)) + " "; message.append(reply); CharSequence text = c.getString(c.getColumnIndex(Tweets.MESSAGE)); int len = 140 - reply.length() - 3; if (text.length() < len) { len = text.length(); } message.append(text, 0, len); if (message.length() == 137) { message.append("..."); } mTweetEditor.startEditing(message.toString(), 0); } catch (Exception e) { Log.e(TAG, "onContextItemSelected: " + e.toString()); return false; } finally { if (c != null && !c.isClosed()) c.close(); } return true; case CONTEXT_MENU_ITEM_DESTROY_STATUS: sendCommand(new CommandData(CommandEnum.DESTROY_STATUS, mCurrentId)); return true; case CONTEXT_MENU_ITEM_FAVORITE: sendCommand(new CommandData(CommandEnum.CREATE_FAVORITE, mCurrentId)); return true; case CONTEXT_MENU_ITEM_DESTROY_FAVORITE: sendCommand(new CommandData(CommandEnum.DESTROY_FAVORITE, mCurrentId)); return true; case CONTEXT_MENU_ITEM_SHARE: uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id); c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID, Tweets.MESSAGE }, null, null, null); try { c.moveToFirst(); StringBuilder subject = new StringBuilder(); StringBuilder text = new StringBuilder(); String message = c.getString(c.getColumnIndex(Tweets.MESSAGE)); subject.append(getText(R.string.button_create_tweet)); subject.append(" - " + message); int maxlength = 80; if (subject.length() > maxlength) { subject.setLength(maxlength); // Truncate at the last space subject.setLength(subject.lastIndexOf(" ")); subject.append("..."); } text.append(message); text.append("\n-- \n" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID))); text.append("\n URL: " + "http://twitter.com/" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)) + "/status/" + c.getString(c.getColumnIndex(Tweets._ID))); Intent share = new Intent(android.content.Intent.ACTION_SEND); share.setType("text/plain"); share.putExtra(Intent.EXTRA_SUBJECT, subject.toString()); share.putExtra(Intent.EXTRA_TEXT, text.toString()); startActivity(Intent.createChooser(share, getText(R.string.menu_item_share))); } catch (Exception e) { Log.e(TAG, "onContextItemSelected: " + e.toString()); return false; } finally { if (c != null && !c.isClosed()) c.close(); } return true; case CONTEXT_MENU_ITEM_UNFOLLOW: case CONTEXT_MENU_ITEM_BLOCK: case CONTEXT_MENU_ITEM_DIRECT_MESSAGE: case CONTEXT_MENU_ITEM_PROFILE: Toast.makeText(this, R.string.unimplemented, Toast.LENGTH_SHORT).show(); return true; } return false; }