下面列出了android.content.Intent#ACTION_ATTACH_DATA 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void setPhotoAs() {
if (!(albumItem instanceof Photo)) {
return;
}
Uri uri = albumItem.getUri(this);
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(uri, MediaType.getMimeType(this, uri));
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivityForResult(Intent.createChooser(intent,
getString(R.string.set_as)), 13);
} catch (SecurityException se) {
Toast.makeText(this, "Error (SecurityException)", Toast.LENGTH_SHORT).show();
se.printStackTrace();
} catch (ActivityNotFoundException anfe) {
Toast.makeText(this, "No App found", Toast.LENGTH_SHORT).show();
anfe.printStackTrace();
}
}
public void onSetFabClick(View view) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
if (mFile != null && mFile.exists()) {
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(Uri.fromFile(mFile), "image/jpeg");
intent.putExtra("mimeType", "image/jpeg");
this.startActivity(Intent.createChooser(intent, "Set as:"));
return;
}
if (mService != null) {
if (isDownloading) {
ToastCenter.with(PhotoActivity.this).text(R.string.toast_download_is_executing).showShort();
return;
}
download();
} else {
bindStreamService();
}
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
}
}
private void wallpaperDownloadSuccess(DownloadMissionEntity entity) {
// Uri file = Uri.parse("file://" + entity.getFilePath());
Uri file = FileUtils.filePathToUri(context, entity.getFilePath());
Intent action = new Intent(Intent.ACTION_ATTACH_DATA);
action.setDataAndType(file, "image/jpg");
action.putExtra("mimeType", "image/jpg");
Mysplash.getInstance()
.getTopActivity()
.startActivity(
Intent.createChooser(
action,
Mysplash.getInstance()
.getString(R.string.feedback_choose_wallpaper_app)));
}
public static Intent createSetAsIntent(IImage image) {
Uri u = image.fullSizeImageUri();
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(u, image.getMimeType());
intent.putExtra("mimeType", image.getMimeType());
return intent;
}
void setWallpaper() {
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(currentImageUri, "image/*");
intent.putExtra("mimeType", "image/*");
this.startActivity(Intent.createChooser(intent, getResources().getString(R.string.set_as)));
}
public static Intent createSetAsIntent(IImage image) {
Uri u = image.fullSizeImageUri();
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(u, image.getMimeType());
intent.putExtra("mimeType", image.getMimeType());
return intent;
}
public static Intent createSetAsIntent(IImage image) {
Uri u = image.fullSizeImageUri();
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(u, image.getMimeType());
intent.putExtra("mimeType", image.getMimeType());
return intent;
}
public void doSettings() {
if (!TextUtils.isEmpty(imageUri)) {
Uri uri = Uri.parse(imageUri);
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(uri, "image/jpg");
intent.putExtra("mimeType", "image/jpg");
startActivityForResult(Intent.createChooser(intent, getText(R.string.action_settings)), 200);
}
}
public static Intent setAsAvatar(FileReference location) {
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(getAvatarUri(location), "image/jpg");
intent.putExtra("mimeType", "image/jpg");
return intent;
}