Android Device Admin dialogue not showing up - Auto declined - android

I'm trying to implement locking the screen with my app.
I've worked my way through google documentation and studied the sample.
When i call this
void getAdmin(){
Intent activateDeviceAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
activateDeviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mPolicy.getPolicyAdmin());
activateDeviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
getResources().getString(R.string.AdminReceiverDescr));
startActivityForResult(activateDeviceAdminIntent, REQ_ACTIVATE_DEVICE_ADMIN);
}
The dialogue doesn't show up (maybe it flashes a little, can't say for sure), it just jumps in my onResult routine and result is "not granted". But my app afterwards shows up in the list in settings/security/device admins and if i enable admin rights manually it locks my screen like a charm.
I've added the permission
uses-permission android:name="android.permission.BIND_DEVICE_ADMIN"
as well as
receiver ... android:permission="android.permission.BIND_DEVICE_ADMIN"
to my manifest.
Does anyone have a clue what i may have missed?
Thx in advance!

Found the problem in my manifest: you have to specify the receiver subclass with a $ sign.
Example:
android:name="com.exampl.PolicyClass$PolicyReceiver"

Related

Screen Overlay Detected | (Android 6.x) Lenovo, Redmi & Samsung Devices

I have created an app which continuously run in background and show an floating overlay TextView(By using the permission android.permission.SYSTEM_ALERT_WINDOW).
I have problem in Lenovo android devices, when other applications try to request for user permission there is an alert dialog says "Screen Overlay Detected". While I have test the same application on Redmi 3S Prime device the "Allow" button in permission dialog is not clickable, until I have turned off the Floating Overlay TextView in my application.
So is there any solution to resolve this device specific issue? One of the possible solution may be disable floating TextView while permission dialog is visible to user and show floating overlay when permission dialog is closed, but the problem is how can I detect the permission dialog open/close state for other foreground application from my app.
Please suggest...
Unfortunately it seems that this is inherent to the Android OS, and as far as I know there is no way to detect when another app is requesting permissions. The general flow for interacting with other apps is to send intents to them in a push manner, so theoretically it could be done if the other apps send an intent to your app to disable the overlay, though this is not a practical solution.
I could be completely wrong, but I am yet to see a programmatic solution to this problem. The best you can probably do is warn your users that your app may cause this problem, and provide them with a quick temporary disable button.
how can I detect the permission dialog open/close state from my app??
Implement Method Mentioned Below, to run this check at the onCreate of the first Activity
public final static int PERM_REQUEST_CODE_DRAW_OVERLAYS = 1234;
/**
* Permission to draw Overlays/On Other Apps, related to
'android.permission.SYSTEM_ALERT_WINDOW'
in Manifest
Resolves issue of popup in Android M and above "Screen overlay detected- To change this permission setting you first have to turn off the screen overlay from Settings > Apps"
If app has not been granted permission to draw on the screen, create an Intent &
set its destination to
Settings.ACTION_MANAGE_OVERLAY_PERMISSION
&
* add a URI in the form of
"package:"
to send users directly to your app's page.
Note: Alternative Ignore URI to send user to the full list of apps.
public void permissionToDrawOverlays() {
if (android.os.Build.VERSION.SDK_INT >= 23) { //Android M Or Over
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, PERM_REQUEST_CODE_DRAW_OVERLAYS);
}
}
}
Called on the activity, to check on the results returned of the user action within the settings
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PERM_REQUEST_CODE_DRAW_OVERLAYS) {
if (android.os.Build.VERSION.SDK_INT >= 23) { //Android M Or Over
if (!Settings.canDrawOverlays(this)) {
// ADD UI FOR USER TO KNOW THAT UI for SYSTEM_ALERT_WINDOW permission was not granted earlier...
}
}
}
}
NOTE:Above code and extract is taken from following gist.
Hope this Helps!!!..
Just clear data of the Es explorer from device then after restart device.
I think these two links could help you.
firstlink
secondlink
Try to use for debug build -- targetSdkVersion 22.
After signed APK (for all targetSdkVersion(s)) application will work fine.

How can I set my WatchFaceService as the default launch activity in Android Studio

I have a WatchFaceService (WatchFace) and every time I run my application it switches to the SimpleFace and then I have to set mine as the watchFace which ends up to be quite frustrating after many restarts.
To notice this does happen with the new Android Studio 2
I read around S.O. how to set the default activity but that does not do the same job as my WatchFaceService is not an activity but a service.
Also via the UI of Android Studio 2 it cannot be selected.
Is there a way to achieve this ? I think it might be difficult because actually it's not running an app, but setting the watch's Watchface at every run.
Any ideas?
The short answer is that this isn't possible. Your watch face is a Service, after all, so there's no way that it can be the default (launch) Activity for your app. They're completely different component classes.
But you can get close.
What you need to do is create a tiny little shell Activity that contains only the following code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER)
.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
new ComponentName(getPackageName(),
MyWatchFaceService.class.getName()));
startActivity(intent);
finish();
}
...where MyWatchFaceService is the class name of your watch face service (surprise). You'll also need to declare it in your manifest, of course:
<activity android:name=".FaceActivity"
android:enabled="true"
android:exported="true">
</activity>
Finally, configure your Wear module in Android Studio to launch FaceActivity when you run the app. This is under the Run menu, in Edit Configurations.
Having done that, run your app from AS onto the watch, and it'll open the watch face chooser on-device, with your face selected. From there, one tap will start it.
I can't see a way to eliminate that single tap, though.

How make a Android application that can't be closed

I'm developing an Android app for a company where those who will use it are the employees, for this reason the company asked me to develop an application that the user can not close, because if he will not use the smartphone for other purposes, but for this I need the Android native buttons do not interfere with the application.
I've deactivated the button to go back and put the application as Home.
#Override
     public void onBackPressed () {
         super.onBackPressed ();
     }
...
<category android: name = "android.intent.category.HOME" />
However if the user clicks the button that displays open applications, it can exit the application.
I researched a lot before creating resolve this question and realized several attempts to solve this problem.
One. I tried to create the same behavior as the MX Player has, when you use the lock to see a video, the MX Player is always on top of everything, leaving the user to see and click others places. However using this behavior does not i cant see My Dialogs nor Popup and also can not apply a thema, as in my case is not simply an activity is the entire application.
Reference links of my attempt
How to disable Home and other system buttons in Android?
http://www.piwai.info/chatheads-basics/
If anyone knows how to use that behavior MX Player, or if anyone knows any more how to make the user can not close the application, please help me, I know it's not just me who have this problem.
Any help is welcome!
My API is 16 - Android-4.1
Are your target devices rooted? If so, this article goes through the steps to make this possible. What you specifically ask about can be done by modifying the build.prop file to include the following line: qemu.hw.mainkeys=1. This will stop the soft-key navigation bar from ever showing up.
If the device you're running isn't rooted, I don't think that it's possible to do what you're asking.
The best way i found to the user can't access others apps, was to make a service that check which is the top activity, if don't is my then reopen my app.
ActivityManager manager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> runningTasks = manager.getRunningTasks(1);
if (runningTasks != null && runningTasks.size() > 0) {
ComponentName topActivity = runningTasks.get(0).topActivity;
if (!topActivity.getPackageName().startsWith("com.mypackage.")) {
Log.i("Top Activity", topActivity.getPackageName());
if (LocalCache.getInstance().isForceHome()) {
Intent intent = new Intent(HomeService.this, AuthLoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
handler.postDelayed(this, 500);
}
Old question, but I'm facing exactly same situation:
In-house App
Can't be close
I'm going to set App as a Launcher, and block top-dowm swipe to prevent status bar appear.
I think it's good enough for an in-house App ~

Disable System bar Android 4.0

I know there has been lot of discussion for hiding system bar on android 4.0 but no discussions on disabling the functionality of virtual button or status bar or system bar on Android 4.0 tablets?
Is this possible? Can somebody guide me to the right direction?
Thanks!
Try FLAG_FULLSCREEN, it should hide the status bar
http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_FULLSCREEN
I have done a lot of research to design a lock screen and finally found a solution to permanently disable System bars i.e Navigation bar(Back, home, Recent apps soft keys) and the status bar. Android disabled the feature to override System bars except the back button. But there is a little work around to make this work:
Understand and implement screen pinning patiently and you will be successful.
You can create an app to control what all applications you want to implement screen pinning in or you can implement screen pinning directly in the same application you want to pin.
I'm going to show you the later implementation in this article:
1. Firstly your app should be the device owner.
You can do it in several ways and the easiest is to execute the command:
adb shell dpm set-device-owner [yourPackageName]/.[MyDeviceAdminReceiver]
Create a receiver(MyDeviceAdminReceiver) that extends DeviceAdminReceiver. You needn't have any code in here. For more info on Device owner implementation refer this link
http://florent-dupont.blogspot.com/2015/02/10-things-to-know-about-device-owner.html
Register the receiver in the AndroidManifest.xml file this way :
<receiver
android:name=".MyDeviceAdminReceiver"
android:label="#string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
2. Your onCreate method should look like this:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lock_screen);
ComponentName deviceAdmin = new ComponentName(this, MyDeviceAdminReceiver.class);
DevicePolicyManager mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
if (mDpm.isDeviceOwnerApp(getPackageName())) {
mDpm.setLockTaskPackages(deviceAdmin, new String[]{getPackageName()});
}
if (mDpm.isLockTaskPermitted(this.getPackageName()))
startLockTask();
3.To unpin the screen and make Navigation Bar functional:
Call the function stopLockTask() at a place in your code where you want to unpin. For example in my application, as soon as I verify that the user has typed the correct passcode, I call this function:
if (userInput.length() == 4) {
if (userInput.equals(passcode)) {
userInput = "";
etxtPasscodeDisplay.setText("");
stopLockTask(); // this is what you need
unlockHomeButton(); // A method to show home screen when
passcode is correct
finishAffinity(); //kill other activities
}
Extra Info which usually is required for lockscreens:
1. If your app is the first thing that comes up after boot:
You need a service(StartAtBootService) and a receiver (BootCompletedReceiver) for this.
2. If you want your app to show up after screen lock and unlock
(the power button is pressed to lock and unlock):
Create AEScreenOnOffService that extends service and AEScreenOnOffReceiver that extends BroadcastReceiver to launch your activity when the screen is on.
For a detailed info on everything I mentioned here, refer http://www.sureshjoshi.com/mobile/android-kiosk-mode-without-root/
This is an excellent write up which helped me a lot. Special thanks to the author.
I need at least 10 reputation to post more than two links. As I'm new to stackoverflow I don't have enough reputation so I'm sorry for not being able to share all the links I referred. Will surely update the post once I get access.

Remove from launcher BUT keep enabled / startable

i tried coding it, i tried solving it with google and stackoverflow, nothing found :=) so hopefully someone else has a better idea, im not sure if i get everything right:
i have 2 applications: ad (main app) / adfree-pro (just license starts ad app without ads ;P)
so the problem is, i want to have a pro version (with pro icon) in the launcher, which starts the normal-ad app, which is (the normal ad-app) not in the launcher.
i tried removing the ad-app from the launcher (which due to my research should JUST remove it from the launcher)
pkgMgr.setComponentEnabledSetting(new ComponentName(PACKAGE_NAME, PACKAGE_NAME + ".Main"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
which results to: the icons in the launcher are correct ;) BUT the application can't be found on the phone, launched, started, even not with a launcher pro activity shortcut. it seems to be there (shortcuts can be created) but i crashes with an activity exception when i try to launch it.
02-18 14:38:59.237: ERROR/AndroidRuntime(9941): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {PACKAGE_NAME/PACKAGE_NAME.Main}; have you declared this activity in your AndroidManifest.xml?
which doesnt seem to belong (the error message)
it looks like there has happened more to the application than just simply removed the entry in the launcher.
thanks a lot guys,
every workaround for this situation appreciated :)
best regards :)
You can't have app installed and hide it's launcher icon. The way I'm addressing it with my application which works similar to yours that I don't try to fight icons but instead the app can be launched using ether icon. Obviously you don't have to do in the main (free) app and the code that launches app from your pro icon will look something like the following:
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
// check if main app is installed. If yes then start it
if (appExists()) {
Log.d(TAG, "Started main app from Pro");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("myapp://com.myapp.main"));
startActivity(intent);
finish();
} else {
// display view with link back to Market
onAppNotExists();
}
}
It's up to you to implement appExists() which is probably some sort of license check
Of course, alternatively you can develop your app's common code as library project and then distribute it in 2 flavors without duplicating the code
BUT the application can't be found on the phone, launched, started,
even not with a launcher pro activity shortcut.
Not application, but activity.
So, if your LAUNCHER activity is BaseActivity, you may create something like BaseFakeActivity (don't forget to set it as LAUNCHER in your manifest instead of your BaseActivity) and which only function is to start your BaseActivity and then finish() itself.
Now you may hide your BaseFakeActivity but you'll still be possible to interact with your BaseActivity.
P.S.: Don't forget to test your app's behaviour after doing things this way ;)

Categories

Resources