List of usage examples for android.content Intent setDataAndType
public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type)
From source file:com.bwash.bwashcar.activities.CompanyActivity.java
private void pickFromGallery() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestPermission(Manifest.permission.READ_EXTERNAL_STORAGE, getString(R.string.permission_read_storage_rationale), REQUEST_STORAGE_READ_ACCESS_PERMISSION); } else {/*from w w w . j a v a2 s . c o m*/ // Intent intent = new Intent(); // intent.setType("image/*"); // intent.setAction(Intent.ACTION_GET_CONTENT); // intent.addCategory(Intent.CATEGORY_OPENABLE); // startActivityForResult(Intent.createChooser(intent, getString(R.string.label_select_picture)), REQUEST_SELECT_PICTURE); mSelectPicturePopupWindow.dismissPopupWindow(); Intent pickIntent = new Intent(Intent.ACTION_PICK, null); // ???"image/jpeg ? image/png" pickIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); startActivityForResult(pickIntent, GALLERY_REQUEST_CODE); } }
From source file:babybear.akbquiz.ConfigActivity.java
/** * ?//from w ww.j ava 2s.co m */ void update() { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory(), APP_SAVENAME)), "application/vnd.android.package-archive"); startActivity(intent); }
From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java
public static void launchSMB(final SmbFile smbFile, final long si, final Activity activity) { final Streamer s = Streamer.getInstance(); new Thread() { public void run() { try { /*/*w ww.ja va2 s .co m*/ List<SmbFile> subtitleFiles = new ArrayList<SmbFile>(); // finding subtitles for (Layoutelements layoutelement : LIST_ELEMENTS) { SmbFile smbFile = new SmbFile(layoutelement.getDesc()); if (smbFile.getName().contains(smbFile.getName())) subtitleFiles.add(smbFile); } */ s.setStreamSrc(smbFile, si); activity.runOnUiThread(new Runnable() { public void run() { try { Uri uri = Uri.parse(Streamer.URL + Uri.fromFile(new File(Uri.parse(smbFile.getPath()).getPath())) .getEncodedPath()); Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(uri, MimeTypes.getMimeType(new File(smbFile.getPath()))); PackageManager packageManager = activity.getPackageManager(); List<ResolveInfo> resInfos = packageManager.queryIntentActivities(i, 0); if (resInfos != null && resInfos.size() > 0) activity.startActivity(i); else Toast.makeText(activity, activity.getResources().getString(R.string.smb_launch_error), Toast.LENGTH_SHORT).show(); } catch (ActivityNotFoundException e) { e.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); } } }.start(); }
From source file:com.giovanniterlingen.windesheim.controllers.DownloadController.java
@Override protected void onPostExecute(final String result) { activeDownloads.remove(contentId);/*from w w w . j a v a 2s . c o m*/ NotificationCenter.getInstance().removeObserver(this, NotificationCenter.downloadCancelled); NotificationCenter.getInstance().postNotificationName(NotificationCenter.downloadFinished, studyRouteId, adapterPosition, contentId); if ("permission".equals(result)) { ((NatschoolActivity) activity).noPermission(); return; } if ("cancelled".equals(result)) { ((NatschoolActivity) activity).downloadCanceled(); return; } if (result != null) { Uri uri; Intent target = new Intent(Intent.ACTION_VIEW); if (android.os.Build.VERSION.SDK_INT >= 24) { uri = FileProvider.getUriForFile(activity, "com.giovanniterlingen.windesheim.provider", new File(result)); target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { uri = Uri.fromFile(new File(result)); target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); } String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(uri.toString()); String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); target.setDataAndType(uri, mimetype); try { activity.startActivity(target); } catch (ActivityNotFoundException e) { ((NatschoolActivity) activity).noSupportedApp(); } } }
From source file:in.neoandroid.neoupdate.neoUpdate.java
private void startUpdateApk(Uri installerUri) { MimeTypeMap myMime = MimeTypeMap.getSingleton(); String mimeType = myMime.getMimeTypeFromExtension("apk"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(installerUri, mimeType);//"application/vnd.android.package-archive"); context.startActivity(intent);/*from www . j a v a2 s . c o m*/ }
From source file:ch.fixme.status.Main.java
private void populateDataHs() { try {//from w w w . j a v a 2 s .c o m HashMap<String, Object> data = new ParseGeneric(mResultHs).getData(); // Initialize views LayoutInflater inflater = getLayoutInflater(); LinearLayout vg = (LinearLayout) inflater.inflate(R.layout.base, null); ScrollView scroll = (ScrollView) findViewById(R.id.scroll); scroll.removeAllViews(); scroll.addView(vg); // Mandatory fields ((TextView) findViewById(R.id.space_name)).setText((String) data.get(ParseGeneric.API_NAME)); ((TextView) findViewById(R.id.space_url)).setText((String) data.get(ParseGeneric.API_URL)); getImageTask = new GetImage(R.id.space_image); getImageTask.execute((String) data.get(ParseGeneric.API_LOGO)); // Status text String status_txt = ""; if ((Boolean) data.get(ParseGeneric.API_STATUS)) { status_txt = OPEN; ((TextView) findViewById(R.id.status_txt)) .setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.presence_online, 0, 0, 0); } else { status_txt = CLOSED; ((TextView) findViewById(R.id.status_txt)) .setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.presence_busy, 0, 0, 0); } if (data.containsKey(ParseGeneric.API_STATUS_TXT)) { status_txt += ": " + (String) data.get(ParseGeneric.API_STATUS_TXT); } ((TextView) findViewById(R.id.status_txt)).setText(status_txt); // Status last change if (data.containsKey(ParseGeneric.API_LASTCHANGE)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setAutoLinkMask(0); tv.setText( getString(R.string.api_lastchange) + " " + (String) data.get(ParseGeneric.API_LASTCHANGE)); vg.addView(tv); } // Status duration if (data.containsKey(ParseGeneric.API_EXT_DURATION) && (Boolean) data.get(ParseGeneric.API_STATUS)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText(getString(R.string.api_duration) + " " + (String) data.get(ParseGeneric.API_EXT_DURATION) + getString(R.string.api_duration_hours)); vg.addView(tv); } // Location Pattern ptn = Pattern.compile("^.*$", Pattern.DOTALL); if (data.containsKey(ParseGeneric.API_ADDRESS) || data.containsKey(ParseGeneric.API_LON)) { TextView title = (TextView) inflater.inflate(R.layout.title, null); title.setText(getString(R.string.api_location)); vg.addView(title); inflater.inflate(R.layout.separator, vg); // Address if (data.containsKey(ParseGeneric.API_ADDRESS)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setAutoLinkMask(0); tv.setText((String) data.get(ParseGeneric.API_ADDRESS)); Linkify.addLinks(tv, ptn, MAP_SEARCH); vg.addView(tv); } // Lon/Lat if (data.containsKey(ParseGeneric.API_LON) && data.containsKey(ParseGeneric.API_LAT)) { String addr = (data.containsKey(ParseGeneric.API_ADDRESS)) ? (String) data.get(ParseGeneric.API_ADDRESS) : getString(R.string.empty); TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setAutoLinkMask(0); tv.setText((String) data.get(ParseGeneric.API_LON) + ", " + (String) data.get(ParseGeneric.API_LAT)); Linkify.addLinks(tv, ptn, String.format(MAP_COORD, (String) data.get(ParseGeneric.API_LAT), (String) data.get(ParseGeneric.API_LON), addr)); vg.addView(tv); } } // Contact if (data.containsKey(ParseGeneric.API_PHONE) || data.containsKey(ParseGeneric.API_TWITTER) || data.containsKey(ParseGeneric.API_IRC) || data.containsKey(ParseGeneric.API_EMAIL) || data.containsKey(ParseGeneric.API_ML)) { TextView title = (TextView) inflater.inflate(R.layout.title, null); title.setText(R.string.api_contact); vg.addView(title); inflater.inflate(R.layout.separator, vg); // Phone if (data.containsKey(ParseGeneric.API_PHONE)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText((String) data.get(ParseGeneric.API_PHONE)); vg.addView(tv); } // SIP if (data.containsKey(ParseGeneric.API_SIP)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText((String) data.get(ParseGeneric.API_SIP)); vg.addView(tv); } // Twitter if (data.containsKey(ParseGeneric.API_TWITTER)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText(TWITTER + (String) data.get(ParseGeneric.API_TWITTER)); vg.addView(tv); } // Identica if (data.containsKey(ParseGeneric.API_IDENTICA)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText((String) data.get(ParseGeneric.API_IDENTICA)); vg.addView(tv); } // Foursquare if (data.containsKey(ParseGeneric.API_FOURSQUARE)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText(FOURSQUARE + (String) data.get(ParseGeneric.API_FOURSQUARE)); vg.addView(tv); } // IRC if (data.containsKey(ParseGeneric.API_IRC)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setAutoLinkMask(0); tv.setText((String) data.get(ParseGeneric.API_IRC)); vg.addView(tv); } // Email if (data.containsKey(ParseGeneric.API_EMAIL)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText((String) data.get(ParseGeneric.API_EMAIL)); vg.addView(tv); } // Jabber if (data.containsKey(ParseGeneric.API_JABBER)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText((String) data.get(ParseGeneric.API_JABBER)); vg.addView(tv); } // Mailing-List if (data.containsKey(ParseGeneric.API_ML)) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText((String) data.get(ParseGeneric.API_ML)); vg.addView(tv); } } // Sensors if (data.containsKey(ParseGeneric.API_SENSORS)) { // Title TextView title = (TextView) inflater.inflate(R.layout.title, null); title.setText(getString(R.string.api_sensors)); vg.addView(title); inflater.inflate(R.layout.separator, vg); HashMap<String, ArrayList<HashMap<String, String>>> sensors = (HashMap<String, ArrayList<HashMap<String, String>>>) data .get(ParseGeneric.API_SENSORS); Set<String> names = sensors.keySet(); Iterator<String> it = names.iterator(); while (it.hasNext()) { String name = it.next(); // Subtitle String name_title = name.toLowerCase().replace("_", " "); name_title = name_title.substring(0, 1).toUpperCase() + name_title.substring(1, name_title.length()); TextView subtitle = (TextView) inflater.inflate(R.layout.subtitle, null); subtitle.setText(name_title); vg.addView(subtitle); // Sensors data ArrayList<HashMap<String, String>> sensorsData = sensors.get(name); for (HashMap<String, String> elem : sensorsData) { RelativeLayout rl = (RelativeLayout) inflater.inflate(R.layout.entry_sensor, null); if (elem.containsKey(ParseGeneric.API_VALUE)) { ((TextView) rl.findViewById(R.id.entry_value)) .setText(elem.get(ParseGeneric.API_VALUE)); } else { rl.findViewById(R.id.entry_value).setVisibility(View.GONE); } if (elem.containsKey(ParseGeneric.API_UNIT)) { ((TextView) rl.findViewById(R.id.entry_unit)).setText(elem.get(ParseGeneric.API_UNIT)); } else { rl.findViewById(R.id.entry_unit).setVisibility(View.GONE); } if (elem.containsKey(ParseGeneric.API_NAME2)) { ((TextView) rl.findViewById(R.id.entry_name)).setText(elem.get(ParseGeneric.API_NAME2)); } else { rl.findViewById(R.id.entry_name).setVisibility(View.GONE); } if (elem.containsKey(ParseGeneric.API_LOCATION2)) { ((TextView) rl.findViewById(R.id.entry_location)) .setText(elem.get(ParseGeneric.API_LOCATION2)); } else { rl.findViewById(R.id.entry_location).setVisibility(View.GONE); } if (elem.containsKey(ParseGeneric.API_DESCRIPTION)) { ((TextView) rl.findViewById(R.id.entry_description)) .setText(elem.get(ParseGeneric.API_DESCRIPTION)); } else { rl.findViewById(R.id.entry_description).setVisibility(View.GONE); } if (elem.containsKey(ParseGeneric.API_PROPERTIES)) { ((TextView) rl.findViewById(R.id.entry_properties)) .setText(elem.get(ParseGeneric.API_PROPERTIES)); } else { rl.findViewById(R.id.entry_properties).setVisibility(View.GONE); } if (elem.containsKey(ParseGeneric.API_MACHINES)) { ((TextView) rl.findViewById(R.id.entry_other)) .setText(elem.get(ParseGeneric.API_MACHINES)); } else if (elem.containsKey(ParseGeneric.API_NAMES)) { ((TextView) rl.findViewById(R.id.entry_other)) .setText(elem.get(ParseGeneric.API_NAMES)); } else { rl.findViewById(R.id.entry_other).setVisibility(View.GONE); } vg.addView(rl); } } } // Stream and cam if (data.containsKey(ParseGeneric.API_STREAM) || data.containsKey(ParseGeneric.API_CAM)) { TextView title = (TextView) inflater.inflate(R.layout.title, null); title.setText(getString(R.string.api_stream)); vg.addView(title); inflater.inflate(R.layout.separator, vg); // Stream if (data.containsKey(ParseGeneric.API_STREAM)) { HashMap<String, String> stream = (HashMap<String, String>) data.get(ParseGeneric.API_STREAM); for (Entry<String, String> entry : stream.entrySet()) { final String type = entry.getKey(); final String url = entry.getValue(); TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText(url); tv.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.parse(url), type); startActivity(i); } }); vg.addView(tv); } } // Cam if (data.containsKey(ParseGeneric.API_CAM)) { HashMap<String, String> cam = (HashMap<String, String>) data.get(ParseGeneric.API_CAM); for (String value : cam.values()) { TextView tv = (TextView) inflater.inflate(R.layout.entry, null); tv.setText(value); vg.addView(tv); } } } } catch (Exception e) { e.printStackTrace(); showError(e.getClass().getCanonicalName(), e.getLocalizedMessage() + getString(R.string.error_generic)); } }
From source file:com.github.developerpaul123.filepickerlibrary.FilePickerActivity.java
/** * Initializes all the views in the layout of the activity. *//* w w w . j av a2s .c om*/ private void initializeViews() { directoryTitle = (TextView) findViewById(R.id.file_directory_title); addButton = (MaterialFloatingActionButton) findViewById(R.id.file_picker_add_button); addButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { NameFileDialog nfd = NameFileDialog.newInstance(); nfd.show(getFragmentManager(), "NameDialog"); } }); if (fabColorId != -1) { addButton.setButtonColor(getResources().getColor(fabColorId)); } selectButton = (Button) findViewById(R.id.select_button); selectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (requestCode == Request.DIRECTORY) { if (currentFile.isDirectory()) { curDirectory = currentFile; data = new Intent(); data.putExtra(FILE_EXTRA_DATA_PATH, currentFile.getAbsolutePath()); setResult(RESULT_OK, data); finish(); } else { Snackbar.make(getWindow().getDecorView(), R.string.file_picker_snackbar_select_directory_message, Snackbar.LENGTH_SHORT) .show(); } } else { //request code is for a file if (currentFile.isDirectory()) { curDirectory = currentFile; new UpdateFilesTask(FilePickerActivity.this).execute(curDirectory); } else { if (!TextUtils.isEmpty(mimeType)) { MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); String requiredExtension = "." + mimeTypeMap.getExtensionFromMimeType(mimeType); if (requiredExtension.equalsIgnoreCase(fileExt(currentFile.toString()))) { data = new Intent(); data.putExtra(FILE_EXTRA_DATA_PATH, currentFile.getAbsolutePath()); setResult(RESULT_OK, data); finish(); } else { Snackbar.make(getWindow().getDecorView(), String.format( getString(R.string.file_picker_snackbar_select_file_ext_message), requiredExtension), Snackbar.LENGTH_SHORT).show(); } } else { data = new Intent(); data.putExtra(FILE_EXTRA_DATA_PATH, currentFile.getAbsolutePath()); setResult(RESULT_OK, data); finish(); } } } } }); openButton = (Button) findViewById(R.id.open_button); openButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (currentFile.isDirectory()) { curDirectory = currentFile; directoryTitle.setText(curDirectory.getName()); new UpdateFilesTask(FilePickerActivity.this).execute(curDirectory); } else { Intent newIntent = new Intent(Intent.ACTION_VIEW); String file = currentFile.toString(); if (file != null) { newIntent.setDataAndType(Uri.fromFile(currentFile), mimeType); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(newIntent); } catch (ActivityNotFoundException e) { Snackbar.make(getWindow().getDecorView(), R.string.file_picker_snackbar_no_file_type_handler, Snackbar.LENGTH_SHORT) .show(); } } else { Snackbar.make(getWindow().getDecorView(), R.string.file_picker_snackbar_no_read_type, Snackbar.LENGTH_SHORT).show(); } } } }); buttonContainer = (LinearLayout) findViewById(R.id.button_container); buttonContainer.setVisibility(View.INVISIBLE); header = (RelativeLayout) findViewById(R.id.header_container); }
From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java
public void setAsWallpaperMore() { String path = Environment.getExternalStorageDirectory().toString(); File file = new File(path, "/" + TEMP_WALLPAPER_DIR + "/" + TEMP_WALLPAPER_NAME + ".png"); Uri uri = Uri.fromFile(file);/* www .j av a 2 s . c o m*/ Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setDataAndType(uri, "image/png"); intent.putExtra("mimeType", "image/png"); startActivity(Intent.createChooser(intent, "Set as : Mood Wallpaper")); // WallpaperManager myWallpaperManager // = WallpaperManager.getInstance(getApplicationContext()); // try { // myWallpaperManager.setBitmap(((BitmapDrawable) imageView.getDrawable()).getBitmap()); // } catch (IOException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } }
From source file:com.jinrustar.sky.main.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 0x57 && resultCode == Activity.RESULT_OK) { content = data.getExtras().getString("result"); if (!TextUtils.isEmpty(content)) { connect();//from w w w . j a va 2 s. c o m // Toast.makeText(context, "ip:"+content, Toast.LENGTH_SHORT).show(); } } if (requestCode == 0x88 && resultCode == Activity.RESULT_OK) { // VideoInfo info = new VideoInfo(); VideoInfo info = (VideoInfo) data.getExtras().getSerializable("videoinfo"); itemClick(info); } if (requestCode == 0x55 && resultCode == Activity.RESULT_OK) { Uri uri = data.getData(); Cursor cursor = this.getContentResolver().query(uri, null, null, null, null); cursor.moveToFirst(); for (int i = 0; i < cursor.getColumnCount(); i++) {// ?uri??? System.out.println(i + "-" + cursor.getColumnName(i) + "-" + cursor.getString(i)); } //Intent Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/*"); // intent.setData(uri); startActivity(intent); } else if (requestCode == 0x56 && resultCode == Activity.RESULT_OK) { Uri uri = data.getData(); Cursor cursor = this.getContentResolver().query(uri, null, null, null, null); cursor.moveToFirst(); for (int i = 0; i < cursor.getColumnCount(); i++) {// ?uri??? System.out.println(i + "-" + cursor.getColumnName(i) + "-" + cursor.getString(i)); } //Intent Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "video/*"); // intent.setData(uri); startActivity(intent); } }
From source file:com.ximai.savingsmore.save.activity.AddGoodsAcitivyt.java
public void cropImage(Uri uri, int requestCode) { Intent intent = new Intent(this, CropImageActivity.class); intent.setDataAndType(uri, "image/*"); intent.putExtra("isCrop", false); startActivityForResult(intent, requestCode); }