Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bastos
Created January 11, 2010 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastos/274493 to your computer and use it in GitHub Desktop.
Save bastos/274493 to your computer and use it in GitHub Desktop.
package bastos.sharetest;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.widget.Toast;
public class ShareTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/jpeg");
Log.i("MAIN", getLastImageThumbUri().toString());
intent.putExtra(Intent.EXTRA_STREAM, getLastImageThumbUri());
try {
startActivity(Intent.createChooser(intent, "Send file"));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Can't share this file", Toast.LENGTH_SHORT)
.show();
}
}
public Uri getLastImageThumbUri() {
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, // Which
// columns
// to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToLast();
return Uri.parse("file://" + cursor.getString(column_index));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment