В моей основной деятельности, вы нажимаете кнопку открывает приложение камеры. Когда фотография сделана в приложении «Камера», вы переходите ко второму упражнению. Таким образом, кнопка открывает приложение камеры и второе действие.
Я хочу, чтобы фотография, сделанная в первом упражнении, была показана во втором упражнении. Однако прямо сейчас код обнаруживается в основной активности.
Этот маленький андроид нуб буквально ценит любую помощь!
Я использовал код для функции камеры из: Захват изображения с камеры и отображение в действии
Основная деятельность Java (MainActivity.java):
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
private static final int MY_CAMERA_PERMISSION_CODE = 100;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.imageView = (ImageView) this.findViewById(R.id.takepicture);
Button photoButton = (Button) this.findViewById(R.id.button3);
photoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, Glamme.class);
startActivity(intent);
if (checkSelfPermission(Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CAMERA},
MY_CAMERA_PERMISSION_CODE);
} else {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
}
});
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == MY_CAMERA_PERMISSION_CODE) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "camera permission granted", Toast.LENGTH_LONG).show();
Intent cameraIntent = new
Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
} else {
Toast.makeText(this, "camera permission denied", Toast.LENGTH_LONG).show();
}
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
}
основная деятельность xml (activity_main.xml):
<Button
android:id="@+id/button3"
android:layout_width="98dp"
android:layout_height="0dp"
android:layout_marginBottom="1dp"
android:gravity="center_vertical|center_horizontal"
android:text="@string/glam_me"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6" />
<ImageView
android:id="@+id/takepicture"
android:layout_width="0dp"
android:layout_height="300dp"
android:layout_marginEnd="67dp"
android:layout_marginStart="67dp"
android:contentDescription="@string/todo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@android:color/transparent" />
</android.support.constraint.ConstraintLayout>
второе занятие java (Glamme.java)
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Glamme extends AppCompatActivity {
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_glamme);
this.imageView = (ImageView) this.findViewById(R.id.takepicture);
Bitmap bitmap=null;
Intent intent = getIntent();
if(intent!=null)
bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
imageView.setImageBitmap(bitmap);
}
вторая активность (activity_glamme.xml):
<ImageView
android:id="@+id/displaypicture"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="40dp"
android:layout_marginEnd="67dp"
android:layout_marginStart="67dp"
android:contentDescription="@string/todo"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:srcCompat="@android:color/transparent" />
</android.support.constraint.ConstraintLayout>
Журналы:
I/zygote: Not late-enabling -Xcheck:jni (already on)
W/zygote: Unexpected CPU variant for X86 using defaults: x86
I/zygote: WaitForGcToComplete blocked Background on None for 7.876ms
I/zygote: Background concurrent copying GC freed 8091(4MB) AllocSpace objects, 0(0B) LOS objects, 63% free, 897KB/2MB, paused 1.607ms total 367.085ms
I/InstantRun: starting instant run server: is main process
D/OpenGLRenderer: HWUI GL Pipeline
I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0
D/EGL_emulation: eglCreateContext: 0xdc485240: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xdc485240: ver 2 0 (tinfo 0xdc4832a0)
D/EGL_emulation: eglMakeCurrent: 0xdc485240: ver 2 0 (tinfo 0xdc4832a0)
V/StudioProfiler: StudioProfilers agent attached.
V/StudioProfiler: Acquiring Application for Events
V/StudioProfiler: Transformed class: java/net/URL
W/zygote: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
V/StudioProfiler: Memory control stream started.
V/StudioProfiler: Live memory tracking disabled.
V/StudioProfiler: Live memory tracking enabled.
JNIEnv not attached
V/StudioProfiler: Loaded classes: 5492
V/StudioProfiler: Tracking initialization took: 653867820ns
D/EGL_emulation: eglMakeCurrent: 0xdc485240: ver 2 0 (tinfo 0xdc4832a0)
E/StudioProfiler: JVMTI error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE)
I/chatty: uid=10080(xcevio.glamit2) Binder:14399_4 identical 1 line
E/StudioProfiler: JVMTI error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE)
E/StudioProfiler: JVMTI error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE)
E/StudioProfiler: JVMTI error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE)
W/zygote: Verification of void android.support.v4.view.AbsSavedState.<clinit>() took 590.693ms
I/zygote: CollectorTransition concurrent copying GC freed 3073(829KB) AllocSpace objects, 0(0B) LOS objects, 51% free, 1435KB/2MB, paused 100.074ms total 209.069ms
I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0
D/EGL_emulation: eglCreateContext: 0xdc485240: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xdc485240: ver 2 0 (tinfo 0xdc4832a0)
I/Choreographer: Skipped 63 frames! The application may be doing too much work on its main thread.
D/EGL_emulation: eglMakeCurrent: 0xdc485240: ver 2 0 (tinfo 0xdc4832a0)
I/zygote: Do partial code cache collection, code=27KB, data=30KB
I/zygote: After code cache collection, code=27KB, data=30KB
Increasing code cache capacity to 128KB