login button not working after permission to acces files granted in android app
This problem only exist during the first run of app after installation , that the login button not working after permission to access files granted ,in the next app run the login button works perfectly. can any one please tell me what is the issue associated with this.
Providing code for login activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if(Build.VERSION.SDK_INT>=24)
try
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
catch(Exception e)
e.printStackTrace();
int hasWriteContactsPermissionW = ContextCompat.checkSelfPermission(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if (!ActivityCompat.shouldShowRequestPermissionRationale(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
showMessageOKCancel("You need to allow access to Files", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
ActivityCompat.requestPermissions(login.this, new String Manifest.permission.WRITE_EXTERNAL_STORAGE, REQUEST_CODE_ASK_PERMISSIONS);
);
return;
ActivityCompat.requestPermissions(login.this,
new String Manifest.permission.WRITE_EXTERNAL_STORAGE,
REQUEST_CODE_ASK_PERMISSIONS);
return;
loginbtn = findViewById(R.id.loginbtn);
loginbtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Log.d("MMMMMM", "CLICKEDDD");
loginbtn.setVisibility(View.GONE);
EditText emailtxt = findViewById(R.id.emailtxt);
String email = emailtxt.getText().toString();
EditText passtxt = findViewById(R.id.passwordtxt);
String pass = passtxt.getText().toString();
GlobalVar.hash = String.valueOf(hashing.md5encrypt(email + pass));
Connect();
);
add a comment |
This problem only exist during the first run of app after installation , that the login button not working after permission to access files granted ,in the next app run the login button works perfectly. can any one please tell me what is the issue associated with this.
Providing code for login activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if(Build.VERSION.SDK_INT>=24)
try
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
catch(Exception e)
e.printStackTrace();
int hasWriteContactsPermissionW = ContextCompat.checkSelfPermission(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if (!ActivityCompat.shouldShowRequestPermissionRationale(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
showMessageOKCancel("You need to allow access to Files", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
ActivityCompat.requestPermissions(login.this, new String Manifest.permission.WRITE_EXTERNAL_STORAGE, REQUEST_CODE_ASK_PERMISSIONS);
);
return;
ActivityCompat.requestPermissions(login.this,
new String Manifest.permission.WRITE_EXTERNAL_STORAGE,
REQUEST_CODE_ASK_PERMISSIONS);
return;
loginbtn = findViewById(R.id.loginbtn);
loginbtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Log.d("MMMMMM", "CLICKEDDD");
loginbtn.setVisibility(View.GONE);
EditText emailtxt = findViewById(R.id.emailtxt);
String email = emailtxt.getText().toString();
EditText passtxt = findViewById(R.id.passwordtxt);
String pass = passtxt.getText().toString();
GlobalVar.hash = String.valueOf(hashing.md5encrypt(email + pass));
Connect();
);
add a comment |
This problem only exist during the first run of app after installation , that the login button not working after permission to access files granted ,in the next app run the login button works perfectly. can any one please tell me what is the issue associated with this.
Providing code for login activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if(Build.VERSION.SDK_INT>=24)
try
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
catch(Exception e)
e.printStackTrace();
int hasWriteContactsPermissionW = ContextCompat.checkSelfPermission(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if (!ActivityCompat.shouldShowRequestPermissionRationale(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
showMessageOKCancel("You need to allow access to Files", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
ActivityCompat.requestPermissions(login.this, new String Manifest.permission.WRITE_EXTERNAL_STORAGE, REQUEST_CODE_ASK_PERMISSIONS);
);
return;
ActivityCompat.requestPermissions(login.this,
new String Manifest.permission.WRITE_EXTERNAL_STORAGE,
REQUEST_CODE_ASK_PERMISSIONS);
return;
loginbtn = findViewById(R.id.loginbtn);
loginbtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Log.d("MMMMMM", "CLICKEDDD");
loginbtn.setVisibility(View.GONE);
EditText emailtxt = findViewById(R.id.emailtxt);
String email = emailtxt.getText().toString();
EditText passtxt = findViewById(R.id.passwordtxt);
String pass = passtxt.getText().toString();
GlobalVar.hash = String.valueOf(hashing.md5encrypt(email + pass));
Connect();
);
This problem only exist during the first run of app after installation , that the login button not working after permission to access files granted ,in the next app run the login button works perfectly. can any one please tell me what is the issue associated with this.
Providing code for login activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if(Build.VERSION.SDK_INT>=24)
try
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
catch(Exception e)
e.printStackTrace();
int hasWriteContactsPermissionW = ContextCompat.checkSelfPermission(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if (!ActivityCompat.shouldShowRequestPermissionRationale(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
showMessageOKCancel("You need to allow access to Files", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
ActivityCompat.requestPermissions(login.this, new String Manifest.permission.WRITE_EXTERNAL_STORAGE, REQUEST_CODE_ASK_PERMISSIONS);
);
return;
ActivityCompat.requestPermissions(login.this,
new String Manifest.permission.WRITE_EXTERNAL_STORAGE,
REQUEST_CODE_ASK_PERMISSIONS);
return;
loginbtn = findViewById(R.id.loginbtn);
loginbtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Log.d("MMMMMM", "CLICKEDDD");
loginbtn.setVisibility(View.GONE);
EditText emailtxt = findViewById(R.id.emailtxt);
String email = emailtxt.getText().toString();
EditText passtxt = findViewById(R.id.passwordtxt);
String pass = passtxt.getText().toString();
GlobalVar.hash = String.valueOf(hashing.md5encrypt(email + pass));
Connect();
);
edited Nov 13 '18 at 5:50
Kripa_K
asked Nov 13 '18 at 3:45
Kripa_KKripa_K
2029
2029
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your code does not run at first. It is because the permission checker stops execution when permission is granted on first run. I've copied your code snippet and commented the line
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if(.....)
// .... your code
return; // this statement terminates (stops ?) the function
// solution is to remove this line
// these lines are never reached because of the return; above
loginbtn = findViewById(R.id.loginbtn);
Solution :
- Check permissions at the end of
onCreate - Remove
return;from block where you check permissions
Modified Code :
@Override protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if (Build.VERSION.SDK_INT >= 24)
try
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
catch (Exception e)
e.printStackTrace();
// moved this above
loginbtn = findViewById(R.id.loginbtn);
loginbtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Log.d("MMMMMM", "CLICKEDDD");
loginbtn.setVisibility(View.GONE);
EditText emailtxt = findViewById(R.id.emailtxt);
String email = emailtxt.getText().toString();
EditText passtxt = findViewById(R.id.passwordtxt);
String pass = passtxt.getText().toString();
GlobalVar.hash = String.valueOf(hashing.md5encrypt(email + pass));
Connect();
);
// moved this below
int hasWriteContactsPermissionW = ContextCompat.checkSelfPermission(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if (!ActivityCompat.shouldShowRequestPermissionRationale(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
showMessageOKCancel("You need to allow access to Files", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
ActivityCompat.requestPermissions(login.this, new String
Manifest.permission.WRITE_EXTERNAL_STORAGE
, REQUEST_CODE_ASK_PERMISSIONS);
);
return;
ActivityCompat.requestPermissions(login.this,
new String
Manifest.permission.WRITE_EXTERNAL_STORAGE
,
REQUEST_CODE_ASK_PERMISSIONS);
return;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273485%2flogin-button-not-working-after-permission-to-acces-files-granted-in-android-app%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your code does not run at first. It is because the permission checker stops execution when permission is granted on first run. I've copied your code snippet and commented the line
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if(.....)
// .... your code
return; // this statement terminates (stops ?) the function
// solution is to remove this line
// these lines are never reached because of the return; above
loginbtn = findViewById(R.id.loginbtn);
Solution :
- Check permissions at the end of
onCreate - Remove
return;from block where you check permissions
Modified Code :
@Override protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if (Build.VERSION.SDK_INT >= 24)
try
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
catch (Exception e)
e.printStackTrace();
// moved this above
loginbtn = findViewById(R.id.loginbtn);
loginbtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Log.d("MMMMMM", "CLICKEDDD");
loginbtn.setVisibility(View.GONE);
EditText emailtxt = findViewById(R.id.emailtxt);
String email = emailtxt.getText().toString();
EditText passtxt = findViewById(R.id.passwordtxt);
String pass = passtxt.getText().toString();
GlobalVar.hash = String.valueOf(hashing.md5encrypt(email + pass));
Connect();
);
// moved this below
int hasWriteContactsPermissionW = ContextCompat.checkSelfPermission(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if (!ActivityCompat.shouldShowRequestPermissionRationale(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
showMessageOKCancel("You need to allow access to Files", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
ActivityCompat.requestPermissions(login.this, new String
Manifest.permission.WRITE_EXTERNAL_STORAGE
, REQUEST_CODE_ASK_PERMISSIONS);
);
return;
ActivityCompat.requestPermissions(login.this,
new String
Manifest.permission.WRITE_EXTERNAL_STORAGE
,
REQUEST_CODE_ASK_PERMISSIONS);
return;
add a comment |
Your code does not run at first. It is because the permission checker stops execution when permission is granted on first run. I've copied your code snippet and commented the line
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if(.....)
// .... your code
return; // this statement terminates (stops ?) the function
// solution is to remove this line
// these lines are never reached because of the return; above
loginbtn = findViewById(R.id.loginbtn);
Solution :
- Check permissions at the end of
onCreate - Remove
return;from block where you check permissions
Modified Code :
@Override protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if (Build.VERSION.SDK_INT >= 24)
try
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
catch (Exception e)
e.printStackTrace();
// moved this above
loginbtn = findViewById(R.id.loginbtn);
loginbtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Log.d("MMMMMM", "CLICKEDDD");
loginbtn.setVisibility(View.GONE);
EditText emailtxt = findViewById(R.id.emailtxt);
String email = emailtxt.getText().toString();
EditText passtxt = findViewById(R.id.passwordtxt);
String pass = passtxt.getText().toString();
GlobalVar.hash = String.valueOf(hashing.md5encrypt(email + pass));
Connect();
);
// moved this below
int hasWriteContactsPermissionW = ContextCompat.checkSelfPermission(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if (!ActivityCompat.shouldShowRequestPermissionRationale(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
showMessageOKCancel("You need to allow access to Files", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
ActivityCompat.requestPermissions(login.this, new String
Manifest.permission.WRITE_EXTERNAL_STORAGE
, REQUEST_CODE_ASK_PERMISSIONS);
);
return;
ActivityCompat.requestPermissions(login.this,
new String
Manifest.permission.WRITE_EXTERNAL_STORAGE
,
REQUEST_CODE_ASK_PERMISSIONS);
return;
add a comment |
Your code does not run at first. It is because the permission checker stops execution when permission is granted on first run. I've copied your code snippet and commented the line
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if(.....)
// .... your code
return; // this statement terminates (stops ?) the function
// solution is to remove this line
// these lines are never reached because of the return; above
loginbtn = findViewById(R.id.loginbtn);
Solution :
- Check permissions at the end of
onCreate - Remove
return;from block where you check permissions
Modified Code :
@Override protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if (Build.VERSION.SDK_INT >= 24)
try
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
catch (Exception e)
e.printStackTrace();
// moved this above
loginbtn = findViewById(R.id.loginbtn);
loginbtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Log.d("MMMMMM", "CLICKEDDD");
loginbtn.setVisibility(View.GONE);
EditText emailtxt = findViewById(R.id.emailtxt);
String email = emailtxt.getText().toString();
EditText passtxt = findViewById(R.id.passwordtxt);
String pass = passtxt.getText().toString();
GlobalVar.hash = String.valueOf(hashing.md5encrypt(email + pass));
Connect();
);
// moved this below
int hasWriteContactsPermissionW = ContextCompat.checkSelfPermission(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if (!ActivityCompat.shouldShowRequestPermissionRationale(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
showMessageOKCancel("You need to allow access to Files", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
ActivityCompat.requestPermissions(login.this, new String
Manifest.permission.WRITE_EXTERNAL_STORAGE
, REQUEST_CODE_ASK_PERMISSIONS);
);
return;
ActivityCompat.requestPermissions(login.this,
new String
Manifest.permission.WRITE_EXTERNAL_STORAGE
,
REQUEST_CODE_ASK_PERMISSIONS);
return;
Your code does not run at first. It is because the permission checker stops execution when permission is granted on first run. I've copied your code snippet and commented the line
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if(.....)
// .... your code
return; // this statement terminates (stops ?) the function
// solution is to remove this line
// these lines are never reached because of the return; above
loginbtn = findViewById(R.id.loginbtn);
Solution :
- Check permissions at the end of
onCreate - Remove
return;from block where you check permissions
Modified Code :
@Override protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if (Build.VERSION.SDK_INT >= 24)
try
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
catch (Exception e)
e.printStackTrace();
// moved this above
loginbtn = findViewById(R.id.loginbtn);
loginbtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Log.d("MMMMMM", "CLICKEDDD");
loginbtn.setVisibility(View.GONE);
EditText emailtxt = findViewById(R.id.emailtxt);
String email = emailtxt.getText().toString();
EditText passtxt = findViewById(R.id.passwordtxt);
String pass = passtxt.getText().toString();
GlobalVar.hash = String.valueOf(hashing.md5encrypt(email + pass));
Connect();
);
// moved this below
int hasWriteContactsPermissionW = ContextCompat.checkSelfPermission(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWriteContactsPermissionW != PackageManager.PERMISSION_GRANTED)
if (!ActivityCompat.shouldShowRequestPermissionRationale(login.this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
showMessageOKCancel("You need to allow access to Files", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
ActivityCompat.requestPermissions(login.this, new String
Manifest.permission.WRITE_EXTERNAL_STORAGE
, REQUEST_CODE_ASK_PERMISSIONS);
);
return;
ActivityCompat.requestPermissions(login.this,
new String
Manifest.permission.WRITE_EXTERNAL_STORAGE
,
REQUEST_CODE_ASK_PERMISSIONS);
return;
answered Nov 13 '18 at 4:13
Naveen NiraulaNaveen Niraula
357214
357214
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273485%2flogin-button-not-working-after-permission-to-acces-files-granted-in-android-app%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown