List of usage examples for android.content Intent setData
public @NonNull Intent setData(@Nullable Uri data)
From source file:org.sogrey.frame.utils.FileUtil.java
/** * app//from w w w.ja v a 2s . c o m * * @param context * * @author Sogrey * @date 2015-11-27?1:56:55 */ public static void openFolder(Context context, String path) { // Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // Uri uri = Uri.parse(path); // intent.setDataAndType(uri, "text/csv"); // try { // context.startActivity(Intent.createChooser(intent, "Open folder")); // } catch (Exception e) { // } // File root = new File(path); // Uri uri = Uri.fromFile(root); // Intent intent = new Intent(); // intent.setAction(android.content.Intent.ACTION_VIEW); // intent.setData(uri); // context.startActivity(intent); // Intent intent = new Intent(); // String videoPath = path;// // File file = new File(videoPath); // Uri uri = Uri.fromFile(file); // intent.setData(uri); // intent.setAction(android.content.Intent.ACTION_VIEW);// "com.xxx.xxx" // ??? // try { // context.startActivity(intent); // } catch (ActivityNotFoundException e) { // e.printStackTrace(); // } // Intent i = new Intent(Intent.ACTION_GET_CONTENT); // // i.setAction(android.content.Intent.ACTION_VIEW); // File file = new File(path); // i.setDataAndType(Uri.fromFile(file), "file/*"); // try { // context.startActivity(i); // } catch (Exception e) { // } // Intent intent = new Intent(); // File file = new File(path); // intent.setAction(android.content.Intent.ACTION_VIEW); // // intent.setData(Uri.fromFile(file)); // intent.setDataAndType(Uri.fromFile(file), "file/*"); // try { // context.startActivity(intent); // } catch (Exception e) { // } Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // intent.setType("*/*"); intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); File file = new File(path); intent.setData(Uri.fromFile(file)); // intent.setDataAndType(Uri.fromFile(file), "*/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); try { context.startActivity(intent); } catch (ActivityNotFoundException ex) { ToastUtil.showToast(context, "?"); } }
From source file:com.java2s.intents4.IntentsDemo4Activity.java
private Intent createIntentFromEditTextFields() { String theAction = actionText.getText().toString().trim(); String theUri = uriText.getText().toString().trim(); String theMimeType = mimeTypeText.getText().toString().trim(); Intent intent = new Intent(); if (theAction.length() != 0) { intent.setAction(theAction);// w w w .j a va 2 s. c o m } intentHasBothUriAndType = false; if (theUri.length() != 0 && theMimeType.length() != 0) { intentHasBothUriAndType = true; intent.setDataAndType(Uri.parse(theUri), theMimeType); } else if (theUri.length() != 0) { intent.setData(Uri.parse(theUri)); } else if (theMimeType.length() != 0) { intent.setType(theMimeType); } if (intentCategoriesLayout != null) { int count = intentCategoriesLayout.getChildCount(); for (int i = 0; i < count; i++) { String cat = ((EditText) ((ViewGroup) intentCategoriesLayout.getChildAt(i)).getChildAt(1)).getText() .toString().trim(); if (cat.length() != 0) { intent.addCategory(cat); } } } Log.i(CLASSNAME, intent.toString()); return intent; }
From source file:com.CloudRecognition.CloudReco.java
public void goToWebProfesional(View view) { Intent intent = new Intent(Intent.ACTION_VIEW); Log.wtf("direccion", urlWebProfesional); intent.setData(Uri.parse(urlWebProfesional)); this.startActivity(intent); }
From source file:net.bytten.comicviewer.ComicViewerActivity.java
public void showArchive() { Intent i = new Intent(this, getArchiveActivityClass()); i.setData(comicDef.getArchiveUrl()); i.setAction(Intent.ACTION_VIEW);// w w w. j a v a2 s .c om i.putExtra(getPackageName() + "LoadType", ArchiveActivity.LoadType.ARCHIVE); startActivityForResult(i, PICK_ARCHIVE_ITEM); }
From source file:net.bytten.comicviewer.ComicViewerActivity.java
public void showBookmarks() { Intent i = new Intent(this, getArchiveActivityClass()); i.setData(comicDef.getArchiveUrl()); i.setAction(Intent.ACTION_VIEW);/*ww w .j a v a 2s.c om*/ i.putExtra(getPackageName() + "LoadType", ArchiveActivity.LoadType.BOOKMARKS); startActivityForResult(i, PICK_ARCHIVE_ITEM); }
From source file:babybear.akbquiz.ConfigActivity.java
/** * // w ww .j a va 2 s .co m */ protected void customBgImage() { DisplayMetrics dm = getResources().getDisplayMetrics(); int width = dm.widthPixels; int height = dm.heightPixels; Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null); intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); // intent.putExtra("crop", "circle"); // ? intent.putExtra("aspectX", width); // ? intent.putExtra("aspectY", height); // ? . intent.putExtra("output", Uri.fromFile(customBgImage));// intent.putExtra("outputFormat", "PNG");// ? intent.putExtra("noFaceDetection", true); // ? intent.putExtra("return-data", false); // ??Intent startActivityForResult(intent, REQUESTCODE_IMAGE); }
From source file:com.neka.cordova.inappbrowser.InAppBrowser.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. *///from ww w . j a va2s . c om public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { if (action.equals("open")) { this.callbackContext = callbackContext; final String url = args.getString(0); String t = args.optString(1); if (t == null || t.equals("") || t.equals(NULL)) { t = SELF; } final String target = t; final HashMap<String, Boolean> features = parseFeature(args.optString(2)); Log.d(LOG_TAG, "target = " + target); this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { String result = ""; // SELF if (SELF.equals(target)) { Log.d(LOG_TAG, "in self"); // load in webview if (url.startsWith("file://") || url.startsWith("javascript:") || Config.isUrlWhiteListed(url)) { Log.d(LOG_TAG, "loading in webview"); webView.loadUrl(url); } //Load the dialer else if (url.startsWith(WebView.SCHEME_TEL)) { try { Log.d(LOG_TAG, "loading in dialer"); Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse(url)); cordova.getActivity().startActivity(intent); } catch (android.content.ActivityNotFoundException e) { LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); } } // load in InAppBrowser else { Log.d(LOG_TAG, "loading in InAppBrowser"); result = showWebPage(url, features); } } // SYSTEM else if (SYSTEM.equals(target)) { Log.d(LOG_TAG, "in system"); result = openExternal(url); } // BLANK - or anything else else { Log.d(LOG_TAG, "in blank"); result = showWebPage(url, features); } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } }); } else if (action.equals("close")) { closeDialog(); } else if (action.equals("injectScriptCode")) { String jsWrapper = null; if (args.getBoolean(1)) { jsWrapper = String.format("prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')", callbackContext.getCallbackId()); } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectScriptFile")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('script'); c.src = %%s; c.onload = function() { prompt('', 'gap-iab://%s'); }; d.body.appendChild(c); })(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('script'); c.src = %s; d.body.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectStyleCode")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('style'); c.innerHTML = %%s; d.body.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('style'); c.innerHTML = %s; d.body.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectStyleFile")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%s; d.head.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %s; d.head.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("show")) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { dialog.show(); } }); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); } else { return false; } return true; }
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 w w .j a va2s .co m*/ //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.layer.atlas.messenger.AtlasMessagesScreen.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.uiHandler = new Handler(); this.app = (MessengerApp) getApplication(); setContentView(R.layout.atlas_screen_messages); boolean convIsNew = getIntent().getBooleanExtra(EXTRA_CONVERSATION_IS_NEW, false); String convUri = getIntent().getStringExtra(EXTRA_CONVERSATION_URI); if (convUri != null) { Uri uri = Uri.parse(convUri);// w w w.java2s.c o m conv = app.getLayerClient().getConversation(uri); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancel(convUri.hashCode()); // Clear notifications for this Conversation } participantsPicker = (AtlasParticipantPicker) findViewById(R.id.atlas_screen_messages_participants_picker); participantsPicker.init(new String[] { app.getLayerClient().getAuthenticatedUserId() }, app.getParticipantProvider()); if (convIsNew) { participantsPicker.setVisibility(View.VISIBLE); } messageComposer = (AtlasMessageComposer) findViewById(R.id.atlas_screen_messages_message_composer); messageComposer.init(app.getLayerClient(), conv); messageComposer.setListener(new AtlasMessageComposer.Listener() { public boolean beforeSend(Message message) { boolean conversationReady = ensureConversationReady(); if (!conversationReady) return false; // push preparePushMetadata(message); return true; } }); messageComposer.registerMenuItem("Photo", new OnClickListener() { public void onClick(View v) { if (!ensureConversationReady()) return; Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); String fileName = "cameraOutput" + System.currentTimeMillis() + ".jpg"; photoFile = new File(getExternalFilesDir(android.os.Environment.DIRECTORY_PICTURES), fileName); final Uri outputUri = Uri.fromFile(photoFile); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri); if (debug) Log.w(TAG, "onClick() requesting photo to file: " + fileName + ", uri: " + outputUri); startActivityForResult(cameraIntent, REQUEST_CODE_CAMERA); } }); messageComposer.registerMenuItem("Image", new OnClickListener() { public void onClick(View v) { if (!ensureConversationReady()) return; // in onCreate or any event where your want the user to select a file Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_CODE_GALLERY); } }); messageComposer.registerMenuItem("Location", new OnClickListener() { public void onClick(View v) { if (!ensureConversationReady()) return; if (lastKnownLocation == null) { Toast.makeText(v.getContext(), "Inserting Location: Location is unknown yet", Toast.LENGTH_SHORT).show(); return; } String locationString = "{\"lat\":" + lastKnownLocation.getLatitude() + ", \"lon\":" + lastKnownLocation.getLongitude() + "}"; MessagePart part = app.getLayerClient().newMessagePart(Atlas.MIME_TYPE_ATLAS_LOCATION, locationString.getBytes()); Message message = app.getLayerClient().newMessage(Arrays.asList(part)); preparePushMetadata(message); conv.send(message); if (debug) Log.w(TAG, "onSendLocation() loc: " + locationString); } }); messagesList = (AtlasMessagesList) findViewById(R.id.atlas_screen_messages_messages_list); messagesList.init(app.getLayerClient(), app.getParticipantProvider()); if (USE_QUERY) { Query<Message> query = Query.builder(Message.class) .predicate(new Predicate(Message.Property.CONVERSATION, Predicate.Operator.EQUAL_TO, conv)) .sortDescriptor(new SortDescriptor(Message.Property.POSITION, SortDescriptor.Order.ASCENDING)) .build(); messagesList.setQuery(query); } else { messagesList.setConversation(conv); } messagesList.setItemClickListener(new ItemClickListener() { public void onItemClick(Cell cell) { if (Atlas.MIME_TYPE_ATLAS_LOCATION.equals(cell.messagePart.getMimeType())) { String jsonLonLat = new String(cell.messagePart.getData()); JSONObject json; try { json = new JSONObject(jsonLonLat); double lon = json.getDouble("lon"); double lat = json.getDouble("lat"); Intent openMapIntent = new Intent(Intent.ACTION_VIEW); String uriString = String.format(Locale.ENGLISH, "geo:%f,%f?z=%d&q=%f,%f", lat, lon, 18, lat, lon); final Uri geoUri = Uri.parse(uriString); openMapIntent.setData(geoUri); if (openMapIntent.resolveActivity(getPackageManager()) != null) { startActivity(openMapIntent); if (debug) Log.w(TAG, "onItemClick() starting Map: " + uriString); } else { if (debug) Log.w(TAG, "onItemClick() No Activity to start Map: " + geoUri); } } catch (JSONException ignored) { } } else if (cell instanceof ImageCell) { Intent intent = new Intent(AtlasMessagesScreen.this.getApplicationContext(), AtlasImageViewScreen.class); app.setParam(intent, cell); startActivity(intent); } } }); typingIndicator = (AtlasTypingIndicator) findViewById(R.id.atlas_screen_messages_typing_indicator); typingIndicator.init(conv, new AtlasTypingIndicator.DefaultTypingIndicatorCallback(app.getParticipantProvider())); // location manager for inserting locations: this.locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); prepareActionBar(); }
From source file:com.hackensack.umc.activity.ProfileSelfieManualCropActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case Constant.FRAGMENT_CONST_REQUEST_IMAGE_CAPTURE: if (resultCode == RESULT_OK) { /*Intent intent = new Intent(ProfileSelfieActivity.this, ActivityCropImage.class); intent.setData(imageUri);//w w w. j a va 2 s .com startActivityForResult(intent, Constant.CROP_IMAGE_ACTIVITY);*/ //cropPictureIntent(imageUri); Intent intent = new Intent(ProfileSelfieManualCropActivity.this, ActivityCropImage.class); intent.setData(imageUri); // intent.putExtra(Constant.Cropp_InterFace, saveCroppedImage); intent.putExtra(Constant.SELECTED_IMAGE_VIEW, selectedImageView); startActivityForResult(intent, Constant.CROP_IMAGE_ACTIVITY); } break; default: if (resultCode == RESULT_OK) { try { if (data != null) { if (selectedImageView == Constant.SELFIE) { imageUri = data.getData(); /*CameraFunctionality.setPhotoToImageView(imageUri.toString(), imgSelfie, ProfileSelfieActivity.this); byte[] byteArray = getIntent().getByteArrayExtra(Constant.BITMAP_IMAGE); Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); getImageUris(imageUri, 5,bmp,null);*/ Bitmap bitmapImage = data.getParcelableExtra(Constant.CROPPED_IMAGE); //bitmapImage=data.getParcelableExtra(Constant.CROPPED_IMAGE); //bitmapImage = CameraFunctionality.getBitmapFromFile(imageUri.toString(), ProfileSelfieManualCropActivity.this); // String base64=CameraFunctionality.readBasee64File(data.getStringExtra(Constant.BASE64_FILE_PATH)); // String base64 = Base64Converter.createBase64StringFromBitmap(bitmapImage, ProfileSelfieManualCropActivity.this); // String base64=Base64Converter.createBitmapFromFileImage(imageUri); String base64 = Base64Converter.createBase64StringFromBitmap(bitmapImage, ProfileSelfieManualCropActivity.this); getImageUris(imageUri, selectedImageView, null, base64); //CameraFunctionality.setPhotoToImageView(imageUri.toString(), imgIcFront, getActivity()); // CameraFunctionality.setBitMapToImageView(imageUri.toString(), bitmapImage, imgSelfie, ProfileSelfieManualCropActivity.this); //pathSelfie = imageUri; /* Bitmap bitmapImage = CameraFunctionality.unCompressedImage(data.getByteArrayExtra(Constant.BITMAP_IMAGE)); pathSelfie=Base64Converter.createBase64StringFroImage(bitmapImage,ProfileSelfieActivity.this);*/ txtSefileSet.setText(R.string.done); } } } catch (Exception e) { e.printStackTrace(); } } break; } }