私のアプリにはカメラボタンがあります。このボタンをクリックすると、ネイティブ カメラ アプリが起動し、ユーザーは写真を撮ることができます。ユーザーが画像を受け入れると (チェック マークをタップ)、その画像を新しい画面に表示する新しいアクティビティを開始したいと考えています。次のように画像を保存しようとしています: File file = new File(this.getFilesDir(), filename); 次に、ファイル パスを取得し、そのパスを文字列として新しいアクティビティに渡します。私の新しいアクティビティでは、以前のインテントからファイルパスを取得し、それを使用してイメージを ImageView にロードしようとしています。イメージを ImageView にロードするためのビットを書き込む前に、新しい画面のテキスト領域にファイルパス文字列を出力して、ファイルパス文字列が渡されていることを確認したいと思いました。残念ながら、正常に通過していないようです。どんな助けでも大歓迎です。以下は私のコードのスニペットです。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_use_camera);
// create Intent to take a picture and return control to the calling application
Intent cameraintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//start the image capture Intent
startActivityForResult(cameraintent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
String filename = "myfile";
//make sure the user clicked to accept the picture in the native camera app
if (resultCode == RESULT_OK) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
{
//save image internally
File file = new File(this.getFilesDir(), filename);
//get the filepath
String filepath = file.getAbsolutePath();
//create the swatchintent
Intent Swatchintent = new Intent(this, DisplaySwatchActivity.class);
//pass filepath to the intent
Swatchintent.putExtra(EXTRA_MESSAGE, filepath);
//start the intent
startActivity(Swatchintent);
}
}
}
次に、私の次の活動:
public class DisplaySwatchActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_swatch);
String filepath = this.getIntent().getStringExtra(UseCameraActivity.EXTRA_MESSAGE);
TextView textView = new TextView(this);
textView.setTextSize(20);
textView.setText(filepath);
}