-1

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!

Emilio
  • 7
  • 3
  • After installing your app on your device, go check for permissions in settings->apps-> your app – Fakher Nov 08 '18 at 10:51
  • I think this post should help (https://stackoverflow.com/questions/4386823/how-to-get-manifest-permissions-of-any-installed-android-app) – android_user77 Nov 08 '18 at 11:00

1 Answers1

0

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;
                    }
                }
            }
        }
Gratien Asimbahwe
  • 1,606
  • 4
  • 19
  • 30