Is there a "Wrong password on lock screen" action intent? - android

I'm looking for a way to get a notification if a user enters a wrong password on the Android lock screen (the system lock screen - not a lock screen in my own app). Is there an existing intent that get's fired in that situation?
Many thanks in advace.

I'm looking for a way to get a notification if a user enters a wrong password on the Android lock screen (the system lock screen - not a lock screen in my own app). Is there an existing intent that get's fired in that situation?
If you have implemented a DeviceAdminReceiver using the device admin APIs, it will be called with onPasswordFailed().

You can create your own dialog in android app to display the error message.Below is the code for that:
AlertDialog alertDialog = new AlertDialog.Builder(LoginActivity.this).create();
// Setting Dialog Title
alertDialog.setTitle("Error");
// Setting Dialog Message
alertDialog.setMessage("Not A User");
// Setting Icon to Dialog
alertDialog.setIcon(R.drawable.inputerror);
// Setting OK Button
alertDialog.setButton("OK",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
// Write your code here to execute after dialog
// closed
Toast.makeText(getApplicationContext(),"Not A Valid User", Toast.LENGTH_SHORT).show();
}
});
// Showing Alert Message
alertDialog.show();
return;

Related

Displaying Toast after opening a Settings Activity

I'm trying to display a Toast right after I open a Settings Activity, which should contain a few instructions on what to do in the opening screen.
For example, let's say I want the user to connect to a specific network, so in my code I run
Toast.makeText(context, "Instruction message", Toast.LENGTH_SHORT).show()
startActivity(Intent(Settings.ACTION_WIFI_SETTINGS))
to display a Toast followed by a call to open up the WiFi Settings Activity. The problem here is that the Toast will display in the current Activity inside my app, but very quickly disappear as soon as the new Activity comes up.
I'm wondering if there's a way of displaying that same Toast but on the opening Activity, rather than the one that is doing the call, in order to properly instruct the user on what to do on such new Activity.
Or perhaps there's a better way of achieving this?
I think it would be better if you used a dialog, so after clicking OK, the user will be shown the screen to change WiFi, like so:
AlertDialog.Builder(context)
.setTitle("Your app name")
.setMessage("Please turn on WiFi on the following screen.")
.setPositiveButton("OK", DialogInterface.OnClickListener { dialog, id ->
{
startActivity(Settings.ACTION_WIFI_SETTINGS)
}
})
.setNegativeButton("Cancel", null)
.show();
You can read more about Dialogs here: https://developer.android.com/guide/topics/ui/dialogs

How to close an app after showing a dialog?

I have almost completed my app development and I have even allowed a way to show up a toast message if there is no internet connection. I need to know how to close an app after showing a dialog if there is no internet connection?
My app is a webview app. So when user turn on the app, the app must check for internet connection. and display a dialog box if no network and the app must close after showing dialog.
OR
I don't want users to see the "webpage not available" page, so if there is no internet connection, the app must close after showing a dialog box with one button 'close'. Or is there any way to redirect users to a text in directory which shows no internet connection?
I need those code only; all the other codes have been done and are working properly.
Just invoke finish() to destroy activity in the onClick() function of dialog. Like:
...
builder.setMessage('There is no connection!! Please close the activity!')
.setPositiveButton('close', new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
})
...
You can popup a dialog after checking the internet connectivity as follows
new AlertDialog.Builder(this)
.setTitle("Connection Error")
.setMessage("You are not connected to Internet.")
.setPositiveButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// finish the activity here or,
// redirect to another activity
}
})
.show();
You can check your internet connectivity before setting the view to the activity.
Like :
if(connnected){
setContentView(layoutId);
}else{
show a tosat with information no internet;
finish activity.
}
call finish() method on your activity once user clicks on dialogue

showing blank screen on back button android

How can I avoid showing blank screen after user click Back button of device in the authentication step?
[ Edited]
The flow is user is asked to authenticate via twitter.
If the user reaches the step, it is possible that user doesn't authenticate and press the back button of device and return to the app. At that step, the app show blank page.
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (MyUtils.checkIsAuthenticated(prefs)) {
//sending the tweet
} else {
Intent i = new Intent(context,
GotoRequestTokenActivity.class);
context.startActivity(i);
}
}
});
Try overriding the onBackPressed() method ,you can do something there to disable the back button pr finishing your activity or display a relevant toast like "cancelling the authentication"
Your qsn is, from dialog, instead of pressing button on dialog user presses back key? or is it after you move to launched activity and user presses back?
in first case, i guess you shall check if user is bypassing dialog in OnResume.
in 2nd case, make your dialog an activity with dialog theme and call finish() in onclicklistener. (ur dialog shall dismiss when you go to next activity)
In any case, check ur log and see if you leaking something.
you use this demo for twitter integration because this demo opens a dialog for login instead of open the twitter url for login...so, if you want to back from that you can easily do that..see this link...This is just like facebook dialog..
https://github.com/lorensiuswlt/AndroidTwitter

Android Eclipse, AlertDialog outside of ativity

I have an AlertDialog with an OK button in my activity by using this code:
alertDialog = new AlertDialog.Builder(getApplicationContext()).create();
//Setting Dialog Title
alertDialog.setTitle("Alert Dialog");
// Setting Dialog Message
alertDialog.setMessage("Welcome to AndroidHive.info");
// Setting Icon to Dialog
alertDialog.setIcon(R.drawable.icon);
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog closed
}
});
alertDialog.show();
This works fine within the application, but I want this to be ran and show even if we're outside of the application. Of course with the application still running and not closed. Much like Toast. even if I can use a Toast with an OK button I'd be happy.
Any help is appreciated. Thanks.
You can't run a dialog as standalone. You will have to get an Activity to display your dialog. In my mind, your solution would lead to a bad user experience if every app could launch a modal dialog whenever it wants.
But you can imagine 2 solutions :
bringing up an activity with this dialog open (maybe you could make the activity transparent) when a certain intent is sent to the system.
use notifications, it looks quite close from what you want to do.

Create notification when application is in background, Android

Initial description:
My application handles some events and do some task related to that event, even if application is in background. I am using receivers.
Problem description
I want to show notification when an event starts or end.
What I did yet
I used Notification manager :- But I need to show notification on home screen not on notification bar.
I used App widget :- But user will not able to notice any changes in information on app widget easily, because this does not do any eye catching effect.
I used Toast :- But this having time limitation to show, I want to show notification until user close.
So what should be the option? How can I do my task?
Please refer below image, as what I want
Unfortunately, you've explored all the possible options. What you want to achieve is not provided intentionally because it will make for very bad user experience. Imagine a notification (of the kind that you want) popping up when you are looking at an email!
Attention piracy
When your app is in the foreground, you can do a lot of things.
When your app is not in the foreground, there are only two options
Start an activity: You must do this only if essential (like an incoming phone call activity). If the user deems it more irritating than useful, your app is going down the drain!
Use the notification manager.
An option is to use Alert Dialogs
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MyActivity.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
Or you can use run an Activity with the Dialog theme.

Categories

Resources