Created
January 1, 2014 09:53
-
-
Save TakamiChie/8206551 to your computer and use it in GitHub Desktop.
写真を共有するとき ref: http://qiita.com/TakamiChie/items/f998b11f34157a387abf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File file = /* 適当なFile(外部ストレージ上に保存している画像であること) */ | |
ContentResolver cr = context.getContentResolver(); | |
ContentValues cv = new ContentValues(); | |
cv.put(MediaStore.Images.Media.TITLE, file.getName()); | |
cv.put(MediaStore.Images.Media.DISPLAY_NAME, file.getName()); | |
cv.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis()); | |
cv.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); | |
cv.put(MediaStore.Images.Media.DATA, file.getAbsolutePath()); | |
Uri uri = cr.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, cv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File file = /* 適当なFile(外部ストレージ上に保存している画像であること) */ | |
ContentResolver cr = context.getContentResolver(); | |
Cursor c = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, | |
new String[] { BaseColumns._ID }, | |
MediaStore.Images.ImageColumns.DATA + " LIKE ?", | |
new String[] { Uri.fromFile(file).getPath() }, null); | |
c.moveToFirst(); | |
long id = c.getLong(c.getColumnIndex(BaseColumns._ID)); | |
c.close(); | |
Uri uri = Uri.withAppendedPath( | |
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Long.toString(id)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File file = /* 送信したいファイルを指定 */ | |
Intent intent = new Intent(Intent.ACTION_SEND); | |
intent.setType("image/jpeg"); | |
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); /* 追加 */ | |
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); /* 追加 */ | |
intent.setClassName(/*起動したいアプリのパッケージ名*/, /*起動したいアクティビティのクラス名*/); | |
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); | |
try { | |
startActivityForResult(intent, REQUEST_SEND); | |
} catch (ActivityNotFoundException e) { | |
Toast.makeText(getActivity(), ”アプリケーションの起動に失敗しました”, Toast.LENGTH_SHORT).show(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File file = /* 送信したいファイルを指定 */ | |
Intent intent = new Intent(Intent.ACTION_SEND); | |
intent.setType("image/jpeg"); | |
intent.setClassName(/*起動したいアプリのパッケージ名*/, /*起動したいアクティビティのクラス名*/); | |
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); | |
try { | |
startActivityForResult(intent, REQUEST_SEND); | |
} catch (ActivityNotFoundException e) { | |
Toast.makeText(getActivity(), ”アプリケーションの起動に失敗しました”, Toast.LENGTH_SHORT).show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment