Berechtigungen für eine App die ein Foto macht und anzeigt

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Ok jetzt kommt nur noch das hier

    Quellcode

    1. 09-07 13:56:21.555 20518-20518/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@af31241[AalBild]: ViewPostImeInputStage processPointer 0
    2. 09-07 13:56:21.657 20518-20518/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@af31241[AalBild]: ViewPostImeInputStage processPointer 1
    3. 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
    4. Can reqeust only one set of permissions at a time
    5. 09-07 13:56:21.691 20518-20518/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@af31241[AalBild]: MSG_WINDOW_FOCUS_CHANGED 0
    6. 09-07 13:56:21.693 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Recording user engagement, ms: 18409
    7. 09-07 13:56:21.694 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Connecting to remote service
    8. 09-07 13:56:21.699 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Activity paused, time: 16304989
    9. 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}]
    10. 09-07 13:56:21.753 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Connection attempt already in progress
    11. 09-07 13:56:21.753 20518-20541/com.jimdo.wachtel_web.fishcounter D/FA: Connected to remote service
    12. 09-07 13:56:21.757 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Processing queued up service tasks: 2
    13. 09-07 13:56:21.885 20518-20518/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@af31241[AalBild]: MSG_WINDOW_FOCUS_CHANGED 1
    14. mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 496576610816}
    15. 09-07 13:56:21.915 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Activity resumed, time: 16305211
    16. 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
    17. 09-07 13:56:26.917 20518-20541/com.jimdo.wachtel_web.fishcounter V/FA: Inactivity, disconnecting from the service
    Alles anzeigen
  • Das ist jetzt mein code

    Java-Quellcode

    1. import java.io.File;
    2. import android.Manifest;
    3. import android.app.Activity;
    4. import android.content.Intent;
    5. import android.content.pm.PackageManager;
    6. import android.graphics.Bitmap;
    7. import android.graphics.BitmapFactory;
    8. import android.net.Uri;
    9. import android.os.Bundle;
    10. import android.os.Environment;
    11. import android.os.StrictMode;
    12. import android.provider.MediaStore;
    13. import android.support.annotation.NonNull;
    14. import android.support.v4.app.ActivityCompat;
    15. import android.view.Menu;
    16. import android.view.MenuItem;
    17. import android.view.View;
    18. import android.view.View.OnClickListener;
    19. import android.widget.Button;
    20. import android.widget.ImageView;
    21. import android.widget.Toast;
    22. public class AalBild extends Activity {
    23. Button btn1;
    24. ImageView iv1;
    25. Intent bildintent;
    26. int RQ = 45;
    27. int RQ2 =23;
    28. int RQ3 =22;
    29. File bildfile;
    30. Uri bilduri;
    31. int Kameracode = 15;
    32. Bitmap bm1;
    33. @Override
    34. protected void onCreate(Bundle savedInstanceState) {
    35. super.onCreate(savedInstanceState);
    36. setContentView(R.layout.activity_aal_bild);
    37. File dir = new File(Environment.getExternalStorageDirectory(), "FotoApp");
    38. dir.mkdirs();
    39. bildfile = new File(dir, "bild.png");
    40. bildfile.mkdirs();
    41. bilduri = Uri.fromFile(bildfile);
    42. StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
    43. StrictMode.setVmPolicy(builder.build());
    44. bildfile = new File(Environment.getExternalStorageDirectory() + "/FotoApp/bild.png");
    45. bilduri = Uri.fromFile(bildfile);
    46. btn1 = (Button) findViewById(R.id.btn2);
    47. iv1 = (ImageView) findViewById(R.id.imageView4);
    48. if (bildfile.exists()){
    49. bm1 = BitmapFactory.decodeFile(bildfile.getAbsolutePath());
    50. iv1.setImageBitmap(bm1);
    51. }
    52. btn1.setOnClickListener(new OnClickListener() {
    53. @Override
    54. public void onClick(View v) {
    55. 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){
    56. foto();
    57. }else {
    58. ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},RQ);
    59. ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},RQ2);
    60. ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.CAMERA},RQ3);
    61. }
    62. }
    63. });
    64. }
    65. private void foto(){
    66. try{
    67. bildintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    68. bildintent.putExtra(MediaStore.EXTRA_OUTPUT, bilduri);
    69. startActivityForResult(bildintent, Kameracode);
    70. }catch(Exception e) {
    71. e.printStackTrace();
    72. Toast.makeText(getApplicationContext(), "Kamera nicht unterstützt!", Toast.LENGTH_SHORT).show();
    73. }
    74. }
    75. @Override
    76. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    77. if (resultCode == RESULT_OK){
    78. if(requestCode == Kameracode){
    79. Toast.makeText(getApplicationContext(), "Bild gespeichert unter: " + bildfile.getAbsolutePath(), Toast.LENGTH_SHORT).show();
    80. bm1 = BitmapFactory.decodeFile(bildfile.getAbsolutePath());
    81. iv1.setImageBitmap(bm1);
    82. }
    83. }
    84. super.onActivityResult(requestCode, resultCode, data);
    85. }
    86. @Override
    87. public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    88. super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    89. 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){
    90. foto();
    91. }
    92. }
    93. }
    Alles anzeigen
  • Statt

    JavaScript-Quellcode

    1. ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},RQ);
    2. ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},RQ2);
    3. ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.CAMERA},RQ3);

    Kannst du auch direkt ein Array aufbauen:

    Java-Quellcode

    1. ActivityCompat.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

    Quellcode

    1. 9-07 14:38:16.525 28878-28878/com.jimdo.wachtel_web.fishcounter D/InputTransport: Input channel destroyed: fd=71
    2. 09-07 14:38:17.780 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@4c8d257[Aal]: ViewPostImeInputStage processPointer 0
    3. 09-07 14:38:17.926 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@4c8d257[Aal]: ViewPostImeInputStage processPointer 1
    4. 09-07 14:38:17.994 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@4c8d257[Aal]: MSG_WINDOW_FOCUS_CHANGED 0
    5. 09-07 14:38:17.998 28878-31539/com.jimdo.wachtel_web.fishcounter V/FA: Recording user engagement, ms: 2188
    6. 09-07 14:38:18.002 28878-31539/com.jimdo.wachtel_web.fishcounter V/FA: Activity paused, time: 18820679
    7. 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}]
    8. 09-07 14:38:18.045 28878-28878/com.jimdo.wachtel_web.fishcounter V/FA: onActivityCreated
    9. 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)
    10. 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}]
    11. 09-07 14:38:18.089 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@8d46c94[AalBild]: ThreadedRenderer.create() translucent=false
    12. 09-07 14:38:18.094 28878-28878/com.jimdo.wachtel_web.fishcounter D/InputTransport: Input channel constructed: fd=73
    13. 09-07 14:38:18.095 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@8d46c94[AalBild]: setView = DecorView@9359c83[AalBild] touchMode=true
    14. 09-07 14:38:18.098 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@8d46c94[AalBild]: dispatchAttachedToWindow
    15. 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
    16. mHardwareRenderer.initialize() mSurface={isValid=true 496576610816} hwInitialized=true
    17. 09-07 14:38:18.145 28878-31539/com.jimdo.wachtel_web.fishcounter V/FA: Activity resumed, time: 18820766
    18. 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
    19. 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
    20. MSG_WINDOW_FOCUS_CHANGED 1
    21. mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 496576610816}
    22. 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
    23. 09-07 14:38:18.228 28878-28878/com.jimdo.wachtel_web.fishcounter I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus
    24. 09-07 14:38:18.245 28878-28878/com.jimdo.wachtel_web.fishcounter D/InputTransport: Input channel constructed: fd=81
    25. Input channel destroyed: fd=75
    26. 09-07 14:38:18.294 28878-28933/com.jimdo.wachtel_web.fishcounter D/OpenGLRenderer: endAllActiveAnimators on 0x737c46b800 (RippleDrawable) with handle 0x73790681a0
    27. 09-07 14:38:18.294 28878-28878/com.jimdo.wachtel_web.fishcounter D/ViewRootImpl@4c8d257[Aal]: mHardwareRenderer.destroy()#1
    28. 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
    29. 09-07 14:38:23.148 28878-31539/com.jimdo.wachtel_web.fishcounter V/FA: Inactivity, disconnecting from the service
    Alles anzeigen
  • Und das ist der code

    Java-Quellcode

    1. import java.io.File;
    2. import android.Manifest;
    3. import android.app.Activity;
    4. import android.content.Intent;
    5. import android.content.pm.PackageManager;
    6. import android.graphics.Bitmap;
    7. import android.graphics.BitmapFactory;
    8. import android.net.Uri;
    9. import android.os.Bundle;
    10. import android.os.Environment;
    11. import android.os.StrictMode;
    12. import android.provider.MediaStore;
    13. import android.support.annotation.NonNull;
    14. import android.support.v4.app.ActivityCompat;
    15. import android.view.Menu;
    16. import android.view.MenuItem;
    17. import android.view.View;
    18. import android.view.View.OnClickListener;
    19. import android.widget.Button;
    20. import android.widget.ImageView;
    21. import android.widget.Toast;
    22. public class AalBild extends Activity {
    23. Button btn1;
    24. ImageView iv1;
    25. Intent bildintent;
    26. int RQ = 45;
    27. int RQ2 =23;
    28. int RQ3 =22;
    29. File bildfile;
    30. Uri bilduri;
    31. int Kameracode = 15;
    32. Bitmap bm1;
    33. @Override
    34. protected void onCreate(Bundle savedInstanceState) {
    35. super.onCreate(savedInstanceState);
    36. setContentView(R.layout.activity_aal_bild);
    37. File dir = new File(Environment.getExternalStorageDirectory(), "FotoApp");
    38. dir.mkdirs();
    39. bildfile = new File(dir, "bild.png");
    40. bildfile.mkdirs();
    41. bilduri = Uri.fromFile(bildfile);
    42. StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
    43. StrictMode.setVmPolicy(builder.build());
    44. btn1 = (Button) findViewById(R.id.btn2);
    45. iv1 = (ImageView) findViewById(R.id.imageView4);
    46. if (bildfile.exists()){
    47. bm1 = BitmapFactory.decodeFile(bildfile.getAbsolutePath());
    48. iv1.setImageBitmap(bm1);
    49. }
    50. btn1.setOnClickListener(new OnClickListener() {
    51. @Override
    52. public void onClick(View v) {
    53. if (ActivityCompat.checkSelfPermission(AalBild.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED){
    54. if1();
    55. }else {
    56. ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},RQ);
    57. }
    58. }
    59. });
    60. }
    61. private void if1(){
    62. if (ActivityCompat.checkSelfPermission(AalBild.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED){
    63. if2();
    64. }else {
    65. ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},RQ2);
    66. }
    67. }
    68. protected void if2(){
    69. if (ActivityCompat.checkSelfPermission(AalBild.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED){
    70. }else{
    71. ActivityCompat.requestPermissions(AalBild.this, new String[] {Manifest.permission.CAMERA},RQ3);
    72. }
    73. }
    74. private void foto(){
    75. try{
    76. bildintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    77. bildintent.putExtra(MediaStore.EXTRA_OUTPUT, bilduri);
    78. startActivityForResult(bildintent, Kameracode);
    79. }catch(Exception e) {
    80. e.printStackTrace();
    81. Toast.makeText(getApplicationContext(), "Kamera nicht unterstützt!", Toast.LENGTH_SHORT).show();
    82. }
    83. }
    84. @Override
    85. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    86. if (resultCode == RESULT_OK){
    87. if(requestCode == Kameracode){
    88. Toast.makeText(getApplicationContext(), "Bild gespeichert unter: " + bildfile.getAbsolutePath(), Toast.LENGTH_SHORT).show();
    89. bm1 = BitmapFactory.decodeFile(bildfile.getAbsolutePath());
    90. iv1.setImageBitmap(bm1);
    91. }
    92. }
    93. super.onActivityResult(requestCode, resultCode, data);
    94. }
    95. @Override
    96. public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    97. super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    98. 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){
    99. foto();
    100. }
    101. }
    102. }
    Alles anzeigen
  • Quellcode

    1. Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/FotoApp/bild.png (Is a directory)
    Nun du bekommst den Fehler das die Datei nicht gefunden wurde. Da bild.png ein Ordner ist.
    Das liegt daran das du einen Ordner stellst.

    Java-Quellcode

    1. bildfile = new File(dir, "bild.png");
    2. bildfile.mkdirs();
  • Xcreen schrieb:

    Quellcode

    1. Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/FotoApp/bild.png (Is a directory)
    Nun du bekommst den Fehler das die Datei nicht gefunden wurde. Da bild.png ein Ordner ist.
    Das liegt daran das du einen Ordner stellst.

    Java-Quellcode

    1. bildfile = new File(dir, "bild.png");
    2. bildfile.mkdirs();
    Der java code ist ja soweit bei mir derselbe oder