I want to check programatically if my device is locked by a third party Lockscreen...With the normal Lockscreen by android you can do that by
KeyguardManager kgMgr = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean locked = kgMgr.inKeyguardRestrictedInputMode();
But what if a third party Lockscreen is installed?! Is there any way to check if the device is locked?
You can get the foreground app and check for its permissions using the PackageManager class.
To get the foreground application you can go through this link.
Once you get the foreground app, you can fetch the permissions of that app. Check this link for this functionality.
Later, You can check whether its a system app or not by going through getApplicationInfo and later & with ApplicationInfo.FLAG_SYSTEM. You can check this link on how to do that.
I think that all custom lockscreens use the <uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> permission. So your method should be correct in most of standard cases.
Related
I am looking for a way to listen for starting applications/activities.
I guess many of You know the application "Tasker" which achieves exactly that. If a chosen applications gets launched, a specific task starts.
Now I wonder how to achieve that? I could start a Service, but which method should I use?
I noticed that Tasker asks for a permission before using this method. The application redirects me to the Accessibility Settings tab where I can enable Tasker with the notification: "Tasker wants permission to: Monitor your actions - Allows TalkBack to know when you are using an app"
Any suggestions?
Edit:
I found out that an AccessibilityService is used. Now my problem is, how do I specify all installed packages to this Service? I know that it's possible to specify packages one by one but how do I select all?
you can use getRunningTasks Method
ActivityManager am = (ActivityManager) mContext
.getSystemService(Activity.ACTIVITY_SERVICE);
String packageName = am.getRunningTasks(1).get(0).topActivity
.getPackageName();
Note This method was deprecated in API level 21. you can try this also.
I have an app that plays audio. I recently added the permission:
android.permission.READ_PHONE_STATE
so I could tell when a call was coming in so I could mute the audio during the call. I also added the permission:
android.permission.CALL_PHONE
So the user could press a icon to call a phone number. These were minor changes and really don't affect how most people use the app. After I published it I now have users who have tablets that don't have phone capability that they can not download the update and new users who have tablets do not see it in the play store anymore.
I read several posts about using this in the manifest instead of the permissions:
<uses-feature android:name="android.hardware.telephony" android:required="false">
But when I try to test the app on the device I get this error:
Caused by: java.lang.SecurityException: Neither user 10022 nor current process has android.permission.READ_PHONE_STATE.
Does anyone have any suggestions on how I can add these minor features to the app without alienating all of the non-phone users?
I read several posts about using this in the manifest instead of the permissions
You use <uses-feature> in addition to the permissions, not instead of the permissions.
Quoting the documentation:
For any of the permissions below, you can disable filtering based on the implied feature by explicitly declaring the implied feature explicitly, in a element, with an android:required="false" attribute.
So, add back your permissions. Then, use PackageManager and hasSystemFeature() at runtime, to see whether the device has android.hardware.telephony, so you can react as needed.
As #CommonsWare suggested use the following code to check if the device has telephony features available using the PackageManager
PackageManager pm = getBaseContext().getPackageManager();
pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
How do I unlock phone screen when some event happens?I tried the following code but it does not unlock the screeen . By unlock I mean bypass PIN or pattern
Am using following code and its get triggered when a sms is received.
private void unlockScreen(Context context){
Log.d("dialog", "unlocking screen now");
PowerManager powermanager = ((PowerManager)context.getSystemService(Context.POWER_SERVICE));
WakeLock wakeLock = powermanager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
wakeLock.acquire();
Window wind = DialogActivity.this.getWindow();
wind.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
wind.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
wind.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
}
Screen is powered on but the user has to enter PIN/pattern.How do I get over it?
Straight from the android API Site for disableKeyguard():
Disable the keyguard from showing. If the keyguard is currently
showing, hide it. The keyguard will be prevented from showing again
until reenableKeyguard() is called. A good place to call this is from
onResume() Note: This call has no effect while any DevicePolicyManager
is enabled that requires a password.
Based off that bolded statement I would probably say that you cannot do that without a password. The only way passed that is if you had yourself(app) added to the phone as a device admin, then you could control that from your device admin application of removing the password, wiping it etc.
Source : KeyguardManager.KeyguardLock & DevicePolicyManager
EDIT
I found the source code of the LockPatternUtils (I know it is from older version, but I doubt it has changed much) that is in part pattern locks and it has DevicePolicyManager all over it. I believe it has an internal service running as root in the system that does all the work. So without being a device admin, you do not even have authority to unlock the phone when it has a security setting for it.
I am developing an SMS android application. One of the feature, I want to add is upon receiving an SMS the screen lock will be automatically disabled so that user need not unlock to read the message.
Is this possible? I tried few examples but those are the working. E.g How to Disable Keyguard and display an activity to the user when receiver of SCREEN_ON is triggered?
Any idea how to implement this?
You should use something like this :
KeyguardManager myKGuard = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
myLock = myKGuard.newKeyguardLock("com.example.myapp.Main");
myLock.disableKeyguard();
Also please note you will need to add DISABLE_KEYGUARD Permission to the manifest as well.
Hope this helps!
This is deprecated as of API 13 as well.
Use FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED instead; this allows you to seamlessly hide the keyguard as your application moves in and out of the foreground and does not require that any special permissions be requested. Handle returned by newKeyguardLock(String) that allows you to disable / reenable the keyguard.
That is what Google says as of now !
I'm trying to turn off the android radio programmatically. I'm trying to use the ServiceState class, but it wont work. I added the permission CHANGE_NETWORK_STATE and MODIFY_PHONE_STATE. Still no luck. any ideas?
Permission MODIFY_PHONE_STATE is a system permission, thus, you cannot use it in your application.
EDIT:
Ok. I'll try to explain. The service method to turn on and turn off radio programatically is protected with MODIFY_PHONE_STATE permission. This permission has signature type, thus, only applications that have the same signature can invoke this method. Thus, so as your application is not signed with the system certificate you cannot use this permission in your application. But without this permission you also cannot change the state of the radio.