Vielen Dank jetzt funktioniert es:D
Beiträge von Lukas
-
-
Wenn ich da bildfile.createNewFile() einesetze kommt der Fehler Unhandled Exception:java.io.IOException. Und dann scheu ich mir das mit den Ordnern lieber nochmal an.
-
Ok danke und wie wäre es dann richtig
-
-
Und das ist der code
Java
Alles anzeigenimport java.io.File; import android.Manifest; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.os.StrictMode; import android.provider.MediaStore; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; import android.widget.Toast; public class AalBild extends Activity { Button btn1; ImageView iv1; Intent bildintent; int RQ = 45; int RQ2 =23; int RQ3 =22; File bildfile; Uri bilduri; int Kameracode = 15; Bitmap bm1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_aal_bild); File dir = new File(Environment.getExternalStorageDirectory(), "FotoApp"); dir.mkdirs(); bildfile = new File(dir, "bild.png"); bildfile.mkdirs(); bilduri = Uri.fromFile(bildfile); StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); btn1 = (Button) findViewById(R.id.btn2); iv1 = (ImageView) findViewById(R.id.imageView4); if (bildfile.exists()){ bm1 = BitmapFactory.decodeFile(bildfile.getAbsolutePath()); iv1.setImageBitmap(bm1); } btn1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (ActivityCompat.checkSelfPermission(AalBild.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED){ if1(); }else { ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},RQ); } } }); } private void if1(){ if (ActivityCompat.checkSelfPermission(AalBild.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED){ if2(); }else { ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},RQ2); } } protected void if2(){ if (ActivityCompat.checkSelfPermission(AalBild.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED){ }else{ ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.CAMERA},RQ3); } } private void foto(){ try{ bildintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); bildintent.putExtra(MediaStore.EXTRA_OUTPUT, bilduri); startActivityForResult(bildintent, Kameracode); }catch(Exception e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Kamera nicht unterstützt!", Toast.LENGTH_SHORT).show(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK){ if(requestCode == Kameracode){ Toast.makeText(getApplicationContext(), "Bild gespeichert unter: " + bildfile.getAbsolutePath(), Toast.LENGTH_SHORT).show(); bm1 = BitmapFactory.decodeFile(bildfile.getAbsolutePath()); iv1.setImageBitmap(bm1); } } super.onActivityResult(requestCode, resultCode, data); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == RQ && grantResults.length >0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && requestCode == RQ2 && grantResults.length >0 && grantResults[0] ==PackageManager.PERMISSION_GRANTED && requestCode == RQ3 && grantResults.length >0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){ foto(); } } }
-
Jetzt kommt das hier
Code
Alles anzeigen9-07 14:38:16.525 28878-28878/com.jimdo.wachtel_web.fishcounter D/InputTransport: Input channel destroyed: fd=71 09-07 14:38:17.780 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@4c8d257[Aal]: ViewPostImeInputStage processPointer 0 09-07 14:38:17.926 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@4c8d257[Aal]: ViewPostImeInputStage processPointer 1 09-07 14:38:17.994 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@4c8d257[Aal]: MSG_WINDOW_FOCUS_CHANGED 0 09-07 14:38:17.998 28878-31539/com.jimdo.wachtel_web.fishcounter V/FA: Recording user engagement, ms: 2188 09-07 14:38:18.002 28878-31539/com.jimdo.wachtel_web.fishcounter V/FA: Activity paused, time: 18820679 09-07 14:38:18.015 28878-31539/com.jimdo.wachtel_web.fishcounter D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=2188, firebase_screen_class(_sc)=Aal, firebase_screen_id(_si)=8426542794729288185}] 09-07 14:38:18.045 28878-28878/com.jimdo.wachtel_web.fishcounter V/FA: onActivityCreated 09-07 14:38:18.076 28878-28878/com.jimdo.wachtel_web.fishcounter E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/FotoApp/bild.png (Is a directory) 09-07 14:38:18.088 28878-31539/com.jimdo.wachtel_web.fishcounter D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=Aal, firebase_previous_id(_pi)=8426542794729288185, firebase_screen_class(_sc)=AalBild, firebase_screen_id(_si)=8426542794729288187}] 09-07 14:38:18.089 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@8d46c94[AalBild]: ThreadedRenderer.create() translucent=false 09-07 14:38:18.094 28878-28878/com.jimdo.wachtel_web.fishcounter D/InputTransport: Input channel constructed: fd=73 09-07 14:38:18.095 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@8d46c94[AalBild]: setView = DecorView@9359c83[AalBild] touchMode=true 09-07 14:38:18.098 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@8d46c94[AalBild]: dispatchAttachedToWindow 09-07 14:38:18.135 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@8d46c94[AalBild]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,0][1440,2560] result=0x27 surface={isValid=true 496576610816} surfaceGenerationChanged=true mHardwareRenderer.initialize() mSurface={isValid=true 496576610816} hwInitialized=true 09-07 14:38:18.145 28878-31539/com.jimdo.wachtel_web.fishcounter V/FA: Activity resumed, time: 18820766 09-07 14:38:18.149 28878-28933/com.jimdo.wachtel_web.fishcounter D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1440x2560]-format:1 09-07 14:38:18.226 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@8d46c94[AalBild]: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1 MSG_WINDOW_FOCUS_CHANGED 1 mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 496576610816} 09-07 14:38:18.228 28878-28878/com.jimdo.wachtel_web.fishcounter V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@4d3047e nm : com.jimdo.wachtel_web.fishcounter ic=null 09-07 14:38:18.228 28878-28878/com.jimdo.wachtel_web.fishcounter I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus 09-07 14:38:18.245 28878-28878/com.jimdo.wachtel_web.fishcounter D/InputTransport: Input channel constructed: fd=81 Input channel destroyed: fd=75 09-07 14:38:18.294 28878-28933/com.jimdo.wachtel_web.fishcounter D/OpenGLRenderer: endAllActiveAnimators on 0x737c46b800 (RippleDrawable) with handle 0x73790681a0 09-07 14:38:18.294 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@4c8d257[Aal]: mHardwareRenderer.destroy()#1 09-07 14:38:18.302 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@4c8d257[Aal]: Relayout returned: oldFrame=[0,0][1440,2560] newFrame=[0,0][1440,2560] result=0x5 surface={isValid=false 0} surfaceGenerationChanged=true 09-07 14:38:23.148 28878-31539/com.jimdo.wachtel_web.fishcounter V/FA: Inactivity, disconnecting from the service
-
Wie kann ich das dann sonst machen
-
Aber der Fehler ist immer noch da
-
Hab ich vergessen rauszunehmen
-
Das ist jetzt mein code
Java
Alles anzeigenimport java.io.File; import android.Manifest; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.os.StrictMode; import android.provider.MediaStore; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; import android.widget.Toast; public class AalBild extends Activity { Button btn1; ImageView iv1; Intent bildintent; int RQ = 45; int RQ2 =23; int RQ3 =22; File bildfile; Uri bilduri; int Kameracode = 15; Bitmap bm1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_aal_bild); File dir = new File(Environment.getExternalStorageDirectory(), "FotoApp"); dir.mkdirs(); bildfile = new File(dir, "bild.png"); bildfile.mkdirs(); bilduri = Uri.fromFile(bildfile); StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); bildfile = new File(Environment.getExternalStorageDirectory() + "/FotoApp/bild.png"); bilduri = Uri.fromFile(bildfile); btn1 = (Button) findViewById(R.id.btn2); iv1 = (ImageView) findViewById(R.id.imageView4); if (bildfile.exists()){ bm1 = BitmapFactory.decodeFile(bildfile.getAbsolutePath()); iv1.setImageBitmap(bm1); } btn1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (ActivityCompat.checkSelfPermission(AalBild.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(AalBild.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(AalBild.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED){ foto(); }else { ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},RQ); ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},RQ2); ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.CAMERA},RQ3); } } }); } private void foto(){ try{ bildintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); bildintent.putExtra(MediaStore.EXTRA_OUTPUT, bilduri); startActivityForResult(bildintent, Kameracode); }catch(Exception e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Kamera nicht unterstützt!", Toast.LENGTH_SHORT).show(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK){ if(requestCode == Kameracode){ Toast.makeText(getApplicationContext(), "Bild gespeichert unter: " + bildfile.getAbsolutePath(), Toast.LENGTH_SHORT).show(); bm1 = BitmapFactory.decodeFile(bildfile.getAbsolutePath()); iv1.setImageBitmap(bm1); } } super.onActivityResult(requestCode, resultCode, data); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == RQ && grantResults.length >0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && requestCode == RQ2 && grantResults.length >0 && grantResults[0] ==PackageManager.PERMISSION_GRANTED && requestCode == RQ3 && grantResults.length >0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){ foto(); } } }
-
Ok jetzt kommt nur noch das hier
Code
Alles anzeigen09-07 13:56:21.555 20518-20518/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@af31241[AalBild]: ViewPostImeInputStage processPointer 0 09-07 13:56:21.657 20518-20518/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@af31241[AalBild]: ViewPostImeInputStage processPointer 1 09-07 13:56:21.686 20518-20518/com.jimdo.wachtel_web.fishcounter W/Activity: Can reqeust only one set of permissions at a time Can reqeust only one set of permissions at a time 09-07 13:56:21.691 20518-20518/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@af31241[AalBild]: MSG_WINDOW_FOCUS_CHANGED 0 09-07 13:56:21.693 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Recording user engagement, ms: 18409 09-07 13:56:21.694 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Connecting to remote service 09-07 13:56:21.699 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Activity paused, time: 16304989 09-07 13:56:21.711 20518-20541/com.jimdo.wachtel_web.fishcounter D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=18409, firebase_screen_class(_sc)=AalBild, firebase_screen_id(_si)=-1555849226117868159}] 09-07 13:56:21.753 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Connection attempt already in progress 09-07 13:56:21.753 20518-20541/com.jimdo.wachtel_web.fishcounter D/FA: Connected to remote service 09-07 13:56:21.757 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Processing queued up service tasks: 2 09-07 13:56:21.885 20518-20518/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@af31241[AalBild]: MSG_WINDOW_FOCUS_CHANGED 1 mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 496576610816} 09-07 13:56:21.915 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Activity resumed, time: 16305211 09-07 13:56:21.946 20518-20518/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@af31241[AalBild]: Relayout returned: oldFrame=[0,0][1440,2560] newFrame=[0,0][1440,2560] result=0x1 surface={isValid=true 496576610816} surfaceGenerationChanged=false 09-07 13:56:26.917 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Inactivity, disconnecting from the service
-
Wie kann man das hinzufügen
-
hast du die permission für die Cammera von User angefordert. denn das bemängelt er.
Nein
-
Des bleibt unverändert
-
Was muss ich dann verändern?
-
Ok das teste ich aus
-
Also ich hab die 2 zeilen in den on create Teil rein getan aber da passiert immer noch nicht das richtige
Code
Alles anzeigen09-07 13:20:28.259 9628-9628/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@d47e74b[AalBild]: ViewPostImeInputStage processPointer 0 09-07 13:20:28.301 9628-9628/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@d47e74b[AalBild]: ViewPostImeInputStage processPointer 1 09-07 13:20:28.333 9628-9628/com.jimdo.wachtel_web.fishcounter W/System.err: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.sec.android.app.camera/.Camera launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } clip={text/uri-list U:file:///storage/emulated/0/FotoApp/bild.png} (has extras) } from ProcessRecord{dcf7483 9628:com.jimdo.wachtel_web.fishcounter/u0a308} (pid=9628, uid=10308) with revoked permission android.permission.CAMERA 09-07 13:20:28.349 9628-9628/com.jimdo.wachtel_web.fishcounter W/System.err: at android.os.Parcel.readException(Parcel.java:1693) at android.os.Parcel.readException(Parcel.java:1646) at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3530) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1526) at android.app.Activity.startActivityForResult(Activity.java:4399) at android.app.Activity.startActivityForResult(Activity.java:4358) at com.jimdo.wachtel_web.fishcounter.AalBild.foto(AalBild.java:92) at com.jimdo.wachtel_web.fishcounter.AalBild.access$000(AalBild.java:25) at com.jimdo.wachtel_web.fishcounter.AalBild$1.onClick(AalBild.java:72) at android.view.View.performClick(View.java:6199) at android.widget.TextView.performClick(TextView.java:11090) 09-07 13:20:28.350 9628-9628/com.jimdo.wachtel_web.fishcounter W/System.err: at android.view.View$PerformClick.run(View.java:23647) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 09-07 13:20:28.394 9628-9666/com.jimdo.wachtel_web.fishcounter V/FA: Recording user engagement, ms: 10315 09-07 13:20:28.412 9628-9666/com.jimdo.wachtel_web.fishcounter V/FA: Connecting to remote service 09-07 13:20:28.416 9628-9628/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@84ca222[Toast]: ThreadedRenderer.create() translucent=true 09-07 13:20:28.433 9628-9628/com.jimdo.wachtel_web.fishcounter D/InputTransport: Input channel constructed: fd=67 09-07 13:20:28.433 9628-9628/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@84ca222[Toast]: setView = android.widget.LinearLayout{a5394b3 V.E...... ......I. 0,0-0,0} touchMode=true 09-07 13:20:28.435 9628-9628/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@84ca222[Toast]: dispatchAttachedToWindow 09-07 13:20:28.440 9628-9666/com.jimdo.wachtel_web.fishcounter V/FA: Activity paused, time: 14151688 09-07 13:20:28.441 9628-9666/com.jimdo.wachtel_web.fishcounter V/FA: Connection attempt already in progress 09-07 13:20:28.442 9628-9666/com.jimdo.wachtel_web.fishcounter V/FA: Activity resumed, time: 14151689 09-07 13:20:28.453 9628-9666/com.jimdo.wachtel_web.fishcounter D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=10315, firebase_screen_class(_sc)=AalBild, firebase_screen_id(_si)=7168516401446736101}] 09-07 13:20:28.476 9628-9628/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@84ca222[Toast]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[299,2128][1141,2304] result=0x27 surface={isValid=true 496576603648} surfaceGenerationChanged=true mHardwareRenderer.initialize() mSurface={isValid=true 496576603648} hwInitialized=true 09-07 13:20:28.477 9628-9666/com.jimdo.wachtel_web.fishcounter V/FA: Connection attempt already in progress 09-07 13:20:28.479 9628-9684/com.jimdo.wachtel_web.fishcounter D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [842x176]-format:1 09-07 13:20:28.496 9628-9628/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@84ca222[Toast]: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1 09-07 13:20:28.498 9628-9666/com.jimdo.wachtel_web.fishcounter D/FA: Connected to remote service 09-07 13:20:28.499 9628-9666/com.jimdo.wachtel_web.fishcounter V/FA: Processing queued up service tasks: 3 09-07 13:20:30.384 9628-9628/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@84ca222[Toast]: mHardwareRenderer.destroy()#4 dispatchDetachedFromWindow 09-07 13:20:30.406 9628-9628/com.jimdo.wachtel_web.fishcounter D/InputTransport: Input channel destroyed: fd=67 09-07 13:20:33.513 9628-9666/com.jimdo.wachtel_web.fishcounter V/FA: Inactivity, disconnecting from the service
-
Aber wenn ich starte steht in Logcat das
Code
Alles anzeigen09-07 12:48:09.028 9353-9353/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@4e35eae[AalBild]: ViewPostImeInputStage processPointer 0 09-07 12:48:09.116 9353-9353/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@4e35eae[AalBild]: ViewPostImeInputStage processPointer 1 09-07 12:48:09.122 9353-9353/com.jimdo.wachtel_web.fishcounter W/System.err: android.os.FileUriExposedException: file:///storage/emulated/0/FotoApp/bild.png exposed beyond app through ClipData.Item.getUri() at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799) 09-07 12:48:09.123 9353-9353/com.jimdo.wachtel_web.fishcounter W/System.err: at android.net.Uri.checkFileUriExposed(Uri.java:2354) at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832) at android.content.Intent.prepareToLeaveProcess(Intent.java:9508) at android.content.Intent.prepareToLeaveProcess(Intent.java:9493) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1525) at android.app.Activity.startActivityForResult(Activity.java:4399) at android.app.Activity.startActivityForResult(Activity.java:4358) at com.jimdo.wachtel_web.fishcounter.AalBild.foto(AalBild.java:83) at com.jimdo.wachtel_web.fishcounter.AalBild.access$000(AalBild.java:24) at com.jimdo.wachtel_web.fishcounter.AalBild$1.onClick(AalBild.java:63) at android.view.View.performClick(View.java:6199) at android.widget.TextView.performClick(TextView.java:11090) at android.view.View$PerformClick.run(View.java:23647) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 09-07 12:48:09.124 9353-9353/com.jimdo.wachtel_web.fishcounter W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 09-07 12:48:09.153 9353-9353/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@1e515e0[Toast]: ThreadedRenderer.create() translucent=true 09-07 12:48:09.159 9353-9353/com.jimdo.wachtel_web.fishcounter D/InputTransport: Input channel constructed: fd=67 09-07 12:48:09.160 9353-9353/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@1e515e0[Toast]: setView = android.widget.LinearLayout{674c099 V.E...... ......I. 0,0-0,0} touchMode=true 09-07 12:48:09.165 9353-9353/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@1e515e0[Toast]: dispatchAttachedToWindow 09-07 12:48:09.190 9353-9353/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@1e515e0[Toast]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[299,2128][1141,2304] result=0x27 surface={isValid=true 495929509376} surfaceGenerationChanged=true mHardwareRenderer.initialize() mSurface={isValid=true 495929509376} hwInitialized=true 09-07 12:48:09.192 9353-9442/com.jimdo.wachtel_web.fishcounter D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [842x176]-format:1 09-07 12:48:09.202 9353-9353/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@1e515e0[Toast]: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1 09-07 12:48:11.145 9353-9353/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@1e515e0[Toast]: mHardwareRenderer.destroy()#4 dispatchDetachedFromWindow 09-07 12:48:11.158 9353-9353/com.jimdo.wachtel_web.fishcounter D/InputTransport: Input channel destroyed: fd=67
-
Wie gesagt den Fehler hab ich schon gefunden, aber der code macht nicht was er soll
-
Ich hab den Fehler gefunden. Jetzt hab ich aber das Problem das ich zwar nach einer Permission gefragt werde aber der try part im code nicht ausgeführt wird
Java
Alles anzeigenimport java.io.File; import android.Manifest; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; import android.widget.Toast; public class AalBild extends Activity { Button btn1; ImageView iv1; Intent bildintent; int RQ = 45; int RQ2 =23; File bildfile; Uri bilduri; int Kameracode = 15; Bitmap bm1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_aal_bild); bildfile = new File(Environment.getExternalStorageDirectory() + "/FotoApp/bild.png"); bilduri = Uri.fromFile(bildfile); btn1 = (Button) findViewById(R.id.btn2); iv1 = (ImageView) findViewById(R.id.imageView4); if (bildfile.exists()){ bm1 = BitmapFactory.decodeFile(bildfile.getAbsolutePath()); iv1.setImageBitmap(bm1); } btn1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (ActivityCompat.checkSelfPermission(AalBild.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(AalBild.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED){ foto(); }else { ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},RQ); ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},RQ2); } } }); } private void foto(){ try{ bildintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); bildintent.putExtra(MediaStore.EXTRA_OUTPUT, bilduri); startActivityForResult(bildintent, Kameracode); }catch(Exception e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Kamera nicht unterstützt!", Toast.LENGTH_SHORT).show(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK){ if(requestCode == Kameracode){ Toast.makeText(getApplicationContext(), "Bild gespeichert unter: " + bildfile.getAbsolutePath(), Toast.LENGTH_SHORT).show(); bm1 = BitmapFactory.decodeFile(bildfile.getAbsolutePath()); iv1.setImageBitmap(bm1); } } super.onActivityResult(requestCode, resultCode, data); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == RQ && grantResults.length >0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && requestCode == RQ2 && grantResults.length >0 && grantResults[0] ==PackageManager.PERMISSION_GRANTED){ foto(); } } }