が、私は写真を取り、ギャラリーに保存しますシンプルなアプリを持っているしたいのですが、ここに示すように:取って、絵のAndroidカメラを保存する:写真は私のデバイスに保存されていない
http://developer.android.com/training/camera/photobasics.htmlは、私がテストしました私のデバイス(2.1)のアプリ、私は写真を撮った、彼らは "ok"をクリックするように頼んだが、画像がギャラリーに保存されていない、あなたはなぜ知っていますか?どのようにエラーが発生するのか知ることができましたか? (エミュレータには「sdカード」がないので、本当にプロジェクトをデバッグすることはできません)。また、この技術とgetContentResolver().openOutputStream(uri);
の違いは何ですか:http://developer.android.com/guide/topics/providers/content-providers.html#modifying?
また、私はこのソリューションを試すことができました:Picture saving in emulator but not on deviceしかし、私のデバイスでコードが動作しないのはなぜですか?
package pack.one;
import java.io.File;
import java.io.IOException;
import java.sql.Date;
import java.text.SimpleDateFormat;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
public class TestPictureActivity extends Activity {
private static final String JPEG_FILE_SUFFIX = ".jpg";
Intent takePictureIntent;
String mCurrentPhotoPath;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dispatchTakePictureIntent(11);
}
private void dispatchTakePictureIntent(int actionCode) {
takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, actionCode);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
try {
handleSmallCameraPhoto(data);
} catch (IOException e) {
e.printStackTrace();
}
}
private void handleSmallCameraPhoto(Intent intent) throws IOException {
Bundle extras = intent.getExtras();
Bitmap mImageBitmap = (Bitmap) extras.get("data");
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.viewlayout, null);
ImageView mImageView = (ImageView) view.findViewById(R.id.V);
mImageView.setImageBitmap(mImageBitmap);
File f = createImageFile();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
galleryAddPic();
}
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date(0));
String imageFileName = timeStamp + "_";
File image = File.createTempFile(
imageFileName,
JPEG_FILE_SUFFIX,
null //default location for temporary files
);
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
private void galleryAddPic() {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}
}
編集:
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
が編集2:私は実際には、「電話」の絵を持っている場合には、誰かがアプリをテストしたい、私はマニフェストでこれらの2行を追加しました私はデバイスを私のコンピュータに接続して、私は正しい名前で新しい画像ファイルを見ることができますが、それは空ですので、私はそれを開くことができません。さらに、私のギャラリーには何も表示されません。
ありがとうございます
おかげビルは、私はこのラインでアプリを再インストールしますが、画像はまだ私のギャラリーに表示されていない、この行を入れていません。.. 。 – Paul