title: Neither user 10232 nor current process has android.permission.READ_PROFILE
body: <p>When I launched the app on Samsung S3 neo  the app crashes with following Security Exception:</p>
  
  <pre><code>java.lang.RuntimeException: An error occured while executing doInBackground()
                        at android.os.AsyncTask$3.done(AsyncTask.java:300)
                        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
                        at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
                        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                        at java.lang.Thread.run(Thread.java:841)
                     Caused by: java.lang.SecurityException: Neither user 10232 nor current process has android.permission.READ_PROFILE.
                        at android.os.Parcel.readException(Parcel.java:1472)
                        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
                        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
                        at android.content.ContentProviderProxy.query(ContentProviderNative.java:413)
                        at android.content.ContentResolver.query(ContentResolver.java:470)
                        at android.content.CursorLoader.loadInBackground(CursorLoader.java:65)
                        at android.content.CursorLoader.loadInBackground(CursorLoader.java:43)
                        at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)
                        at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
                        at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:57)
                        at android.os.AsyncTask$2.call(AsyncTask.java:288)
                        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  </code></pre>
  
  <p><strong>Androidmanifest.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.ulguru.lms.myapplication"&gt;
  
      &lt;!-- To auto-complete the email text field in the login form with the user's emails --&gt;
      &lt;uses-feature
          android:name="android.hardware.telephony"
          android:required="true" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_CONTACTS" /&gt;
      &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;`
          &lt;activity android:name=".TabActivity1"&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=".ChooseLoginTypeActivity" /&gt;
          &lt;activity
              android:name=".LoginActivity"
              android:label="@string/title_activity_login" /&gt;
          &lt;activity android:name=".SignUpActivity" /&gt;
          &lt;activity
              android:name=".ListActivity"
              android:label="@string/title_activity_list"
              android:theme="@style/AppTheme.NoActionBar" /&gt;
          &lt;activity android:name=".TabActivity" /&gt;
          &lt;activity android:name=".UpCmngCourseListActivity" /&gt;
          &lt;activity
              android:name=".VideoActivity"
              android:configChanges="orientation|screenSize"
              android:label="@string/title_activity_video"
              android:theme="@style/AppTheme"/&gt;
          -
          &lt;activity
              android:name=".MainActivity"
              android:theme="@style/AppTheme"/&gt;
          &lt;activity
              android:name=".AboutUSActivity"
              android:label="@string/title_activity_about_us"
              android:theme="@style/AppTheme" /&gt;
          &lt;activity
              android:name=".PurchaseActivity"
              android:label="@string/title_activity_purchase"
              android:theme="@style/AppTheme"/&gt;
          &lt;activity
              android:name=".FeedBackActivity"
              android:label="@string/title_activity_feed_back"
              android:theme="@style/AppTheme"/&gt;
          &lt;meta-data
              android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" /&gt;
  
          &lt;activity
              android:name=".OfflineVideoActivity"
              android:label="@string/title_activity_offline_video"
              android:theme="@style/AppTheme"/&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>Login Activity</strong></p>
  
  <pre><code>public class LoginActivity extends AppCompatActivity implements LoaderCallbacks&lt;Cursor&gt; {
  
      /**
       * Id to identity READ_CONTACTS permission request.
       */
      private static final int REQUEST_READ_CONTACTS = 0;
      private static final int REQUEST_ACCESS_FINE_LOCATION = 0;
      private static final int REQUEST_READ_EXTERNAL_STORAGE = 0;
      JSONArray jsonArray;
      public static final String MyPREFERENCES = "MyPrefs" ;
      static final int DIALOG_ERROR_CONNECTION = 1;
      SessionManager sessionManager;
      String email;
      private UserLoginTask mAuthTask = null;
  
      // UI references.
      private AutoCompleteTextView mEmailView;
      private EditText mPasswordView;
      private View mProgressView;
      private View mLoginFormView;
      SharedPreferences sharedpreferences;
      ConnectivityManager connectivityManager;
      NetworkInfo wifiNetwork;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
          sessionManager = new SessionManager(getApplicationContext());
          // Set up the login form.
          mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
          populateAutoComplete();
  
          if (hasConnection(LoginActivity.this)){
              //call methods
              //getJsonData();
          }
          else{
              showNetDisabledAlertToUser(LoginActivity.this);
          }
  
          mPasswordView = (EditText) findViewById(R.id.password);
          mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
              @Override
              public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
  
                /*check the interet connection*/
  
  
                  if (id == R.id.login || id == EditorInfo.IME_NULL) {
                      attemptLogin();
                      return true;
                  }
                  return false;
              }
          });
          sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
          Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
          mEmailSignInButton.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View view) {
                  attemptLogin();
              }
          });
  
          mLoginFormView = findViewById(R.id.login_form);
          mProgressView = findViewById(R.id.login_progress);
  
  
      }
  
  
      public boolean hasConnection(Context context){
          ConnectivityManager cm=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
          wifiNetwork=cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
          if (wifiNetwork != null &amp;&amp; wifiNetwork.isConnected()){
              return true;
          }
          NetworkInfo mobileNetwork=cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
          if (mobileNetwork != null &amp;&amp; mobileNetwork.isConnected()){
              return true;
          }
          NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
          if (activeNetwork != null &amp;&amp; activeNetwork.isConnected()){
              return true;
          }
          return false;
      }
  
      public static void showNetDisabledAlertToUser(final Context context){
          AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
          alertDialogBuilder.setMessage("Would you like to enable it?")
                  .setTitle("No Internet Connection")
                  .setPositiveButton(" Enable Internet ", new DialogInterface.OnClickListener(){
                      public void onClick(DialogInterface dialog, int id){
                          Intent dialogIntent = new Intent(android.provider.Settings.ACTION_SETTINGS);
                          dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                          context.startActivity(dialogIntent);
                      }
                  });
  
          alertDialogBuilder.setNegativeButton(" Cancel ", new DialogInterface.OnClickListener(){
              public void onClick(DialogInterface dialog, int id){
                  dialog.cancel();
              }
          });
          AlertDialog alert = alertDialogBuilder.create();
          alert.show();
      }
  
  
      private void populateAutoComplete() {
          /*if (!mayRequestContacts()) {
              return;
          }*/
          if(!myRequestLocation()){
              return;
          }
          if(!myRequestStorage()){
              return;
          }
          if(!mayRequestContacts()){
              return;
          }
  
  
          getLoaderManager().initLoader(0, null, this);
      }
  
     private boolean mayRequestContacts() {
          if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.M) {
              return true;
          }
          if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
              return true;
          }
          if (shouldShowRequestPermissionRationale(READ_CONTACTS)) {
              Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE)
                      .setAction(android.R.string.ok, new View.OnClickListener() {
                          @Override
                          @TargetApi(Build.VERSION_CODES.M)
                          public void onClick(View v) {
                              requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
                          }
                      });
          } else {
              requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
          }
          return false;
      }
  
      private boolean myRequestLocation(){
          if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.M) {
              return true;
          }
          if (checkSelfPermission(ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
              return true;
          }
          if (shouldShowRequestPermissionRationale(ACCESS_FINE_LOCATION)) {
              Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE)
                      .setAction(android.R.string.ok, new View.OnClickListener() {
                          @Override
                          @TargetApi(Build.VERSION_CODES.M)
                          public void onClick(View v) {
                              requestPermissions(new String[]{ACCESS_FINE_LOCATION}, REQUEST_ACCESS_FINE_LOCATION);
                          }
                      });
          }else {
              requestPermissions(new String[]{ACCESS_FINE_LOCATION}, REQUEST_ACCESS_FINE_LOCATION);
          }
  
  
          return false;
      }
      private boolean myRequestStorage(){
          if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.M) {
              return true;
          }
          if (checkSelfPermission(READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
              return true;
          }
          if (shouldShowRequestPermissionRationale(READ_EXTERNAL_STORAGE)) {
              Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE)
                      .setAction(android.R.string.ok, new View.OnClickListener() {
                          @Override
                          @TargetApi(Build.VERSION_CODES.M)
                          public void onClick(View v) {
                              requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, REQUEST_READ_EXTERNAL_STORAGE);
                          }
                      });
          } else {
              requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, REQUEST_READ_EXTERNAL_STORAGE);
          }
  
  
          return false;
      }
  
      /**
       * Callback received when a permissions request has been completed.
       */
      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                             @NonNull int[] grantResults) {
          if (requestCode == REQUEST_READ_CONTACTS) {
              if (grantResults.length == 1 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                  populateAutoComplete();
              }
          }
          if (requestCode == REQUEST_ACCESS_FINE_LOCATION) {
              if (grantResults.length == 1 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                  populateAutoComplete();
              }
          }
          if (requestCode == REQUEST_READ_EXTERNAL_STORAGE) {
              if (grantResults.length == 1 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                  populateAutoComplete();
              }
          }
      }
  
  
  
      /**
       * Attempts to sign in or register the account specified by the login form.
       * If there are form errors (invalid email, missing fields, etc.), the
       * errors are presented and no actual login attempt is made.
       */
      private void attemptLogin() {
          if (mAuthTask != null) {
              return;
          }
  
          // Reset errors.
          mEmailView.setError(null);
          mPasswordView.setError(null);
  
          // Store values at the time of the login attempt.
          String email = mEmailView.getText().toString();
          String password = mPasswordView.getText().toString();
  
          boolean cancel = false;
          View focusView = null;
  
          // Check for a valid password, if the user entered one.
          if (!TextUtils.isEmpty(password) &amp;&amp; !isPasswordValid(password)) {
  
  
              mPasswordView.setError(getString(R.string.error_invalid_password));
              focusView = mPasswordView;
              cancel = true;
          }
  
          // Check for a valid email address.
          if (TextUtils.isEmpty(email)) {
              mEmailView.setError(getString(R.string.error_field_required));
              focusView = mEmailView;
              cancel = true;
          } else if (!isEmailValid(email)) {
              mEmailView.setError(getString(R.string.error_invalid_email));
              focusView = mEmailView;
              cancel = true;
          }
  
          if (cancel) {
              // There was an error; don't attempt login and focus the first
              // form field with an error.
              focusView.requestFocus();
          } else {
  
              showProgress(true);
              mAuthTask = new UserLoginTask(email, password);
              mAuthTask.execute((Void) null);
          }
      }
  
      private boolean isEmailValid(String email) {
          //TODO: Replace this with your own logic
          return email.contains("@");
      }
  
      private boolean isPasswordValid(String password) {
          //TODO: Replace this with your own logic
          return password.length() &gt; 4;
      }
  
      /**
       * Shows the progress UI and hides the login form.
       */
      @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
      private void showProgress(final boolean show) {
          // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
          // for very easy animations. If available, use these APIs to fade-in
          // the progress spinner.
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB_MR2) {
              int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
  
              mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
              mLoginFormView.animate().setDuration(shortAnimTime).alpha(
                      show ? 0 : 1).setListener(new AnimatorListenerAdapter() {
                  @Override
                  public void onAnimationEnd(Animator animation) {
                      mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
                  }
              });
  
              mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
              mProgressView.animate().setDuration(shortAnimTime).alpha(
                      show ? 1 : 0).setListener(new AnimatorListenerAdapter() {
                  @Override
                  public void onAnimationEnd(Animator animation) {
                      mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
                  }
              });
          } else {
              // The ViewPropertyAnimator APIs are not available, so simply show
              // and hide the relevant UI components.
              mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
              mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
          }
      }
  
      @Override
      public Loader&lt;Cursor&gt; onCreateLoader(int i, Bundle bundle) {
          return new CursorLoader(this,
                  // Retrieve data rows for the device user's 'profile' contact.
                  Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
                          ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,
  
                  // Select only email addresses.
                  ContactsContract.Contacts.Data.MIMETYPE +
                          " = ?", new String[]{ContactsContract.CommonDataKinds.Email
                  .CONTENT_ITEM_TYPE},
  
                  // Show primary email addresses first. Note that there won't be
                  // a primary email address if the user hasn't specified one.
                  ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
      }
  
      @Override
      public void onLoadFinished(Loader&lt;Cursor&gt; cursorLoader, Cursor cursor) {
          List&lt;String&gt; emails = new ArrayList&lt;&gt;();
          cursor.moveToFirst();
          while (!cursor.isAfterLast()) {
              emails.add(cursor.getString(ProfileQuery.ADDRESS));
              cursor.moveToNext();
          }
  
          addEmailsToAutoComplete(emails);
      }
  
      @Override
      public void onLoaderReset(Loader&lt;Cursor&gt; cursorLoader) {
  
      }
  
      private void addEmailsToAutoComplete(List&lt;String&gt; emailAddressCollection) {
          //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list.
          ArrayAdapter&lt;String&gt; adapter =
                  new ArrayAdapter&lt;&gt;(LoginActivity.this,
                          android.R.layout.simple_dropdown_item_1line, emailAddressCollection);
  
          mEmailView.setAdapter(adapter);
      }
  
  
      private interface ProfileQuery {
          String[] PROJECTION = {
                  ContactsContract.CommonDataKinds.Email.ADDRESS,
                  ContactsContract.CommonDataKinds.Email.IS_PRIMARY,
          };
  
          int ADDRESS = 0;
          int IS_PRIMARY = 1;
      }
      public boolean isOnline(Context c) {
          connectivityManager= (ConnectivityManager) c
                  .getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo ni = connectivityManager.getActiveNetworkInfo();
  
          if (ni != null &amp;&amp; ni.isConnected())
              return true;
          else
              return false;
      }
  
  
      /**
       * Represents an asynchronous login/registration task used to authenticate
       * the user.
       */
      public class UserLoginTask extends AsyncTask&lt;Void, Void, JSONArray&gt; {
  
          private final String mEmail ;
          private final String mPassword ;
  
  
          UserLoginTask(String email, String password) {
              mEmail = email;
              mPassword = password;
          }
         // String serverURL = "http://http://111.93.107.10/8080/AndroidRest/login/dologin?username='"+mEmail+"'&amp;password='"+mPassword+"'";
          @Override
  
          protected  JSONArray doInBackground(Void... params) {
              email = mEmail;
  
  
              HttpURLConnection conn = null;
              StringBuilder response = new StringBuilder();
              try {
                  URL url = new URL("http://111.93.107.10:6080/AndroidRest/login/dologin?email='"+mEmail+"'&amp;password='"+mPassword+"'");
                  conn = (HttpURLConnection) url.openConnection();
                  conn.setRequestMethod("GET");
                  conn.setInstanceFollowRedirects(false);
  
                  conn.connect();
                  int status = conn.getResponseCode();
                  switch (status) {
                      case 200:
                          BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                          StringBuilder sb = new StringBuilder();
                          String line;
                          while ((line = br.readLine()) != null) {
                              sb.append(line+"\n");
  
  
                          }
                          br.close();
                          jsonArray  = new JSONArray(sb.toString());
                          System.out.println("upcoming responce message getting values="+sb);
                          return jsonArray;
  
                  }
  
              } catch (IOException e) {
  
                  e.printStackTrace();
              } catch (JSONException e) {
  
              }
              return jsonArray;
          }
  
          @Override
          protected void onPostExecute(final JSONArray success) {
              mAuthTask = null;
              showProgress(false);
              String msg = null;
              String username = null;
              if(jsonArray!= null) {
                  try {
                      System.out.println("upcoming responce message after Regisration =" + jsonArray.getJSONObject(0).getString("msg"));
                      msg = jsonArray.getJSONObject(0).getString("msg");
                      username= jsonArray.getJSONObject(0).getString("username");
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
                  if(msg.indexOf("invaid_email") != -1){
                      mEmailView.setError("Invalid Email");
  
  
                  }
                  if(msg.indexOf("invalid_password") != -1){
                      mPasswordView.setError("Invalid Password");
  
  
                  }
                  if(msg.equals("OK")){
                      System.out.println("no error go a head");
                      sessionManager.createLoginSession(username,email);
                      Intent intent  = new Intent(LoginActivity.this, TabActivity1.class);
                      startActivity(intent);
  
                  }
              }
  
          }
  
          @Override
          protected void onCancelled() {
              mAuthTask = null;
              showProgress(false);
          }
  
  
  
      }
  } 
  </code></pre>
  
  <p>What is the correct way to avoid this crash.Same code working on android 6.0 .</p>