I'm developing an application that needs to know when other third party app requests the microphone. Is there any way to detect it?
Thanks in advance!
I'm developing an application that needs to know when other third party app requests the microphone. Is there any way to detect it?
Thanks in advance!
After some research, it seems to be impossible to know when another third party application requests the MICROPHONE due to security reasons.
If you want to perform actions according to actual state of the media recorder, you may have to handle that as explained in this post:
How to detect if MediaRecorder is used by another application?
And about detecting other apps permissions access, I think this can provide an answer: How to detect permission access of other apps?
But if you want to check apps that needs RECORD_AUDIO permission, you can continue reading the following lines:
Based on the answer of Kopi-B at this question
To get the list of apps requesting microphone you can then proceed as follows:
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
//create a package names list
List<String> packageNames=new ArrayList<>();
for (Object obj : pkgAppsList) {
ResolveInfo resolveInfo = (ResolveInfo) obj;
PackageInfo packageInfo = null;
try {
packageInfo = getPackageManager().getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS);
} catch (PackageManager.NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] requestedPermissions = packageInfo.requestedPermissions;
//check the microphone permission
if (requestedPermissions!=null) {
for (String packagePermission : requestedPermissions) {
if (packagePermission == Manifest.permission.RECORD_AUDIO) {
packageNames.add(packageInfo.packageName);
break;
}
}
}
}