Set Authentication while DeviceAdmin mode get disable? - java

I am create an parental control app, where i want to put the Simple password authentication before disable to administrator mode by used . I am using DeviceAdminReceiver . An Idea or sample code which help . Thankyou

Unfortunately there is no direct approach to achieve it. However there is a workaround which can be done by overriding onDisableRequested() method of DeviceAdminReceiver
public class AdminReceiver extends DeviceAdminReceiver {
#Override
public CharSequence onDisableRequested(Context context, Intent intent) {
DevicePolicyManager mDPM =(DevicePolicyManager)getApplicationContext().getSystemService("device_policy");
mDPM.lockNow();
// You can also display overlay screen
return "Are you sure you want to disable the Device admin?";//OR whatever message you would like to display
}
}
As per documentation
Called when the user has asked to disable the administrator, as a result of receiving ACTION_DEVICE_ADMIN_DISABLE_REQUESTED, giving you a chance to present a warning message to them. The message is returned as the result; if null is returned (the default implementation), no message will be displayed.
Note:
If you are trying to display overlay screen, do note that disable popup will and deactivate screen will have high visibility precedence. Any attempts to do so won't help much. One work around is to lock screen first and then display overlay screen.

Related

How can I show a confirm dialog with Vaadin 23 when the user clicks on back button?

how can I show a dialog to stay or leave the current page with Vaadin 23, when a user clicks back button on browser?
Regards
It depends what you wish to achieve.
See this older discussion: Vaadin onbeforeunload event
Generally: use the onBeforeUnload javascript even for this
https://www.w3schools.com/tags/ev_onbeforeunload.asp
This is executed when the user would go away from your vaadin app, but not when using the back button inside your vaadin app.
For these you can use the navigation lifecycle events as documented here
https://vaadin.com/docs/latest/routing/lifecycle
Not sure if it also catches, when a user leaves your app...
Assuming you mean, that is it possible to prevent the navigation happening, you simply can't do that. If disabling back button is important for you, the only way is to enforce your users to use the application via desktop shortcut which starts the app using --app paramater (if using Chrome). This is not a limitation in Vaadin, but a general restriction in browser behavior.
There is already a possibility to handle Browser Back Button Event on Vaadin (https://vaadin.com/docs/v14/flow/routing/tutorial-routing-lifecycle):
public class SignupForm extends Div implements BeforeLeaveObserver {
#Override
public void beforeLeave(BeforeLeaveEvent event) {
if (this.hasChanges()) {
ContinueNavigationAction action = event.postpone();
ConfirmDialog.build("Are you sure you want"+
" to leave this page?")
.ifAccept(action::proceed)
.show();
}
}
private boolean hasChanges() {
// no-op implementation
return true;
}
}
This code works once but when you click on Cancel on Confirm Dialog so that you want to stay on current page and click again on Back Button on Browser, than you don't see any Confirm Dialog again... I can not understand, why...

How to verify icon's presence in statusBar of Android with Selenium?

I need to write code (Java, Selenium) that verifies icon's presence in Android status bar. For instance, after enabling airplane mode, a plane icon appears. But I can't figure out how to do this, what selectors should be used? Appium desktop doesn't seem to work with the status bar and 'adb shell dumpsys statusbar' also gives no useful info. I have written verifications of the elements in the notification bar, quick options, etc, but I'm stuck at finding about status bar icons. Please help.
So, I've found a way to verify it via dumpsys of systemUIservice. The code looks like this:
public static boolean validateAirplaneModeBySystemUIService(DeviceAng deviceAng) throws Exception {
String systemUIService = "activity service SystemUIService";
return deviceAng.getADB().shell().dumpsys().service(systemUIService, "mAirplaneMode=true").GetBoolean()
&& deviceAng.getADB().shell().dumpsys().service(systemUIService,
"icon=StatusBarMobileView(slot=mobile state=MobileIconState").GetString().contains("visible=false")
&& deviceAng.getADB().shell().dumpsys().service(systemUIService,
"icon=StatusBarIconView(slot=airplane icon=StatusBarIcon").GetString().contains("visible user=0");
}

How do I overwrite back button of BSImagePicker gallery?

I'm new new in Java and working on an old project that uses bsImagePicker. There's a bug in my current project that when the user wants to click the below back button of the gallery it takes the user to home page.
This shouldn't be the default behavior, rather it should take the user 1 step back. Please, How do I overwrite the method of this back button? Unfortunately, I couldn't find any xml file that has referenced this button neither there's any previous overwritten method.
Thanks in advance.
Edit: I searched more and figured out maybe it has to do something with getSupportActionBar().setDisplayHomeAsUpEnabled() but I don't know how to set its android:parentActivityName attribute.
To override onBackPressed() method and implement your own functionality or behavior.
#Override
public void onBackPressed() {
//implement your own functionality in this
}
But since you are trying to implement it for back button shown in attached image and you don't have reference of it. Either you can create a reference by own or you can try on onCancelled method as provided in BSImagePicker gallary github repo.
//Optional
#Override
public void onCancelled(boolean isMultiSelecting, String tag) {
//Do whatever you want when user cancelled
}

Android Application for Kids

I'm Developing Android Application for Parental Controlling, so I want to disable home and back button. Because kids are unpredictable, their can push home button or back button and so on. Than i want to disable sliding notification bar. (Because notification bar can change device configuration and setting)
I'm planning to create Android Application which is similar to the Samsung Kids Mode-Parental Control.
Is possible to create application like Samsung Kids Mode? Can you give some link/article or even example program to me?
I Have tried this :
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
but it not handle home button, the Home button still working.
Thanks in advance to everyone for taking time to read this, hoping a positive solution.
I dont know of anyway to override the home button. Im not sure that it can be done. You can override the back button like so.
#Override
public void onBackPressed() {
//do nothing, important dont call super.onBackPressed
}
Another this you can do is set the app to immersive mode to reduce the chance of accidently exiting the app
https://developer.android.com/training/system-ui/immersive.html
Extended from Activity
#Override
public void onBackPressed() {
}
can be used to override back button. Be sure to remove super.onBackPressed().

I want to run the application in background of mobile without any GUI in mobile using J2ME?

I am developing the network application in which I want to run my J2ME MIDP application in background without any GUI so that is any way to construct the application is such manner.
try this
set your current Display to null. so there will not be any form or alert running on the screen. But however your code will be running in the background.
Display display = Display.getDisplay(this); // here 'this' points to Midlet
display.setCurrent(null);
it easy just have a code of line on any event for example in the click of button
Display.getDisplay (this).setCurrent (null);
and return back the control via
Display.getDisplay (this).setCurrent (mycanvas);
Yes this code works Good,
display = Display.getDisplay(this);
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void hide()
{
Display.getDisplay (this).setCurrent (null);
}
This is will work like, make a button can after clicking it call hide Function, or you call this hide function in constructor so it will hide itself when app start, can you keep unHide statement in appStart() so if you Tab the program then it will unHide app again.
NOTE: you said you are working on Network app, but some mobile will turn off the Internet Connection, when the Mobile screen Turn Off. please check this. and If you found any solution It will be Good to share here.

Categories