List of usage examples for android.content Intent setDataAndType
public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type)
From source file:com.googlecode.android_scripting.activity.ScriptManager.java
protected void externalEditor(File file) { Intent intent = new Intent(Intent.ACTION_EDIT); intent.setDataAndType(Uri.fromFile(file), "text/plain"); try {/* w w w .j a va 2 s . c o m*/ startActivity(intent); } catch (Exception e) { Crouton.showText(this, getString(R.string.s_UnableOpeneditor) + e.toString(), Style.ALERT); } }
From source file:com.example.commander.CommandManager.java
/** * Start intent for file open//from ww w . ja v a 2s. co m */ private void StartOpenFileIntent() { // Make intent File file = new File(mFilePath); MimeTypeMap map = MimeTypeMap.getSingleton(); String extension = MimeTypeMap.getFileExtensionFromUrl(file.getName()); String type = map.getMimeTypeFromExtension(extension); if (type == null) { type = "*/*"; } Intent intent = new Intent(Intent.ACTION_VIEW); Uri dataForIntent = Uri.fromFile(file); intent.setDataAndType(dataForIntent, type); mActivity.startActivity(intent); }
From source file:com.keithandthegirl.ui.activity.EpisodesFragment.java
private void play(PlayType type, Resource resource, Long id, String title, String description, String url, String file, boolean shouldReset) { Log.d(TAG, "play : enter"); if (mBound) { if (shouldReset) { mMediaPlayer.reset();/*from w ww. j a va 2s . c om*/ } } switch (resource) { case MP3: Log.d(TAG, "play : playing mp3"); Intent mp3Activity = new Intent(getActivity(), PlayerActivity.class); mp3Activity.putExtra(PlayerActivity.PLAY_TYPE, type.name()); mp3Activity.putExtra(PlayerActivity.PLAYBACK_URL, (null != file && !"".equals(file) ? file : url)); mp3Activity.putExtra(PlayerActivity.TITLE, title); mp3Activity.putExtra(PlayerActivity.DESCRIPTION, description); startActivity(mp3Activity); break; case MP4: Log.d(TAG, "play : playing mp4"); Intent mp4Activity = new Intent(Intent.ACTION_VIEW); mp4Activity.setDataAndType(Uri.parse((null != file && !"".equals(file) ? file : url)), resource.getMimeType()); startActivity(mp4Activity); break; case M4V: Log.d(TAG, "play : playing m4v"); Intent m4vActivity = new Intent(Intent.ACTION_VIEW); m4vActivity.setDataAndType(Uri.parse((null != file && !"".equals(file) ? file : url)), resource.getMimeType()); startActivity(m4vActivity); break; default: Log.d(TAG, "play : unknown play type"); break; } Log.d(TAG, "play : exit"); }
From source file:com.android.contacts.activities.ContactDetailActivity.java
/** @} */ @Override//from w ww . j ava 2 s . c o m protected void onCreate(Bundle savedState) { super.onCreate(savedState); LogUtils.i(TAG, "[onCreate][launch]start"); ///M: Bug Fix for ALPS01022809,JE happens when click the favourite video to choose contact in tablet registerPHBReceiver(); mIsActivitFinished = false; /** M: Bug Fix for ALPS00393950 @{ */ boolean isUsingTwoPanes = PhoneCapabilityTester.isUsingTwoPanes(this); if (!isUsingTwoPanes) { SetIndicatorUtils.getInstance().registerReceiver(this); } /** @} */ if (PhoneCapabilityTester.isUsingTwoPanes(this)) { // This activity must not be shown. We have to select the contact in the // PeopleActivity instead ==> Create a forward intent and finish final Intent originalIntent = getIntent(); Intent intent = new Intent(); intent.setAction(originalIntent.getAction()); intent.setDataAndType(originalIntent.getData(), originalIntent.getType()); // If we are launched from the outside, we should create a new task, because the user // can freely navigate the app (this is different from phones, where only the UP button // kicks the user into the full app) if (shouldUpRecreateTask(intent)) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); } else { intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); } intent.setClass(this, PeopleActivity.class); startActivity(intent); LogUtils.i(TAG, "onCreate(),Using Two Panes...finish Actiivity.."); finish(); return; } setContentView(R.layout.contact_detail_activity); mContactDetailLayoutController = new ContactDetailLayoutController(this, savedState, getFragmentManager(), null, findViewById(R.id.contact_detail_container), mContactDetailFragmentListener); // We want the UP affordance but no app icon. // Setting HOME_AS_UP, SHOW_TITLE and clearing SHOW_HOME does the trick. ActionBar actionBar = getActionBar(); if (actionBar != null) { ///@Modify for add Customer view{ actionBar.setDisplayOptions( ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM); ///@} actionBar.setTitle(""); } Log.i(TAG, getIntent().getData().toString()); /** M: New Feature xxx @{ */ //M:fix CR:ALPS00958663,disconnect to smartbook when contact screen happen JE if (getIntent() != null && getIntent().getData() != null) { mSimOrPhoneUri = getIntent().getData(); Log.i(TAG, "mSimOrPhoneUri = " + mSimOrPhoneUri); } else { Log.e(TAG, "Get intent data error getIntent() = " + getIntent()); } /// M: @ CT contacts detail history set listener{ ExtensionManager.getInstance().getContactDetailEnhancementExtension().configActionBarExt(getActionBar(), ContactPluginDefault.COMMD_FOR_OP09); /// @} LogUtils.i(TAG, "[onCreate][launch]end"); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LinkObj.java
@Override public void activate(Context context, SignedObj obj) { JSONObject content = obj.getJson();/*from w ww. ja va2s. c om*/ //linkify should have picked it up already but if we are in TV mode we //still need to activate Intent intent = new Intent(Intent.ACTION_VIEW); String text = content.optString(URI); //some shared links come in with two lines of text "title\nuri" //for example google maps does this and passes that same value as both the //uri and title //launch the first thing that looks like a link Matcher m = p.matcher(text); while (m.find()) { Uri uri = Uri.parse(m.group()); String scheme = uri.getScheme(); if (scheme != null && (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"))) { String type = content.optString(MIME_TYPE); if (type != null && type.length() > 0) { intent.setDataAndType(uri, type); } else { intent.setData(uri); } if (!(context instanceof Activity)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } try { context.startActivity(intent); } catch (ActivityNotFoundException e) { String msg; if (type != null) msg = "A third party application that supports " + type + " is required."; else msg = "A third party application that supports " + uri.getScheme() + " is required."; Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } return; } } }
From source file:com.phonegap.cordova.FileOpener.java
private void openFile(String url, String type) throws IOException { // Create URI Uri uri = Uri.parse(url);/*w w w. ja v a 2 s . c o m*/ Intent intent = null; Log.v("FileOpener", "Type: " + type); if (type.equals("pdfshare")) { intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:")); // intent.setDataAndType(uri, "application/pdf"); intent.setType("application/pdf"); intent.putExtra(Intent.EXTRA_SUBJECT, "AMR Report"); intent.putExtra(Intent.EXTRA_TEXT, ""); intent.putExtra(Intent.EXTRA_STREAM, uri); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } else if (url.contains(".pdf")) { // PDF file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/pdf"); } else if (url.contains(".ppt") || url.contains(".pptx")) { // Powerpoint file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); } else if (url.contains(".xls") || url.contains(".xlsx")) { // Excel file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/vnd.ms-excel"); } else if (url.contains(".rtf")) { // RTF file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/rtf"); } else if (url.contains(".wav")) { // WAV audio file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "audio/x-wav"); } else if (url.contains(".gif")) { // GIF file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/gif"); } else if (url.contains(".jpg") || url.contains(".jpeg")) { // JPG file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/jpeg"); } else if (url.contains(".png")) { // PNG file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/png"); } else if (url.contains(".txt")) { // Text file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "text/plain"); } else if (url.contains(".mpg") || url.contains(".mpeg") || url.contains(".mpe") || url.contains(".mp4") || url.contains(".avi")) { // Video files intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "video/*"); } else if (url.contains(".doc") || url.contains(".docx")) { // Word document intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/msword"); } //if you want you can also define the intent type for any other file //additionally use else clause below, to manage other unknown extensions //in this case, Android will show all applications installed on the device //so you can choose which application to use else if (type.equals("none") || type.equals("*/*")) { intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "*/*"); } else { intent = new Intent(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(uri, type); } //TRY Catch error try { this.cordova.getActivity().startActivity(intent); } catch (ActivityNotFoundException e) { intent.setData(uri); this.cordova.getActivity().startActivity(intent); } }
From source file:com.ibuildapp.romanblack.NewsPlugin.NewsPlugin.java
public void startRssDetails(int adapterPosition) { FeedItem currentItem = items.get(adapterPosition); if ((currentItem.getMediaType() != null && currentItem.getMediaType().contains("image")) || !currentItem.hasMedia() || currentItem.getDescription().length() > 70) { Intent details = new Intent(this, NewsDetailsActivity.class); Bundle store = new Bundle(); store.putString("func", funcName); store.putSerializable("Widget", widget); store.putSerializable("item", items.get(adapterPosition)); if (encoding.equals("")) { store.putString("enc", "UTF-8"); } else {// ww w . j av a 2 s.com store.putString("enc", encoding); } details.putExtras(store); startActivity(details); overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale); } else if (currentItem.getMediaType().contains("video")) { Intent details = new Intent(this, VideoPlayer.class); Bundle store = new Bundle(); store.putString("link", currentItem.getMediaUrl()); store.putString("cache", cachePath); store.putSerializable("Widget", widget); store.putSerializable("item", currentItem); details.putExtras(store); startActivity(details); overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale); } else if (currentItem.getMediaType().contains("audio")) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(currentItem.getMediaUrl()), "audio/*"); startActivity(intent); overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale); } }
From source file:br.com.anteros.vendas.gui.AnexoCadastroActivity.java
/** * Abre o anexo pela URI do arquivo anexado para visualizao. * @param mUri//from w ww.j a va2 s. co m */ private void abrirAnexo(Uri mUri) { String extension = FilenameUtils.getExtension(AndroidFileUtils.getPath(AnexoCadastroActivity.this, mUri)); try { Intent intent = new Intent(Intent.ACTION_VIEW); MimeTypeMap mime = MimeTypeMap.getSingleton(); String type = mime.getMimeTypeFromExtension(extension); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(mUri, type); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplicationContext().startActivity(intent); } catch (ActivityNotFoundException e) { new ErrorAlert(AnexoCadastroActivity.this, getResources().getString(R.string.app_name), "No foi encontrado nenhum aplicativo nesse aparelho que suporte abrir a extenso '" + extension + "', entre em contato com a equipe de Suporte para resolver esse problema.").show(); } catch (Exception e) { new ErrorAlert(AnexoCadastroActivity.this, getResources().getString(R.string.app_name), "No foi possvel abrir o anexo " + anexo.getId() + ". " + e.getMessage()).show(); e.printStackTrace(); } }
From source file:com.ibuildapp.romanblack.NewsPlugin.NewsPlugin.java
private void showDetails(int position) { try {/*from www . j ava 2 s . c om*/ if ((items.get(position).getMediaType() != null && items.get(position).getMediaType().contains("image")) || !items.get(position).hasMedia() || items.get(position).getDescription().length() > 70) { Intent details = new Intent(this, FeedDetails.class); Bundle store = new Bundle(); store.putString("func", funcName); store.putSerializable("Widget", widget); store.putSerializable("item", items.get(position)); if (encoding.equals("")) { store.putString("enc", "UTF-8"); } else { store.putString("enc", encoding); } details.putExtras(store); startActivity(details); overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale); } else { if (items.get(position).getMediaType().contains("video")) { Intent details = new Intent(this, VideoPlayer.class); Bundle store = new Bundle(); store.putString("link", items.get(position).getMediaUrl()); store.putString("cache", cachePath); store.putSerializable("Widget", widget); store.putSerializable("item", items.get(position)); details.putExtras(store); startActivity(details); overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale); } else if (items.get(position).getMediaType().contains("audio")) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(items.get(position).getMediaUrl()), "audio/*"); startActivity(intent); overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale); } } } catch (Exception ex) { // Error Logging ex.printStackTrace(); } }