|
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)); |
|
|
|
} |
|
} |