在 Android 应用程序中拍摄和发送照片
我目前正在尝试从我的应用程序中拍摄并发送照片。我尝试过不同的方法,但我要么选择在拍照前发送电子邮件,要么根本不选择。我需要发送图片然后选择消息客户端。有什么帮助吗?
public class PhotoHandler extends Activity {
private final static int TAKE_PHOTO_CODE = 1;
File downloadedPic;
Intent in;
boolean taken = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!taken) {
downloadedPic = takeandReturn(this, taken);
if (taken){
try {
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));
startActivity(Intent.createChooser(picMessageIntent, "Send Picture Using: "));
} catch (Exception e) {
Log.e("TAG", "sendPictureMessage() failed to start activity.", e);
Toast.makeText(this, "No handler", Toast.LENGTH_LONG).show();
}
}
}
}
private File getTempFile(Context context){
//it will return /sdcard/image.tmp
final File path = new File( Environment.getExternalStorageDirectory(), context.getPackageName() );
if(!path.exists()){
path.mkdir();
}
return new File(path, "image.jpg");
}
private File takeandReturn(Context context, boolean b) {
final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(this)) );
startActivityForResult(intent, TAKE_PHOTO_CODE);
final File path = new File( Environment.getExternalStorageDirectory(), context.getPackageName() );
if(!path.exists()){
path.mkdir();
}
b=true;
return new File(path, "image.jpg");
}
}
I am currently trying to take and send a photo from within my app. I have messed around with different ways but I either get the options as to how to send the email before the picture is taken, or not at all. I need to send the picture THEN choose the messaging client. Any help?
public class PhotoHandler extends Activity {
private final static int TAKE_PHOTO_CODE = 1;
File downloadedPic;
Intent in;
boolean taken = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!taken) {
downloadedPic = takeandReturn(this, taken);
if (taken){
try {
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));
startActivity(Intent.createChooser(picMessageIntent, "Send Picture Using: "));
} catch (Exception e) {
Log.e("TAG", "sendPictureMessage() failed to start activity.", e);
Toast.makeText(this, "No handler", Toast.LENGTH_LONG).show();
}
}
}
}
private File getTempFile(Context context){
//it will return /sdcard/image.tmp
final File path = new File( Environment.getExternalStorageDirectory(), context.getPackageName() );
if(!path.exists()){
path.mkdir();
}
return new File(path, "image.jpg");
}
private File takeandReturn(Context context, boolean b) {
final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(this)) );
startActivityForResult(intent, TAKE_PHOTO_CODE);
final File path = new File( Environment.getExternalStorageDirectory(), context.getPackageName() );
if(!path.exists()){
path.mkdir();
}
b=true;
return new File(path, "image.jpg");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查此教程
http://labs.makemachine.net/2010/03 /simple-android-photo-capture/
http://mobile.tutsplus.com/tutorials/android/android-sdk-sending-pictures-the-easy-way/
和本文档
http://developer.android.com/reference/android/content/Intent.html
Check this Tutorials
http://labs.makemachine.net/2010/03/simple-android-photo-capture/
http://mobile.tutsplus.com/tutorials/android/android-sdk-sending-pictures-the-easy-way/
and this documentation
http://developer.android.com/reference/android/content/Intent.html