本文整理汇总了Java中android.content.Intent.getData方法的典型用法代码示例。如果您正苦于以下问题:Java Intent.getData方法的具体用法?Java Intent.getData怎么用?Java Intent.getData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Intent
的用法示例。
在下文中一共展示了Intent.getData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActivityResult
import android.content.Intent; //导入方法依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RC_SIGN_IN){
if (resultCode == RESULT_OK){
Toast.makeText(this, "Sign in successful", Toast.LENGTH_SHORT).show();
} else if (requestCode == RESULT_CANCELED){
Toast.makeText(this, "Sign in cancelled", Toast.LENGTH_SHORT).show();
finish();
}
} else if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK){
Uri selectedImageUri = data.getData();
StorageReference photoRef = mChatPhotoStorageReference.child(selectedImageUri.getLastPathSegment());
photoRef.putFile(selectedImageUri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUrl = taskSnapshot.getDownloadUrl();
FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, downloadUrl.toString());
mMessagesDatabaseReference.push().setValue(friendlyMessage);
}
});
}
}
示例2: onActivityResult
import android.content.Intent; //导入方法依赖的package包/类
@Override
public void onActivityResult(int requestCode, int result, Intent data){
super.onActivityResult(requestCode, result, data);
if(requestCode==REQUEST_INFO_ACTIVITY&&result== RESULT_FILE_DELETED){
Uri file = data.getData();
for(int i = 0; i<= getFragmentManager().getBackStackEntryCount(); i++){
Fragment frag = getFragmentManager().findFragmentByTag("fragment_"+i);//tag specified in fragmenttransaction
if(frag != null&&frag instanceof ListingFragment){ //send uri to refresh
((ListingFragment)frag).onFileDelete(file);
}
}
}
}
示例3: onActivityResult
import android.content.Intent; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent resultData) {
super.onActivityResult(requestCode, resultCode, resultData);
switch (requestCode) {
case REQUEST_CODE_PICK_FILE:
if (resultCode == RESULT_OK && resultData != null) {
Uri uri = resultData.getData();
try {
if (uri != null) {
readKeyFromFile(uri);
} else {
String filename = resultData.getDataString();
if (filename != null) {
readKeyFromFile(Uri.parse(filename));
}
}
} catch (IllegalArgumentException e) {
Log.e(TAG, "Couldn't read from picked file", e);
}
}
break;
}
}
示例4: onReceive
import android.content.Intent; //导入方法依赖的package包/类
@Override
public void onReceive(final Context context, final Intent intent) {
final String action = intent.getAction();
final Uri uri = intent.getData();
if (uri == null || uri.getPath() == null) {
return;
}
Timber.v("StorageGoneReceiver: %s", intent);
final String path = uri.getPath();
if (Intent.ACTION_MEDIA_EJECT.equals(action)) {
StorageManager.getInstance(context).onBeforeUnmount(path);
} else if (Intent.ACTION_MEDIA_UNMOUNTED.equals(action)) {
StorageManager.getInstance(context).onAfterUnmount(path);
}
}
示例5: handleImageOnKitKat
import android.content.Intent; //导入方法依赖的package包/类
@TargetApi(19)
private void handleImageOnKitKat(Intent data) {
String imagePath = null;
Uri uri = data.getData();
if (DocumentsContract.isDocumentUri(mView.getActivity(), uri)) {
// 如果是documentlent类型的URI,则通过docment id处理
String docId = DocumentsContract.getDocumentId(uri);
if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
String id = docId.split(":")[1];
String selection = MediaStore.Images.Media._ID + "=" + id;
imagePath = getImagePatch(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
} else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId));
imagePath = getImagePatch(contentUri, null);
}
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
// 如果是content类型的uri的话,则使用普通方式处理
imagePath = getImagePatch(uri, null);
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
// 若果是file类型的uri,则直接获取图片路径
imagePath = uri.getPath();
}
copyFileInOtherThread(imagePath);
}
示例6: onActivityResult
import android.content.Intent; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//PDF
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PDF) {
Uri selectedUri_PDF = data.getData();
InputStream inputstream;
try {
inputstream = getContentResolver().openInputStream(selectedUri_PDF);
pdfview.fromStream(inputstream).load();
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(PdfView.this, "unable to open", Toast.LENGTH_SHORT).show();
}
}
}
else
{
startActivity(new Intent(PdfView.this,Subjects.class));
finish();
}
}
示例7: onActivityResult
import android.content.Intent; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ACacheKey.INPUT_CODE && resultCode == ACacheKey.INPUT_CODE) {
Bundle bundle = data.getExtras();
String resultString = bundle.getString(ACacheKey.INPUT_STRING);
if (StringUtils.isNotEmpty(resultString) && null != inPutView) {
inPutView.setText(resultString);
inPutView = null;
}
} else if (requestCode == 998 && resultCode == 998) {
ArrayList<String> strs = (ArrayList<String>) data.getExtras().get("data");
mvpPresenter.upLoadPhotos(strs);
// mvpPresenter.uploadPhoto(BitmapUtil.saveBitmapFile(BitmapUtil.getBitmap(strs), pathurl), type);
} else if (resultCode == RESULT_OK) {
String pathUrl;
if (requestCode == 1) {
pathUrl = mPhotoPath;
} else {
Uri uri = data.getData();
if (!TextUtils.isEmpty(uri.getAuthority())) {
pathUrl = getPathFromUri(uri);
} else {
pathUrl = uri.getPath();
}
}
mvpPresenter.uploadPhoto(BitmapUtil.saveBitmapFile(BitmapUtil.getBitmap(pathUrl), pathUrl), type);
}
}
示例8: onResult
import android.content.Intent; //导入方法依赖的package包/类
@OnActivityResult(REQUEST_CODE)
public void onResult(int resultCode, Intent intent) {
if (resultCode == RESULT_OK) {
uri = intent.getData();
displayFromUri(uri);
}
}
示例9: onActivityResult
import android.content.Intent; //导入方法依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Constants.RESULT_PROFILE_IMAGE_SELECTED) { // image selected. Crop the image
if (resultCode == RESULT_OK && data != null && data.getData() != null) {
startImageCrop(data.getData());
} else if (resultCode != RESULT_CANCELED) {
Toast.makeText(getActivity(), getString(R.string.image_selection_error), Toast.LENGTH_SHORT).show();
}
} else if (requestCode == Constants.RESULT_PROFILE_IMAGE_TAKEN) { // image taken. Crop the image
if (resultCode == RESULT_OK) {
Uri uri = FileProvider.getUriForFile(getActivity(), getString(R.string.file_provider),
mPresenter.getTempImageFileForOwner());
getActivity().revokeUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startImageCrop(uri);
} else if (resultCode != RESULT_CANCELED) {
Toast.makeText(getActivity(), getString(R.string.image_taking_error), Toast.LENGTH_SHORT).show();
}
} else if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { // image cropped
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
Bitmap bitmap = ImageHelper.decodeSampledBitmapFromUri(getActivity().getContentResolver(),
result.getUri(), Constants.PROFILE_IMAGE_WIDTH, Constants.PROFILE_IMAGE_HEIGHT);
mPresenter.newProfileImageSelected(bitmap);
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Diagnostic.logError(Diagnostic.DiagnosticFlag.Other, "Image failed to be cropped");
Toast.makeText(getActivity(), getString(R.string.image_selection_error), Toast.LENGTH_SHORT).show();
}
} else if (requestCode == Constants.RESULT_PROFILE_UPDATE && resultCode == Activity.RESULT_OK) { // bio updated
if (getView() != null) {
((TextView) getView().findViewById(R.id.profile_bio)).setText(data.getStringExtra("bio"));
Toast.makeText(getActivity(), getString(R.string.updated), Toast.LENGTH_SHORT).show();
}
}
}
示例10: onActivityResult
import android.content.Intent; //导入方法依赖的package包/类
/**
* call this method from the activity's onResult which was passed to requestSAFPermission method
*
* @param activity the activity whose onResult has been called on returning from document picker activity
* @param customKeyForStoringPermissionKey a custom key for storing saf permission uri
* @throws SAFOperationFailedException if the user did not gave the permission
*/
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data, @Nullable String customKeyForStoringPermissionKey) throws SAFOperationFailedException {
if (requestCode == REQUEST_CODE_SAF && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity);
String p = sharedPreferences.getString(getKeyForStoringPermissionKey(customKeyForStoringPermissionKey), null);
Uri oldUri = null;
if (p != null) oldUri = Uri.parse(p);
Uri treeUri = null;
if (resultCode == Activity.RESULT_OK) {
treeUri = data.getData();
if (treeUri != null)
sharedPreferences.edit().putString(getKeyForStoringPermissionKey(customKeyForStoringPermissionKey), treeUri.toString()).commit();
if (!TextUtils.isEmpty(customKeyForStoringPermissionKey))
sharedPreferences.edit().putString(KEY_CUSTOM_KEY, customKeyForStoringPermissionKey).commit();
}
// If not confirmed SAF, or if still not writable, then revert settings.
if (resultCode != Activity.RESULT_OK) {
if (treeUri != null)
sharedPreferences.edit().putString(getKeyForStoringPermissionKey(customKeyForStoringPermissionKey), oldUri.toString()).commit();
throw new SAFOperationFailedException("responseCode of result for saf request is not RESULT_OK. Its value is " + String.valueOf(resultCode));
}
activity.getContentResolver().takePersistableUriPermission(treeUri, data.getFlags()
& (Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION));
if (runPostSAFComplete != null)
runPostSAFComplete.run();
}
}
示例11: onActivityResult
import android.content.Intent; //导入方法依赖的package包/类
@Override
@TargetApi(Build.VERSION_CODES.KITKAT)
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
if (resultData != null) {
Uri uri = resultData.getData();
try {
getActivity().getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
String file = System.currentTimeMillis() + ".dr";//Daedalus Rule
InputStream inputStream = getActivity().getContentResolver().openInputStream(uri);
OutputStream outputStream = new FileOutputStream(Daedalus.rulePath + file);
byte[] b = new byte[1024];
while ((inputStream.read(b)) != -1) {
outputStream.write(b);
}
inputStream.close();
outputStream.close();
((EditTextPreference) findPreference("ruleFilename")).setText(file);
findPreference("ruleFilename").setSummary(file);
((EditTextPreference) findPreference("ruleDownloadUrl")).setText(uri.toString());
findPreference("ruleDownloadUrl").setSummary(uri.toString());
Snackbar.make(getView(), R.string.notice_importing_rule, Snackbar.LENGTH_LONG).show();
} catch (Exception e) {
Logger.logException(e);
}
}
}
}
示例12: onActivityResult
import android.content.Intent; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
mbuttonLoadImage.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
示例13: onCreate
import android.content.Intent; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ATTENTION: This was auto-generated to handle app links.
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
setContentView(linearLayout);
TextView textView = new TextView(this);
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
linearLayout.addView(textView);
int year = ParamUtils.getIntExtra(appLinkData, "year", 0);
double amount = ParamUtils.getDoubleExtra(appLinkData, "amount", 0.0);
String name = ParamUtils.getStringExtra(appLinkData, "name");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("The param is : year -> " + String.valueOf(year) + "\n");
stringBuilder.append("The param is : amount -> " + String.valueOf(amount) + "\n");
stringBuilder.append("The param is : name -> " + name + "\n");
textView.setText(stringBuilder);
}
示例14: getValue
import android.content.Intent; //导入方法依赖的package包/类
@Override
public String getValue(ComponentName resolvedComponent, Intent intent,
String resolvedType) {
Uri data = intent.getData();
if (data != null) {
return data.getScheme();
}
return null;
}
示例15: onActivityResult
import android.content.Intent; //导入方法依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult() called with: requestCode = [" + requestCode + "], resultCode = [" + resultCode + "]");
if (data != null && data.getData() != null) {
Log.d(TAG, "data = [" + data.getData().toString() + "]");
Response response = new Response(data.getData());
makeText(getContext(), response.getReason(), LENGTH_SHORT).show();
if (response.getResponseCode() == 0) {
sharedPreferencesManager.setStoneCode(stoneCode);
}
} else { makeText(getContext(), "no data content", LENGTH_SHORT).show();}
}