title: How to get access to my camera from my app in Android
body: <p>I am creating a app. In this application I want to open my camera and I want to save it.</p>
  
  <p>So I wrote code to do that </p>
  
  <pre><code>takepic.setOnClickListener(new View.OnClickListener() {
  
          @Override
  
          public void onClick(View v) {
  
              count++;
              String file = dir+count+".jpg";
              File newfile = new File(file);
  
              try {
                  newfile.createNewFile();
              }
              catch (IOException e)
              {
  
              }
  
              Uri outputFileUri = Uri.fromFile(newfile);
  
              Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
              cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
  
              startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
  
          }
      });
  </code></pre>
  
  <p>and also i have added the permission to the manifest file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;uses-feature android:name="android.hardware.camera"
      android:required="true" /&gt;
  
  
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.CAMERA"/&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/&gt;
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;meta-data
          android:name="com.facebook.sdk.ApplicationId"
          android:value="@string/app_id" /&gt;
  
      &lt;activity android:name=".LoginActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity
          android:name="com.facebook.FacebookActivity"
          android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.Translucent.NoTitleBar" /&gt;
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/title_activity_main"
          android:theme="@style/AppTheme.NoActionBar"&gt;&lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>But when I try to open the camera I am getting this error:</p>
  
  <pre><code>java.lang.SecurityException: Permission Denial: 
  </code></pre>
  
  <p>Why am I getting this since I have added the permissions</p>
  
  <p>This is my error in the log </p>
  
  <pre><code>04-05 14:03:56.839 9562-9562/com.example.pavithraprabodha.selfimania E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                     Process: com.example.pavithraprabodha.selfimania, PID: 9562
                                                                                     java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.android.camera/.Camera clip={text/uri-list U:file:///storage/emulated/0/Pictures/Selfimania/1.jpg} (has extras) } from ProcessRecord{420a1c9 9562:com.example.pavithraprabodha.selfimania/u0a58} (pid=9562, uid=10058) with revoked permission android.permission.CAMERA
                                                                                         at android.os.Parcel.readException(Parcel.java:1599)
                                                                                         at android.os.Parcel.readException(Parcel.java:1552)
                                                                                         at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2658)
                                                                                         at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)
                                                                                         at android.app.Activity.startActivityForResult(Activity.java:3917)
                                                                                         at android.support.v4.app.ActivityCompatJB.startActivityForResult(ActivityCompatJB.java:30)
                                                                                         at android.support.v4.app.ActivityCompat.startActivityForResult(ActivityCompat.java:162)
                                                                                         at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:925)
                                                                                         at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:1008)
                                                                                         at android.support.v4.app.Fragment.startActivityForResult(Fragment.java:940)
                                                                                         at android.support.v4.app.Fragment.startActivityForResult(Fragment.java:929)
                                                                                         at com.example.pavithraprabodha.selfimania.Add_new_fragement$2.onClick(Add_new_fragement.java:89)
                                                                                         at android.view.View.performClick(View.java:5198)
                                                                                         at android.view.View$PerformClick.run(View.java:21147)
                                                                                         at android.os.Handler.handleCallback(Handler.java:739)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  </code></pre>