В первом действии есть кнопка, при нажатии на которую открывается встроенная камера. Теперь, когда изображение сделано, открывается новое действие с изображением, снятым в
imageView
, и кнопкой «Поделиться» в следующем действии. Я настроил действие так, чтобы оно открывалось после того, как изображение будет снято, однако я не могу передать изображение, снятое между действиями. Пожалуйста, мне нужна помощь или толчок в правильном направлении.
Первое действие, которое делает снимок, это Takepicture.java
:
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.os.Environment;
import java.io.File;
import java.util.Date;
public class TakePicture extends Activity {
Button camerabutton;
Intent intent;
int requestCode;
int resultCode;
static int REQUEST_IMAGE_CAPTURE = 1;
SharedPreferences imagepreferences;
SharedPreferences.Editor imageeditor;
private String imgPath;
Uri setImageUri;
File file;
Uri imgUri;
public String getImagePath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.takepicture);
camerabutton = (Button) findViewById(R.id.button6);
imagepreferences=getSharedPreferences("image", MODE_PRIVATE);
imageeditor=imagepreferences.edit();
camerabutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null)
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
startActivity(new Intent(TakePicture.this, Aftertakepicture.class));
}
}
}
второе действие, Aftertakepicture.java
:
package com.example.kesandunwokolo.febclasstest;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
public class Aftertakepicture extends Activity {
Button camerabutton;
ImageView saveimage;
Button sharebutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aftertakepicture);
camerabutton=(Button)findViewById(R.id.button6);
saveimage=(ImageView)findViewById(R.id.imageView2);
sharebutton=(Button)findViewById(R.id.button7);
}
}
takepicture.xml
для первого действия:
<?xml version="1.0" encoding="utf-8"?>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Take Picture"
android:id="@+id/button6" />
aftertakepicture.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Take Picture"
android:id="@+id/button6" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:minHeight="100dp"
android:minWidth="100dp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Share"
android:id="@+id/button7" />
</LinearLayout>
пожалуйста, любая помощь будет оценена!
if (resultCode == RESULT_OK) { if (mFileUri != null) { mFilePath = mFileUri.toString(); ... intent.putExtra("filepath", mFilePath); startActivity(intent); ... } }
- person BNK   schedule 21.08.2015Intent intent = new Intent(mContext, SecondActivity.class);
, которое я проверил. Более того, в SecondActivity вы должны обрабатыватьIntent intent = getIntent(); String filepath = intent.getStringExtra("filepath");
в onCreate - person BNK   schedule 21.08.2015