android widget prompt for unlock - android

I've a problem developing an application, I'm building a Widget that can be either on lockscreen or in home page. when is in lockscreen I want that when the user clicks a button the widget prompt for the user login in case of needed. I mean prompt for patter or password or face recognition depending if the user have any of this security enabled.
after the user enter his pattern the widget will run an application (intent).
I've notice that some widgets does prompt for login and other doesn't I haven't found the difference between them.
I think this has to be on the onReceive method but not sure how can I call this "login" method, so far on the onReceive I start the intent
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.getApplicationContext().startActivity(i);
but this still not prompt for login. when the widget is on the lockscreen.
let say that the user interacts with the widget in the Lock screen, the user is not prompted to enter the password, either way the user does enter his pattern|password and after the user "enter" his home screen and the application is started. So the widget does start the intent just don't let the user "know" or login to see the application.
any thoughts on how can I prompt the user to enter his pattern so it enter to the home screen?
[Edit]
The problem occurs when I try to fire the intent within a BroadcastReceiver.
What I do is allow the user interact with the widgetd buttons, depending on what the user has selected I'll open my application adding some extras to the intent.
so on the onReceive method of my BroadcastReceiver I try to fire:
Intent i = new Intent(context, MyActivity.class);
i.putExtra(WidgetUtils.TAG_CURRENT_SELECTION, StringIGotFromInteraction);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(i);
this way the intent don't prompt for the "unblock".
If in the onUpdate I cast the pending intent to any button when the user clicks that button does prompt for the unlock this way:
views.setOnClickPendingIntent(R.id.aButton, buildAPendingIntent(context));
but I need to know what has the user selected to open and Intent in case I open any.
and my contex.startActivity Approach works fine when the widget is on home screen just not on loockscreen.
Any thoughts how can I make this happen.

I couldn't find the answer what I end up doing was create a dynamic button and when the widget is updated (by the other buttons) I assign the PendingIntent to this button.
So when user clicks this dynamic button the widget attempt to open the intent and is there when the user is prompted for the password.
I think this is not the best solution seance we make the user make an extra click on the widget.

Related

clearing all open previous activities not working in android 5.0

My app has a log in MainActivity. By tapping on a link a SecondActivity starts and the user can sign up. After the user completes the form an email is sent with a deep link to activate the account. When the user taps that link the MainActivity starts again indicating that the account was activated and that the user can log in. The problem is that in android 4.3 the previous activities get clear, but not in Android 5:
This is part of the code I'm using when the user taps the deep link:
Intent toLaunchMainActivityAgain = new Intent(this, MainActivity.class);
toLaunchMainActivityAgain.addFlags(toLaunchMainActivityAgain.FLAG_ACTIVITY_CLEAR_TOP);
toLaunchMainActivityAgain.setFlags(toLaunchMainActivityAgain.FLAG_ACTIVITY_MULTIPLE_TASK);
toLaunchMainActivityAgain.setFlags(toLaunchMainActivityAgain.FLAG_ACTIVITY_NEW_TASK);
When you are trying to launch another activity, call below to make sure Android Task Manager doesn't store the activity you are leaving
startActivity(new Intent(MainActivity.this, OtherActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK));
When I want to then go back to another activity from my current one, I simply call
finish();

Open application in last state it was in

when the user clicks on the icon in the app drawer to start my application, my app opens in the state it was last in.
I have a broadcast receiver, and when I receive a certain intent I want to have the same effect.
At the moment I use
Intent launchIntent = mContext.getPackageManager().getLaunchIntentForPackage("xx.xx.xx"); //My package name
context.startActivity(launchIntent);
But this always opens the mainactivity of my application.
How can I fix this? thx

Android Services, Activities and Handlers?

Im developping an Android Service in Android that needs to pop-up a new dialog box for confirmation.
I can popup a new activity using Intent and Context
Intent myIntent = new Intent(context, ConfirmationActivity.class);
But then I need to handle the option selected in the dialog box (OK or Cancel).
Any suggestion?
Note: Not developing for smartphones.
Update: I need to return the result to the place I call the Dialog.
A service should not pop up anything at all. Imagine the user is in the middle of a phone call when your dialog pops up.
If you need a confirmation from the user the best thing you can do is to use the NotificationManager and use a PendingIntent to launch an Activity. The Activity can still have a dialog style if you like.
Control flows back from the Activity to your Service then, so when the user presses ok or cancel you would either call a bound interface or use SharedPreferences to tell the service about the user's choice.

How do I undo clearPackagePreferredActivities("com.android.launcher");

What I am trying to do is replicate what the ToddlerLock app does. I have managed to clear the default launcher with
PackageManager localPackageManager = getPackageManager();
localPackageManager.clearPackagePreferredActivities("com.android.launcher");
and then open the launch select dialog with this
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
As long as the user checks the "use by default for this action" the home key now sends the user to my app, thus essentially disabling it.
I then use "clearPackagePreferredActivities("com.my_application")" when I exit my app and the user has to choose a new default home app.
My question is how can I choose the default home application (essentially checking the "use by default for this action" check box in code for the "com.android.launcher" package. That way the user does not constantly have to see that dialog box every time they open and close my app.
I think ToddlerLock does this somehow without using clearPackagePreferredActivities
because if I look at the "clear defaults" in the application manager it is not cleared and you only have to go through the set as default dialog box one time on startup and once when you exit to set it back to the normal home screen.
Thanks for your help.
I have implemented the same functionality in different way.
Let's say you have 'LockScreenAcitivity' configured as Home Screen in Manifest.
Launch LockScreenActivity by sending Home Intent.
Android will popup a dialog, to select the default Acitivity
choose your LockScreenActivity from List as default Activity
.....
.....
While closing the Activity don't clear the prefered Activities.
Disable your LockScreenActivity alone by calling PackageManager.setComponentEnabledSetting()
After you disable your LockScreenActivity, android will rollback to previous Prefered Activity (that's your old home screen ).
Next time when you launch your app,
enable your lockscreenActivity again by calling PackageManager.setComponentEnabledSetting()
Launch LockScreenActivity by sending Home Intent.

Open an already opened Activity in android

I am developing an application and its Home Screen Widget.
Now from my widget when i press on a button it would open up my application from where it was left.
Means if i press home button during my application running then my application will go in background mode.
Now i want that it should resume my opened application.
Whenever i press a button from my Widget. How Can i Do it??
Please help
Thanks a bunch in advance!
I've never made a widget before, but this is how I've made a notification launch back into my original activity when you pull down the bar and click it.
Intent originalActivity = new Intent(getApplicationContext(), Widget.class);
originalActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Once again, not sure how you would do this with a widget, but to relaunch it for a notification you convert that Intent into a PendingIntent to be called later when you want to launch back into it. I would assume this is a similar fashion for how you would it on a widget.

Categories

Resources