List of usage examples for android.content Intent setType
public @NonNull Intent setType(@Nullable String type)
From source file:com.ibuildapp.romanblack.WebPlugin.WebPlugin.java
@Override public void create() { try {//www. j a v a2 s . co m setContentView(R.layout.romanblack_html_main); root = (FrameLayout) findViewById(R.id.romanblack_root_layout); webView = new ObservableWebView(this); webView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); root.addView(webView); webView.setHorizontalScrollBarEnabled(false); setTitle("HTML"); Intent currentIntent = getIntent(); Bundle store = currentIntent.getExtras(); widget = (Widget) store.getSerializable("Widget"); if (widget == null) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } appName = widget.getAppName(); if (widget.getPluginXmlData().length() == 0) { if (currentIntent.getStringExtra("WidgetFile").length() == 0) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } } if (widget.getTitle() != null && widget.getTitle().length() > 0) { setTopBarTitle(widget.getTitle()); } else { setTopBarTitle(getResources().getString(R.string.romanblack_html_web)); } currentUrl = (String) getSession(); if (currentUrl == null) { currentUrl = ""; } ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null && ni.isConnectedOrConnecting()) { isOnline = true; } // topbar initialization setTopBarLeftButtonText(getString(R.string.common_home_upper), true, new View.OnClickListener() { @Override public void onClick(View view) { onBackPressed(); } }); if (isOnline) { webView.getSettings().setJavaScriptEnabled(true); } webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.getSettings().setGeolocationEnabled(true); webView.getSettings().setAllowFileAccess(true); webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setUseWideViewPort(false); webView.getSettings().setSavePassword(false); webView.clearHistory(); webView.invalidate(); if (Build.VERSION.SDK_INT >= 19) { } webView.getSettings().setUserAgentString( "Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"); webView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.invalidate(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { } break; case MotionEvent.ACTION_UP: { if (!v.hasFocus()) { v.requestFocus(); } } break; case MotionEvent.ACTION_MOVE: { } break; } return false; } }); webView.setBackgroundColor(Color.WHITE); try { if (widget.getBackgroundColor() != Color.TRANSPARENT) { webView.setBackgroundColor(widget.getBackgroundColor()); } } catch (IllegalArgumentException e) { } webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); startActivity(intent); } }); webView.setWebChromeClient(new WebChromeClient() { FrameLayout.LayoutParams LayoutParameters = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); @Override public void onGeolocationPermissionsShowPrompt(final String origin, final GeolocationPermissions.Callback callback) { AlertDialog.Builder builder = new AlertDialog.Builder(WebPlugin.this); builder.setTitle(R.string.location_dialog_title); builder.setMessage(R.string.location_dialog_description); builder.setCancelable(true); builder.setPositiveButton(R.string.location_dialog_allow, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { callback.invoke(origin, true, false); } }); builder.setNegativeButton(R.string.location_dialog_not_allow, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { callback.invoke(origin, false, false); } }); AlertDialog alert = builder.create(); alert.show(); } @Override public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) { if (customView != null) { customViewCallback.onCustomViewHidden(); return; } view.setBackgroundColor(Color.BLACK); view.setLayoutParams(LayoutParameters); root.addView(view); customView = view; customViewCallback = callback; webView.setVisibility(View.GONE); } @Override public void onHideCustomView() { if (customView == null) { return; } else { closeFullScreenVideo(); } } public void openFileChooser(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT);//Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); isMedia = true; startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); } // For Android 3.0+ public void openFileChooser(ValueCallback uploadMsg, String acceptType) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE); } //For Android 4.1 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); isMedia = true; i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); } @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { isV21 = true; mUploadMessageV21 = filePathCallback; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); return true; } @Override public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) { super.onReceivedTouchIconUrl(view, url, precomposed); } }); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); if (state == states.EMPTY) { currentUrl = url; setSession(currentUrl); state = states.LOAD_START; handler.sendEmptyMessage(SHOW_PROGRESS); } } @Override public void onLoadResource(WebView view, String url) { if (!alreadyLoaded && (url.startsWith("http://www.youtube.com/get_video_info?") || url.startsWith("https://www.youtube.com/get_video_info?")) && Build.VERSION.SDK_INT < 11) { try { String path = url.contains("https://www.youtube.com/get_video_info?") ? url.replace("https://www.youtube.com/get_video_info?", "") : url.replace("http://www.youtube.com/get_video_info?", ""); String[] parqamValuePairs = path.split("&"); String videoId = null; for (String pair : parqamValuePairs) { if (pair.startsWith("video_id")) { videoId = pair.split("=")[1]; break; } } if (videoId != null) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com")) .setData(Uri.parse("http://www.youtube.com/watch?v=" + videoId))); needRefresh = true; alreadyLoaded = !alreadyLoaded; return; } } catch (Exception ex) { } } else { super.onLoadResource(view, url); } } @Override public void onPageFinished(WebView view, String url) { if (hideProgress) { if (TextUtils.isEmpty(WebPlugin.this.url)) { state = states.LOAD_COMPLETE; handler.sendEmptyMessage(HIDE_PROGRESS); super.onPageFinished(view, url); } else { view.loadUrl("javascript:(function(){" + "l=document.getElementById('link');" + "e=document.createEvent('HTMLEvents');" + "e.initEvent('click',true,true);" + "l.dispatchEvent(e);" + "})()"); hideProgress = false; } } else { state = states.LOAD_COMPLETE; handler.sendEmptyMessage(HIDE_PROGRESS); super.onPageFinished(view, url); } } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { if (errorCode == WebViewClient.ERROR_BAD_URL) { startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), DOWNLOAD_REQUEST_CODE); } } @Override public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) { final AlertDialog.Builder builder = new AlertDialog.Builder(WebPlugin.this); builder.setMessage(R.string.notification_error_ssl_cert_invalid); builder.setPositiveButton(WebPlugin.this.getResources().getString(R.string.wp_continue), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handler.proceed(); } }); builder.setNegativeButton(WebPlugin.this.getResources().getString(R.string.wp_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handler.cancel(); } }); final AlertDialog dialog = builder.create(); dialog.show(); } @Override public void onFormResubmission(WebView view, Message dontResend, Message resend) { super.onFormResubmission(view, dontResend, resend); } @Override public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { return super.shouldInterceptRequest(view, request); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { try { if (url.contains("youtube.com/watch")) { if (Build.VERSION.SDK_INT < 11) { try { startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com")) .setData(Uri.parse(url))); return true; } catch (Exception ex) { return false; } } else { return false; } } else if (url.contains("paypal.com")) { if (url.contains("&bn=ibuildapp_SP")) { return false; } else { url = url + "&bn=ibuildapp_SP"; webView.loadUrl(url); return true; } } else if (url.contains("sms:")) { try { Intent smsIntent = new Intent(Intent.ACTION_VIEW); smsIntent.setData(Uri.parse(url)); startActivity(smsIntent); return true; } catch (Exception ex) { Log.e("", ex.getMessage()); return false; } } else if (url.contains("tel:")) { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse(url)); startActivity(callIntent); return true; } else if (url.contains("mailto:")) { MailTo mailTo = MailTo.parse(url); Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { mailTo.getTo() }); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mailTo.getSubject()); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, mailTo.getBody()); WebPlugin.this.startActivity(Intent.createChooser(emailIntent, getString(R.string.romanblack_html_send_email))); return true; } else if (url.contains("rtsp:")) { Uri address = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, address); final PackageManager pm = getPackageManager(); final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0); if (matches.size() > 0) { startActivity(intent); } else { Toast.makeText(WebPlugin.this, getString(R.string.romanblack_html_no_video_player), Toast.LENGTH_SHORT).show(); } return true; } else if (url.startsWith("intent:") || url.startsWith("market:") || url.startsWith("col-g2m-2:")) { Intent it = new Intent(); it.setData(Uri.parse(url)); startActivity(it); return true; } else if (url.contains("//play.google.com/")) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } else { if (url.contains("ibuildapp.com-1915109")) { String param = Uri.parse(url).getQueryParameter("widget"); finish(); if (param != null && param.equals("1001")) com.appbuilder.sdk.android.Statics.launchMain(); else if (param != null && !"".equals(param)) { View.OnClickListener widget = Statics.linkWidgets.get(Integer.valueOf(param)); if (widget != null) widget.onClick(view); } return false; } currentUrl = url; setSession(currentUrl); if (!isOnline) { handler.sendEmptyMessage(HIDE_PROGRESS); handler.sendEmptyMessage(STOP_LOADING); } else { String pageType = "application/html"; if (!url.contains("vk.com")) { getPageType(url); } if (pageType.contains("application") && !pageType.contains("html") && !pageType.contains("xml")) { startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), DOWNLOAD_REQUEST_CODE); return super.shouldOverrideUrlLoading(view, url); } else { view.getSettings().setLoadWithOverviewMode(true); view.getSettings().setUseWideViewPort(true); view.setBackgroundColor(Color.WHITE); } } return false; } } catch (Exception ex) { // Error Logging return false; } } }); handler.sendEmptyMessage(SHOW_PROGRESS); new Thread() { @Override public void run() { EntityParser parser; if (widget.getPluginXmlData() != null) { if (widget.getPluginXmlData().length() > 0) { parser = new EntityParser(widget.getPluginXmlData()); } else { String xmlData = readXmlFromFile(getIntent().getStringExtra("WidgetFile")); parser = new EntityParser(xmlData); } } else { String xmlData = readXmlFromFile(getIntent().getStringExtra("WidgetFile")); parser = new EntityParser(xmlData); } parser.parse(); url = parser.getUrl(); html = parser.getHtml(); if (url.length() > 0 && !isOnline) { handler.sendEmptyMessage(NEED_INTERNET_CONNECTION); } else { if (isOnline) { } else { if (html.length() == 0) { } } if (html.length() > 0 || url.length() > 0) { handler.sendEmptyMessageDelayed(SHOW_HTML, 700); } else { handler.sendEmptyMessage(HIDE_PROGRESS); handler.sendEmptyMessage(INITIALIZATION_FAILED); } } } }.start(); } catch (Exception ex) { } }
From source file:com.kdao.cmpe235_project.UploadActivity.java
private void initUI() { /**// w w w .jav a 2 s . co m * This adapter takes the data in transferRecordMaps and displays it, * with the keys of the map being related to the columns in the adapter */ simpleAdapter = new SimpleAdapter(this, transferRecordMaps, R.layout.record_item, new String[] { "checked", "fileName", "progress", "bytes", "state", "percentage" }, new int[] { R.id.radioButton1, R.id.textFileName, R.id.progressBar1, R.id.textBytes, R.id.textState, R.id.textPercentage }); simpleAdapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { switch (view.getId()) { case R.id.radioButton1: RadioButton radio = (RadioButton) view; radio.setChecked((Boolean) data); return true; case R.id.textFileName: TextView fileName = (TextView) view; fileName.setText((String) data); return true; case R.id.progressBar1: ProgressBar progress = (ProgressBar) view; progress.setProgress((Integer) data); return true; case R.id.textBytes: TextView bytes = (TextView) view; bytes.setText((String) data); return true; case R.id.textState: TextView state = (TextView) view; state.setText(((TransferState) data).toString()); return true; case R.id.textPercentage: TextView percentage = (TextView) view; percentage.setText((String) data); return true; } return false; } }); setListAdapter(simpleAdapter); // Updates checked index when an item is clicked getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int pos, long id) { if (checkedIndex != pos) { transferRecordMaps.get(pos).put("checked", true); if (checkedIndex >= 0) { transferRecordMaps.get(checkedIndex).put("checked", false); } checkedIndex = pos; updateButtonAvailability(); simpleAdapter.notifyDataSetChanged(); } } }); //btnUploadFile = (Button) findViewById(R.id.buttonUploadFile); btnUploadImage = (Button) findViewById(R.id.buttonUploadImage); btnUploadAudio = (Button) findViewById(R.id.buttonUploadAudio); btnUploadVideo = (Button) findViewById(R.id.buttonUploadVideo); btnPause = (Button) findViewById(R.id.buttonPause); btnResume = (Button) findViewById(R.id.buttonResume); btnCancel = (Button) findViewById(R.id.buttonCancel); btnDelete = (Button) findViewById(R.id.buttonDelete); btnPauseAll = (Button) findViewById(R.id.buttonPauseAll); btnCancelAll = (Button) findViewById(R.id.buttonCancelAll); btnUploadImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isTreeSelected) { System.out.println(">>>>> Start uploading photos... <<<<<<<"); Intent intent = new Intent(); if (Build.VERSION.SDK_INT >= 19) { // For Android versions of KitKat or later, we use a // different intent to ensure // we can get the file path from the returned intent URI intent.setAction(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); } else { intent.setAction(Intent.ACTION_GET_CONTENT); } APIurl = "/tree/" + treeId + "/photo"; intent.setType("image/*"); startActivityForResult(intent, 0); } else { Toast.makeText(getApplicationContext(), Config.UPLOAD_NOTREE_ERR, Toast.LENGTH_LONG).show(); } } }); btnUploadAudio.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isTreeSelected) { Intent intent = new Intent(); if (Build.VERSION.SDK_INT >= 19) { // For Android versions of KitKat or later, we use a // different intent to ensure // we can get the file path from the returned intent URI intent.setAction(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); } else { intent.setAction(Intent.ACTION_GET_CONTENT); } APIurl = "/tree/" + treeId + "/audio"; intent.setType("audio/*"); startActivityForResult(intent, 0); } else { Toast.makeText(getApplicationContext(), Config.UPLOAD_NOTREE_ERR, Toast.LENGTH_LONG).show(); } } }); btnUploadVideo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isTreeSelected) { Intent intent = new Intent(); if (Build.VERSION.SDK_INT >= 19) { // For Android versions of KitKat or later, we use a // different intent to ensure // we can get the file path from the returned intent URI intent.setAction(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); } else { intent.setAction(Intent.ACTION_GET_CONTENT); } APIurl = "/tree/" + treeId + "/video"; intent.setType("video/*"); startActivityForResult(intent, 0); } else { Toast.makeText(getApplicationContext(), Config.UPLOAD_NOTREE_ERR, Toast.LENGTH_LONG).show(); } } }); btnPause.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Make sure the user has selected a transfer if (checkedIndex >= 0 && checkedIndex < observers.size()) { Boolean paused = transferUtility.pause(observers.get(checkedIndex).getId()); /** * If paused does not return true, it is likely because the * user is trying to pause an upload that is not in a * pausable state (For instance it is already paused, or * canceled). */ if (!paused) { Toast.makeText(UploadActivity.this, Config.UPLOAD_PAUSE_ERR, Toast.LENGTH_SHORT).show(); } } } }); btnResume.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Make sure the user has selected a transfer if (checkedIndex >= 0 && checkedIndex < observers.size()) { TransferObserver resumed = transferUtility.resume(observers.get(checkedIndex).getId()); // Sets a new transfer listener to the original observer. // This will overwrite existing listener. observers.get(checkedIndex).setTransferListener(new UploadListener()); /** * If resume returns null, it is likely because the transfer * is not in a resumable state (For instance it is already * running). */ if (resumed == null) { Toast.makeText(UploadActivity.this, Config.UPLOAD_RESUME_ERR, Toast.LENGTH_SHORT).show(); } } } }); btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Make sure a transfer is selected if (checkedIndex >= 0 && checkedIndex < observers.size()) { Boolean canceled = transferUtility.cancel(observers.get(checkedIndex).getId()); /** * If cancel returns false, it is likely because the * transfer is already canceled */ if (!canceled) { Toast.makeText(UploadActivity.this, Config.UPLOAD_TRANSFER_ERR, Toast.LENGTH_SHORT).show(); } } } }); btnDelete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Make sure a transfer is selected if (checkedIndex >= 0 && checkedIndex < observers.size()) { transferUtility.deleteTransferRecord(observers.get(checkedIndex).getId()); observers.remove(checkedIndex); transferRecordMaps.remove(checkedIndex); checkedIndex = INDEX_NOT_CHECKED; updateButtonAvailability(); updateList(); } } }); btnPauseAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { transferUtility.pauseAllWithType(TransferType.UPLOAD); } }); btnCancelAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { transferUtility.cancelAllWithType(TransferType.UPLOAD); } }); updateButtonAvailability(); }
From source file:com.nttec.everychan.ui.gallery.GalleryActivity.java
private void share() { GalleryItemViewTag tag = getCurrentTag(); if (tag == null) return;/* w w w .j av a 2s .co m*/ Intent shareIntent = new Intent(Intent.ACTION_SEND); String extension = Attachments.getAttachmentExtention(tag.attachmentModel); switch (tag.attachmentModel.type) { case AttachmentModel.TYPE_IMAGE_GIF: shareIntent.setType("image/gif"); break; case AttachmentModel.TYPE_IMAGE_SVG: shareIntent.setType("image/svg+xml"); break; case AttachmentModel.TYPE_IMAGE_STATIC: if (extension.equalsIgnoreCase(".png")) { shareIntent.setType("image/png"); } else if (extension.equalsIgnoreCase(".jpg") || extension.equalsIgnoreCase(".jpg")) { shareIntent.setType("image/jpeg"); } else { shareIntent.setType("image/*"); } break; case AttachmentModel.TYPE_VIDEO: if (extension.equalsIgnoreCase(".mp4")) { shareIntent.setType("video/mp4"); } else if (extension.equalsIgnoreCase(".webm")) { shareIntent.setType("video/webm"); } else if (extension.equalsIgnoreCase(".avi")) { shareIntent.setType("video/avi"); } else if (extension.equalsIgnoreCase(".mov")) { shareIntent.setType("video/quicktime"); } else if (extension.equalsIgnoreCase(".mkv")) { shareIntent.setType("video/x-matroska"); } else if (extension.equalsIgnoreCase(".flv")) { shareIntent.setType("video/x-flv"); } else if (extension.equalsIgnoreCase(".wmv")) { shareIntent.setType("video/x-ms-wmv"); } else { shareIntent.setType("video/*"); } break; case AttachmentModel.TYPE_AUDIO: if (extension.equalsIgnoreCase(".mp3")) { shareIntent.setType("audio/mpeg"); } else if (extension.equalsIgnoreCase(".mp4")) { shareIntent.setType("audio/mp4"); } else if (extension.equalsIgnoreCase(".ogg")) { shareIntent.setType("audio/ogg"); } else if (extension.equalsIgnoreCase(".webm")) { shareIntent.setType("audio/webm"); } else if (extension.equalsIgnoreCase(".flac")) { shareIntent.setType("audio/flac"); } else if (extension.equalsIgnoreCase(".wav")) { shareIntent.setType("audio/vnd.wave"); } else { shareIntent.setType("audio/*"); } break; case AttachmentModel.TYPE_OTHER_FILE: shareIntent.setType("application/octet-stream"); break; } Logger.d(TAG, shareIntent.getType()); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tag.file)); startActivity(Intent.createChooser(shareIntent, getString(R.string.share_via))); }
From source file:com.kncwallet.wallet.ui.WalletActivity.java
private void mailPrivateKeys(@Nonnull final File file) { final Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.export_keys_dialog_mail_subject)); intent.putExtra(Intent.EXTRA_TEXT,//w ww. j a v a2 s. c o m getString(R.string.export_keys_dialog_mail_text) + "\n\n" + String.format(Constants.WEBMARKET_APP_URL, getPackageName()) + "\n\n" + Constants.SOURCE_URL + '\n'); intent.setType("x-bitcoin/private-keys"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); startActivity(Intent.createChooser(intent, getString(R.string.export_keys_dialog_mail_intent_chooser))); log.info("invoked archive private keys chooser"); }
From source file:com.zlkj.dingdangwuyou.activity.CompanyInfoActivity.java
/** * ?/* ww w . ja v a 2s . co m*/ */ private void showAvatarOption() { AlertDialog.Builder builder = new AlertDialog.Builder(this); String[] items = new String[] { "?", "" }; builder.setTitle("").setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(); switch (which) { case 0: // ? if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { String curTime = AppTool.dateFormat(System.currentTimeMillis(), "yyyyMMddHHmmss"); // ??? File imagePath = new File(Environment.getExternalStorageDirectory() + Const.APP_IMAGE_PATH); if (!imagePath.exists()) { imagePath.mkdirs(); } cameraFile = new File(imagePath.getPath(), curTime + ".jpg"); intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)); startActivityForResult(intent, Const.REQUEST_CODE_CAMERA); } else { Toast.makeText(context, "???", Toast.LENGTH_SHORT) .show(); } break; case 1: // intent.setAction(Intent.ACTION_PICK); intent.setType("image/*"); startActivityForResult(intent, Const.REQUEST_CODE_GALLERY); break; default: break; } } }); builder.show(); }
From source file:com.scoreflex.ScoreflexView.java
/** * The constructor of the view./* w w w.j ava 2s . c o m*/ * @param activity The activity holding the view. * @param attrs * @param defStyle */ @SuppressWarnings("deprecation") public ScoreflexView(Activity activity, AttributeSet attrs, int defStyle) { super(activity, attrs, defStyle); // Keep a reference on the activity mParentActivity = activity; // Default layout params if (null == getLayoutParams()) { setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Scoreflex.getDensityIndependantPixel(R.dimen.scoreflex_panel_height))); } // Set our background color setBackgroundColor(getContext().getResources().getColor(R.color.scoreflex_background_color)); // Create the top bar View topBar = new View(getContext()); topBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height), Gravity.TOP)); topBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.scoreflex_gradient_background)); addView(topBar); // Create the retry button LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); mErrorLayout = (ViewGroup) inflater.inflate(R.layout.scoreflex_error_layout, null); if (mErrorLayout != null) { // Configure refresh button Button refreshButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_retry_button); if (null != refreshButton) { refreshButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (null == Scoreflex.getPlayerId()) { setUserInterfaceState(new LoadingState()); loadUrlAfterLoggedIn(mInitialResource, mInitialRequestParams); } else if (null == mWebView.getUrl()) { setResource(mInitialResource); } else { mWebView.reload(); } } }); } // Configure cancel button Button cancelButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_cancel_button); if (null != cancelButton) { cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { close(); } }); } // Get hold of the message view mMessageView = (TextView) mErrorLayout.findViewById(R.id.scoreflex_error_message_view); addView(mErrorLayout); } // Create the close button mCloseButton = new ImageButton(getContext()); Drawable closeButtonDrawable = getResources().getDrawable(R.drawable.scoreflex_close_button); int closeButtonMargin = (int) ((getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height) - closeButtonDrawable.getIntrinsicHeight()) / 2.0f); FrameLayout.LayoutParams closeButtonLayoutParams = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP | Gravity.RIGHT); closeButtonLayoutParams.setMargins(0, closeButtonMargin, closeButtonMargin, 0); mCloseButton.setLayoutParams(closeButtonLayoutParams); mCloseButton.setImageDrawable(closeButtonDrawable); mCloseButton.setBackgroundDrawable(null); mCloseButton.setPadding(0, 0, 0, 0); mCloseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { close(); } }); addView(mCloseButton); // Create the web view mWebView = new WebView(mParentActivity); mWebView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // mWebView.setBackgroundColor(Color.RED); mWebView.setWebViewClient(new ScoreflexWebViewClient()); mWebView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage cm) { Log.d("Scoreflex", "javascript Error: " + String.format("%s @ %d: %s", cm.message(), cm.lineNumber(), cm.sourceId())); return true; } public void openFileChooser(ValueCallback<Uri> uploadMsg) { // mtbActivity.mUploadMessage = uploadMsg; mUploadMessage = uploadMsg; String fileName = "picture.jpg"; ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, fileName); // mOutputFileUri = mParentActivity.getContentResolver().insert( // MediaStore.Images.Media.DATA, values); final List<Intent> cameraIntents = new ArrayList<Intent>(); final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); final PackageManager packageManager = mParentActivity.getPackageManager(); final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0); for (ResolveInfo res : listCam) { final String packageName = res.activityInfo.packageName; final Intent intent = new Intent(captureIntent); intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); intent.setPackage(packageName); cameraIntents.add(intent); } // Filesystem. final Intent galleryIntent = new Intent(); galleryIntent.setType("image/*"); galleryIntent.setAction(Intent.ACTION_GET_CONTENT); // Chooser of filesystem options. final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source please"); // Add the camera options. chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {})); mParentActivity.startActivityForResult(chooserIntent, Scoreflex.FILECHOOSER_RESULTCODE); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { openFileChooser(uploadMsg); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { openFileChooser(uploadMsg); } }); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setDomStorageEnabled(true); mWebView.getSettings().setDatabasePath( getContext().getFilesDir().getPath() + "/data/" + getContext().getPackageName() + "/databases/"); addView(mWebView); TypedArray a = mParentActivity.obtainStyledAttributes(attrs, R.styleable.ScoreflexView, defStyle, 0); String resource = a.getString(R.styleable.ScoreflexView_resource); if (null != resource) setResource(resource); a.recycle(); // Create the animated spinner mProgressBar = (ProgressBar) ((LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.scoreflex_progress_bar, null); mProgressBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER)); addView(mProgressBar); LocalBroadcastManager.getInstance(activity).registerReceiver(mLoginReceiver, new IntentFilter(Scoreflex.INTENT_USER_LOGED_IN)); setUserInterfaceState(new InitialState()); }
From source file:cn.kangeqiu.kq.activity.ChatActivity.java
/** * ?/*from w w w . j a va 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_LOCAL); }
From source file:cn.kangeqiu.kq.activity.ChatActivity.java
/** * /* w w w .j av a 2 s. c o m*/ */ private void selectFileFromLocal() { Intent intent = null; if (Build.VERSION.SDK_INT < 19) { intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); } else { intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); } startActivityForResult(intent, REQUEST_CODE_SELECT_FILE); }
From source file:au.com.infiniterecursion.vidiom.utils.PublishingUtils.java
public void launchEmailIntentWithCurrentVideo(final Activity activity, final String latestVideoFile_absolutepath) { Log.d(TAG, "launchEmailIntentWithCurrentVideo starting"); Intent i = new Intent(Intent.ACTION_SEND); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // XXX hardcoded video mimetype i.setType("video/mp4"); i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + latestVideoFile_absolutepath)); activity.startActivity(i);//w w w . j ava 2 s. c o m }