Was muss ich dann verändern?
Berechtigungen für eine App die ein Foto macht und anzeigt
-
-
Des bleibt unverändert
-
hast du die permission für die Cammera von User angefordert. denn das bemängelt er.
musst du genau so machen wie die schreib lese Permission -
hast du die permission für die Cammera von User angefordert. denn das bemängelt er.
Nein
-
Wie kann man das hinzufügen
-
genau so wie du die schreib lese permissoin gemacht hast.
-
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
-
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(); } } }
-
wieso hast du das noch drin
zeile 61-62- bildfile = new File(Environment.getExternalStorageDirectory() + "/FotoApp/bild.png");
- bilduri = Uri.fromFile(bildfile);
-
Hab ich vergessen rauszunehmen
-
Aber der Fehler ist immer noch da
-
du kannst nicht gleich alle Premisoin auf einmal holen.
-
Wie kann ich das dann sonst machen
-
Statt
JavaScriptActivityCompat.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);
Kannst du auch direkt ein Array aufbauen:JavaActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA},RQ);
Bin mir aber jetzt nicht sicher, ob das hilft.
-
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
-
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(); } } }
-
-
-
Ja du erzeugst damit einen Ordner der "bild.png" heißt!
-
Ok danke und wie wäre es dann richtig
Jetzt mitmachen!
Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!