开发者

ControlledAccessException occurs during player creation in 4.6 above OS!

开发者 https://www.devze.com 2022-12-17 00:30 出处:网络
PLease suggest how to overcome from this exception, my code is given below: String TestFile = \"file:///\" + RTTToneImpl.getEmergencyTone();

PLease suggest how to overcome from this exception, my code is given below:

String TestFile = "file:///" + RTTToneImpl.getEmergencyTone();
       Player player;
       try
       {
           player = Manager.createPlayer(TestFile);
       }
       catch(ControlledAccessException e)
       {
           Dialog errorDialog = new Dialog(0, "Please use the BlackBerry Options application to allow Media Access permission for Ring Trump Tones.", 0, Bitmap.getPredefinedBitmap(2), 0L);
           errorDialog.doModal();
           System.exit(0);
       }
       catch(IOException e)
       {
           Dialog errorDialog = new Dialog(0, "Caught IOException type when checking media permission:- " + e.getMessage(), 0, Bitmap.getPredefinedBitmap(2), 0L);
           errorDialog.doModal();
           System.exit(0);
       }
       catch(Exception e)
      开发者_运维百科 {
           Dialog errorDialog = new Dialog(0, "Unexpected exception type when checking media permission:- " + e.getMessage(), 0, Bitmap.getPredefinedBitmap(2), 0L);
           errorDialog.doModal();
           System.exit(0);
       }
ApplicationPermissions permRequest = ApplicationPermissionsManager.getInstance().getApplicationPermissions();
       if( permRequest.getPermission( ApplicationPermissions.PERMISSION_MEDIA ) == ApplicationPermissions.VALUE_ALLOW )
       {
                 return ;
       }
       permRequest = new ApplicationPermissions();
       permRequest.addPermission( ApplicationPermissions.PERMISSION_MEDIA );
       permRequest.addPermission( ApplicationPermissions.PERMISSION_FILE_API );

       ApplicationPermissionsManager.getInstance().invokePermissionsRequest( permRequest );

Thanks and Regards Mintu


In addition to ApplicationPermissions.PERMISSION_MEDIA (which you have in your code), we found that we sometimes needed the ApplicationPermissions.PERMISSION_CHANGE_DEVICE_SETTINGS permission in order to play audio. I'm not sure why, but give that a try and see if it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消