List of usage examples for android.content Intent getData
public @Nullable Uri getData()
From source file:com.nonstop.android.SoC.BluetoothChat.BluetoothChat.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (D)/*from ww w .j a va 2 s .com*/ Log.d(TAG, "onActivityResult " + resultCode); switch (requestCode) { case REQUEST_CONNECT_DEVICE_SECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, true); } break; case REQUEST_CONNECT_DEVICE_INSECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, false); } break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { // Bluetooth is now enabled, so set up a chat session setupChat(); } else { // User did not enable Bluetooth or an error occured Log.d(TAG, "BT not enabled"); Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show(); finish(); } /* * if this is the activity result from authorization flow, do a call * back to authorizeCallback Source Tag: login_tag */ case AUTHORIZE_ACTIVITY_RESULT_CODE: { Utility.mFacebook.authorizeCallback(requestCode, resultCode, data); break; } /* * if this is the result for a photo picker from the gallery, upload the * image after scaling it. You can use the Utility.scaleImage() function * for scaling */ case PICK_EXISTING_PHOTO_RESULT_CODE: { if (resultCode == Activity.RESULT_OK) { Uri photoUri = data.getData(); if (photoUri != null) { Bundle params = new Bundle(); try { params.putByteArray("photo", Utility.scaleImage(getApplicationContext(), photoUri)); } catch (IOException e) { e.printStackTrace(); } params.putString("caption", "NonstopSoC"); Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null); } else { Toast.makeText(getApplicationContext(), "Error selecting image from the gallery.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "No image selected for upload.", Toast.LENGTH_SHORT).show(); } break; } } }
From source file:fm.smart.r1.ItemActivity.java
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); // this should be called once image has been chosen by user // using requestCode to pass item id - haven't worked out any other way // to do it//w w w . j a v a 2s . c o m // if (requestCode == SELECT_IMAGE) if (resultCode == Activity.RESULT_OK) { // TODO check if user is logged in if (LoginActivity.isNotLoggedIn(this)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(this, LoginActivity.class.getName()); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid navigation back to this? LoginActivity.return_to = ItemActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("item_id", (String) item.getId()); startActivity(intent); // TODO in this case forcing the user to rechoose the image // seems a little // rude - should probably auto-submit here ... } else { // Bundle extras = data.getExtras(); // String sentence_id = (String) extras.get("sentence_id"); final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Uploading image ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread add_image = new Thread() { public void run() { // TODO needs to check for interruptibility String sentence_id = Integer.toString(requestCode); Uri selectedImage = data.getData(); // Bitmap bitmap = Media.getBitmap(getContentResolver(), // selectedImage); // ByteArrayOutputStream bytes = new // ByteArrayOutputStream(); // bitmap.compress(Bitmap.CompressFormat.JPEG, 40, // bytes); // ByteArrayInputStream fileInputStream = new // ByteArrayInputStream( // bytes.toByteArray()); // TODO Might have to save to file system first to get // this // to work, // argh! // could think of it as saving to cache ... // add image to sentence FileInputStream is = null; FileOutputStream os = null; File file = null; ContentResolver resolver = getContentResolver(); try { Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes); // ByteArrayInputStream bais = new // ByteArrayInputStream(bytes.toByteArray()); // FileDescriptor fd = // resolver.openFileDescriptor(selectedImage, // "r").getFileDescriptor(); // is = new FileInputStream(fd); String filename = "test.jpg"; File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE); file = new File(dir, filename); os = new FileOutputStream(file); // while (bais.available() > 0) { // / os.write(bais.read()); // } os.write(bytes.toByteArray()); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (os != null) { try { os.close(); } catch (IOException e) { } } if (is != null) { try { is.close(); } catch (IOException e) { } } } // File file = new // File(Uri.decode(selectedImage.toString())); // ensure item is in users default list ItemActivity.add_item_result = new AddItemResult(Main.lookup.addItemToGoal(Main.transport, Main.default_study_goal_id, item.getId(), null)); Result result = ItemActivity.add_item_result; if (ItemActivity.add_item_result.success() || ItemActivity.add_item_result.alreadyInList()) { // ensure sentence is in users default goal ItemActivity.add_sentence_goal_result = new AddSentenceResult( Main.lookup.addSentenceToGoal(Main.transport, Main.default_study_goal_id, item.getId(), sentence_id, null)); result = ItemActivity.add_sentence_goal_result; if (ItemActivity.add_sentence_goal_result.success()) { String media_entity = "http://test.com/test.jpg"; String author = "tansaku"; String author_url = "http://smart.fm/users/tansaku"; Log.d("DEBUG-IMAGE-URI", selectedImage.toString()); ItemActivity.add_image_result = addImage(file, media_entity, author, author_url, "1", sentence_id, (String) item.getId(), Main.default_study_goal_id); result = ItemActivity.add_image_result; } } final Result display = result; myOtherProgressDialog.dismiss(); ItemActivity.this.runOnUiThread(new Thread() { public void run() { final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create(); dialog.setTitle(display.getTitle()); dialog.setMessage(display.getMessage()); dialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (ItemActivity.add_image_result != null && ItemActivity.add_image_result.success()) { ItemListActivity.loadItem(ItemActivity.this, item.getId().toString()); } } }); dialog.show(); } }); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { add_image.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { add_image.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); closeMenu(); myOtherProgressDialog.show(); add_image.start(); } } }
From source file:com.piusvelte.taplock.client.core.TapLockToggle.java
@Override public void onServiceConnected(ComponentName name, IBinder binder) { mServiceInterface = ITapLockService.Stub.asInterface(binder); if (mUIInterface != null) { try {/*from ww w. j a v a 2s. co m*/ mServiceInterface.setCallback(mUIInterface); } catch (RemoteException e) { Log.e(TAG, e.toString()); } } Intent intent = getIntent(); if (intent != null) { String action = intent.getAction(); if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action) && intent.hasExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) { Log.d(TAG, "service connected, NDEF_DISCOVERED"); Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage message; if (rawMsgs != null) { // process the first message message = (NdefMessage) rawMsgs[0]; // process the first record NdefRecord record = message.getRecords()[0]; if (record.getTnf() == NdefRecord.TNF_WELL_KNOWN) { try { byte[] payload = record.getPayload(); /* * payload[0] contains the "Status Byte Encodings" field, per the * NFC Forum "Text Record Type Definition" section 3.2.1. * * bit7 is the Text Encoding Field. * * if (Bit_7 == 0): The text is encoded in UTF-8 if (Bit_7 == 1): * The text is encoded in UTF16 * * Bit_6 is reserved for future use and must be set to zero. * * Bits 5 to 0 are the length of the IANA language code. */ String textEncoding = ((payload[0] & 0200) == 0) ? "UTF-8" : "UTF-16"; int languageCodeLength = payload[0] & 0077; String taggedDeviceName = new String(payload, languageCodeLength + 1, payload.length - languageCodeLength - 1, textEncoding); manageDevice(taggedDeviceName, ACTION_TOGGLE); } catch (UnsupportedEncodingException e) { // should never happen unless we get a malformed tag. Log.e(TAG, e.toString()); finish(); } } else finish(); } else finish(); } else if (intent.getData() != null) { String taggedDeviceName = intent.getData().getHost(); if (taggedDeviceName != null) manageDevice(taggedDeviceName, ACTION_TOGGLE); else finish(); } else if (ACTION_UNLOCK.equals(action) || ACTION_LOCK.equals(action) || ACTION_TOGGLE.equals(action)) manageDevice(intent.getStringExtra(EXTRA_DEVICE_NAME), action); else finish(); } else finish(); }
From source file:com.Beat.RingdroidEditActivity.java
/** Called with an Activity we started with an Intent returns. */ @Override//from w w w. ja va 2 s. com protected void onActivityResult(int requestCode, int resultCode, Intent dataIntent) { if (requestCode == REQUEST_CODE_CHOOSE_CONTACT) { // The user finished saving their ringtone and they're // just applying it to a contact. When they return here, // they're done. sendStatsToServerIfAllowedAndFinish(); return; } if (requestCode != REQUEST_CODE_RECORD) { return; } if (resultCode != RESULT_OK) { finish(); return; } if (dataIntent == null) { finish(); return; } // Get the recorded file and open it, but save the uri and // filename so that we can delete them when we exit; the // recorded file is only temporary and only the edited & saved // ringtone / other sound will stick around. mRecordingUri = dataIntent.getData(); mRecordingFilename = getFilenameFromUri(mRecordingUri); mFilename = mRecordingFilename; loadFromFile(); }
From source file:fm.smart.r1.activity.ItemActivity.java
@Override public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); // this should be called once image has been chosen by user // using requestCode to pass item id - haven't worked out any other way // to do it/* ww w . jav a 2s . c o m*/ // if (requestCode == SELECT_IMAGE) if (resultCode == Activity.RESULT_OK) { // TODO check if user is logged in if (Main.isNotLoggedIn(this)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(this, LoginActivity.class.getName()); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid navigation back to this? LoginActivity.return_to = ItemActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("item_id", (String) item.item_node.atts.get("id")); startActivity(intent); // TODO in this case forcing the user to rechoose the image // seems a little // rude - should probably auto-submit here ... } else { // Bundle extras = data.getExtras(); // String sentence_id = (String) extras.get("sentence_id"); final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Uploading image ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread add_image = new Thread() { public void run() { // TODO needs to check for interruptibility String sentence_id = Integer.toString(requestCode); Uri selectedImage = data.getData(); // Bitmap bitmap = Media.getBitmap(getContentResolver(), // selectedImage); // ByteArrayOutputStream bytes = new // ByteArrayOutputStream(); // bitmap.compress(Bitmap.CompressFormat.JPEG, 40, // bytes); // ByteArrayInputStream fileInputStream = new // ByteArrayInputStream( // bytes.toByteArray()); // TODO Might have to save to file system first to get // this // to work, // argh! // could think of it as saving to cache ... // add image to sentence FileInputStream is = null; FileOutputStream os = null; File file = null; ContentResolver resolver = getContentResolver(); try { Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes); // ByteArrayInputStream bais = new // ByteArrayInputStream(bytes.toByteArray()); // FileDescriptor fd = // resolver.openFileDescriptor(selectedImage, // "r").getFileDescriptor(); // is = new FileInputStream(fd); String filename = "test.jpg"; File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE); file = new File(dir, filename); os = new FileOutputStream(file); // while (bais.available() > 0) { // / os.write(bais.read()); // } os.write(bytes.toByteArray()); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (os != null) { try { os.close(); } catch (IOException e) { } } if (is != null) { try { is.close(); } catch (IOException e) { } } } // File file = new // File(Uri.decode(selectedImage.toString())); // ensure item is in users default list ItemActivity.add_item_result = addItemToList(Main.default_study_list_id, (String) item.item_node.atts.get("id"), ItemActivity.this); Result result = ItemActivity.add_item_result; if (ItemActivity.add_item_result.success() || ItemActivity.add_item_result.alreadyInList()) { // ensure sentence is in users default list ItemActivity.add_sentence_list_result = addSentenceToList(sentence_id, (String) item.item_node.atts.get("id"), Main.default_study_list_id, ItemActivity.this); result = ItemActivity.add_sentence_list_result; if (ItemActivity.add_sentence_list_result.success()) { String media_entity = "http://test.com/test.jpg"; String author = "tansaku"; String author_url = "http://smart.fm/users/tansaku"; Log.d("DEBUG-IMAGE-URI", selectedImage.toString()); ItemActivity.add_image_result = addImage(file, media_entity, author, author_url, "1", sentence_id, (String) item.item_node.atts.get("id"), Main.default_study_list_id); result = ItemActivity.add_image_result; } } final Result display = result; myOtherProgressDialog.dismiss(); ItemActivity.this.runOnUiThread(new Thread() { public void run() { final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create(); dialog.setTitle(display.getTitle()); dialog.setMessage(display.getMessage()); dialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (ItemActivity.add_image_result != null && ItemActivity.add_image_result.success()) { ItemListActivity.loadItem(ItemActivity.this, item.item_node.atts.get("id").toString()); } } }); dialog.show(); } }); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { add_image.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { add_image.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); closeMenu(); myOtherProgressDialog.show(); add_image.start(); } } }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@Override protected void onNewIntent(Intent intent) { // Handle clear XPrivacy data (needs UI refresh) Bundle extras = intent.getExtras();/*from ww w.ja v a2 s. co m*/ if (extras != null && extras.containsKey(cAction) && extras.getInt(cAction) == cActionRefresh) recreate(); else { // Refresh application list if (mAppAdapter != null) mAppAdapter.notifyDataSetChanged(); // Import pro license if (Intent.ACTION_VIEW.equals(intent.getAction())) Util.importProLicense(new File(intent.getData().getPath())); } }
From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java
@Override public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) { if (intent == null) return;//from ww w . jav a 2 s . c o m switch (requestCode) { case REQUEST_TAKE_PHOTO: { if (resultCode == Activity.RESULT_OK) { final String path = mImageUri.getPath(); final File file = path != null ? new File(path) : null; if (file != null && file.exists()) { mService.updateProfileImage(mUser.getId(), mImageUri, true); } } break; } case REQUEST_BANNER_TAKE_PHOTO: { if (resultCode == Activity.RESULT_OK) { final String path = mImageUri.getPath(); final File file = path != null ? new File(path) : null; if (file != null && file.exists()) { mService.updateBannerImage(mUser.getId(), mImageUri, true); } } break; } case REQUEST_PICK_IMAGE: { if (resultCode == Activity.RESULT_OK && intent != null) { final Uri uri = intent.getData(); final String image_path = getImagePathFromUri(getActivity(), uri); final File file = image_path != null ? new File(image_path) : null; if (file != null && file.exists()) { mService.updateProfileImage(mUser.getId(), Uri.fromFile(file), false); } } break; } case REQUEST_BANNER_PICK_IMAGE: { if (resultCode == Activity.RESULT_OK && intent != null) { final Uri uri = intent.getData(); final String image_path = getImagePathFromUri(getActivity(), uri); final File file = image_path != null ? new File(image_path) : null; if (file != null && file.exists()) { mService.updateBannerImage(mUser.getId(), Uri.fromFile(file), false); } } break; } case REQUEST_SET_COLOR: { if (resultCode == Activity.RESULT_OK && intent != null) { final int color = intent.getIntExtra(Accounts.USER_COLOR, Color.TRANSPARENT); setUserColor(getActivity(), mUserId, color); updateUserColor(); } break; } } }
From source file:it.feio.android.omninotes.DetailFragment.java
@SuppressLint("NewApi") @Override//from www. ja v a 2 s. com public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Fetch uri from activities, store into adapter and refresh adapter Attachment attachment; if (resultCode == Activity.RESULT_OK) { switch (requestCode) { case TAKE_PHOTO: attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_IMAGE); addAttachment(attachment); mAttachmentAdapter.notifyDataSetChanged(); mGridView.autoresize(); break; case TAKE_VIDEO: // Gingerbread doesn't allow custom folder so data are retrieved from intent if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_VIDEO); } else { attachment = new Attachment(intent.getData(), Constants.MIME_TYPE_VIDEO); } addAttachment(attachment); mAttachmentAdapter.notifyDataSetChanged(); mGridView.autoresize(); break; case FILES: onActivityResultManageReceivedFiles(intent); break; case SET_PASSWORD: noteTmp.setPasswordChecked(true); lockUnlock(); break; case SKETCH: attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_SKETCH); addAttachment(attachment); mAttachmentAdapter.notifyDataSetChanged(); mGridView.autoresize(); break; case CATEGORY: mainActivity.showMessage(R.string.category_saved, ONStyle.CONFIRM); Category category = intent.getParcelableExtra("category"); noteTmp.setCategory(category); setTagMarkerColor(category); break; case DETAIL: mainActivity.showMessage(R.string.note_updated, ONStyle.CONFIRM); break; } } }