Niva Kaur
Niva Kaur

Reputation: 1

Sample Print Service application is getting crash with Fatal Exception: java.lang.RuntimeException: java.lang.SecurityException:

I am using the isPrintServiceEnabled new API of the PrintManager class to retrieve the getPrintServiceState of Android version 13 and above. After implementation, we encounter a java.lang.SecurityException: Permission denial, indicating that we must have one of the following permissions: [android.permission.WRITE_SECURE_SETTINGS]. Steps to reproduce:

  1. Install the print application.
  2. Launch the application.
  3. Shutdown the mobile device.
  4. Turn ON the mobile device again.
  5. Immediately launch the Print Application. At this point, the Print Application crashes.

Here the sample code if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE); ComponentName serviceComponent = new ComponentName(serviceName, PrintApplication.class.getName()); boolean isServiceAvailable = printManager.isPrintServiceEnabled(serviceComponent); if (isServiceAvailable) { return "enable"; } else { return "disable"; } }

Upvotes: 0

Views: 25

Answers (0)

Related Questions