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.
Related
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.
I created an example project here:
https://github.com/amitishai/Android-notifications
Here is the scenario:
Open app
Press button
Exit app
Click on the notification that was created. When the app opens you will be in Activity "Bla".
Press the OS BACK button.
Long press the OS Home button in order to see the open apps.
Click on the app.
You will see that you have entered Activity "Bla" again, and the text is the same.
If the activity was initially created with the intent, and then destroyed, how is the intent not null when restarting the activity?
The solution was to use Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
Example is here:
Android: Starting app from 'recent applications' starts it with the last set of extras used in an intent
I developed a dial up application and I installed it to my phone. Now I want to "on click a button" in my app to set the built in dialer as the default dialing application "automatically" without giving the user to choose between my app and the default dialer application.
This code gives the user the choice,
startActivityForResult(new Intent("android.intent.action.DIAL",
Uri.parse("tel:" + someNumber)), 1);
I don't want this, I want to set the default application to be built in dialer without asking the user.
Note: Once the user is not using my app he will be given the choice, Howevre, if he clicked that button in my app .. it will set the default app automatically.
Try this. This should open default dialer .
Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:0000000000"));
startActivity(i);
You can't force the default activity without user interaction. Why don't you just call your class directly on the button press?
Intent intent = new Intent(this, mydialer.class))
intent.putExtra("PHONENUMBER", _phoneNumber);
startActivityForResult(intent);
I use an Navigation intent in my app like:
uri= String.format(Locale.ENGLISH,"http://maps.google.com/maps?daddr=%f,%f",latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
EventMapOfflineActivity.this.startActivity(intent);
Works perfectly, the user can select the app (s)he wants to start.
But, after the selection the dialog won't close itself and after returning to the app sometimes the user has to press the back button up to 4x to close that dialog.
So is there any way to get the Android OS to close that dialog?
Or do we have to respect that Android way of doing it?
I would do that in the onStop() Handler of my app which is called when the user selected an app to start in the dialog (with a flag set to true on the click to go to navi and resettet to false in the onStop() )
I just think that the Android OS would not like messing with its dialogs, or is there a CLEAN way to do this?
Thanks in advance
But, after the selection the dialog won't close itself and after returning to the app sometimes the user has to press the back button up to 4x to close that dialog.
This is most likely a problem with your firmware, either due to bugs from the device manufacturer or bugs in some modded firmware that you have installed upon your device.
So is there any way to get the Android OS to close that dialog?
Android automatically closes the dialog.
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.