I want to return a bitmap in my activity, so other applications can use it.
Returning a text is clear.
Intent data = new Intent();
data.putExtra("text1", "text.");
data.putExtra("text2", "longer text.");
setResult(RESULT_OK, data);
But how to return a bitmap?
More Information: The activity has several intents to be available for everyone who wants to get a image.
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.OPENABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="vnd.android.cursor.dir/image" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="vnd.android.cursor.dir/image" />
</intent-filter>
EDIT: Here is the solution in one function:
public void finish(Bitmap bitmap) {
try {
File folder = new File(Environment.getExternalStorageDirectory() + "/Icon Select/");
if(!folder.exists()) {
folder.mkdirs();
}
File nomediaFile = new File(folder, ".nomedia");
if(!nomediaFile.exists()) {
nomediaFile.createNewFile();
}
FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/Icon Select/latest.png");
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
File bitmapFile = new File(Environment.getExternalStorageDirectory() + "/Icon Select/latest.png");
if(bitmapFile.exists()) {
Intent localIntent = new Intent().setData(Uri.fromFile(bitmapFile));
setResult(RESULT_OK, localIntent);
} else {
setResult(RESULT_CANCELED);
}
super.finish();
} catch (Exception e) {
e.printStackTrace();
Log.d("beewhale", "Error writing data");
}
}