Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 46
Registered: ‎12-01-2009
My Device: Not Specified

BlackBerry freezes on rejected permissions request

Hey guys,

 

I'm trying to make my app request permissions up front. It mostly works fine, like so:

 

1. App starts, user is notified that the app would like to request a change to its permissions.

2. User gets a permissions screen with a bunch of features on the left (e.g. Phone, WiFi), and permissions on the right (e.g. Allow, Prompt, Deny).

3. If the user chooses all Allow (as default) and clicks Save, all it well. Otherwise, nasty things happen:

 

The BlackBerry completely freezes on the permissions screen, ignoring all key presses. The only exception I've found is holding the power button, which will cause it to turn off after a few seconds.

 

I was following the tutorial here: http://developerlife.com/tutorials/?p=852

 

The code is as follows:

 

 

public class Main extends UiApplication
{
    public static void main(String[] args)
    {
        Main main = new Main();
        main.enterEventDispatcher();
    }
    
    public Main()
    {
        if(haveAllPermissions() == false)
        {
            System.exit(1);
        }

// Continue to run.
}


// And here is my haveAllPermissions()
public boolean haveAllPermissions() { ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance(); ApplicationPermissions original = apm.getApplicationPermissions(); if( original.getPermission(ApplicationPermissions.PERMISSION_PHONE) == ApplicationPermissions.VALUE_ALLOW && original.getPermission(ApplicationPermissions.PERMISSION_WIFI) == ApplicationPermissions.VALUE_ALLOW ) { return true; } else { ApplicationPermissions permissionsRequest = new ApplicationPermissions(); permissionsRequest.addPermission(ApplicationPermissions.PERMISSION_PHONE); permissionsRequest.addPermission(ApplicationPermissions.PERMISSION_WIFI); return apm.invokePermissionsRequest(permissionsRequest); } }

 

 

This is on the Curve 8900.

 

Cheers,

Pav

 

Highlighted
Contributor
Posts: 41
Registered: ‎07-28-2010
My Device: Not Specified

Re: BlackBerry freezes on rejected permissions request

Geez, no body knows the answer, I'm having the same problem and looking for the solution ...

Developer
Posts: 92
Registered: ‎01-15-2009
My Device: Blackberry 9550

Re: BlackBerry freezes on rejected permissions request

Hi. Try to use this sample code

 

 

int[] PERMS //- array of permissions
public void setPermissions()
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
{ try { ApplicationPermissionsManager pmanager = ApplicationPermissionsManager.getInstance(); ApplicationPermissions permRequest = new ApplicationPermissions(); for (int i = 0; i < PERMS.length; i++) permRequest.addPermission(PERMS[i]); if (pmanager.invokePermissionsRequest(permRequest)) Dialog.alert("Changes take effect after the next start of the application."); else Dialog.alert("Permissions was not set properly"); } catch (Exception e) { System.exit(0); } System.exit(0); }
}
});
}

 

Regards, Dmitry.

 

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: BlackBerry freezes on rejected permissions request

the problem is not (directly) with your code but rather with RIMs implementation.

the applicationpermissionsmanager somehow trys to access the outer (your) application. if you launch it from a static context there is no application instance.

 

you can solve this by creating an application instance for this call.

 

In my application, for example, i check the permissions in the autostart part by using

 

new AutoStartApplication().enterEventDispatcher();

 

in the alternate entry point.

 

 

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 107
Registered: ‎10-06-2010
My Device: Not Specified

Re: BlackBerry freezes on rejected permissions request

Sorry Simon

 

Could you please explain in detail in steps as I am still confused.

 

I created an alternate entry point and UiApplication class to invoke the Application Permissions. But I cannot get going.

 

Thank you very much for your help. I really feel that I am very close to solution now.

 

Nitin

 

 

 

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: BlackBerry freezes on rejected permissions request

you can use an application, no need for uiapplication.

inside the apps constructor you can check the permissions.

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 92
Registered: ‎01-15-2009
My Device: Blackberry 9550

Re: BlackBerry freezes on rejected permissions request

Hi. Demo start of application

 

 

public class Myapplication extends UiApplication
{
	public static Myapplication instance = null;

	public Myapplication()
	{
	}

	public static void main(String[] args)
	{

		//Check for the argument defined in the project 
		instance = new Myapplication();
		instance.init();
		instance.enterEventDispatcher();
	}

        public void init()
	{
		try
		{
			if (!checkPermissions())
			{
			    setPermissions();
			    return;
			}
		}
		catch (Exception e)
		{
			Log.critical("Entry point falt at=", e);
			//alertError( "quitApp "+e );
		}
	}

Method  setPermissions() you can find in my previous post. You need to use

 

UiApplication.getUiApplication().invokeLater(new Runnable()
{
  public void run()
  {	
  }
});

 to avoid freezing like I do.

 

 

Regards, Dmitry.

 

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: BlackBerry freezes on rejected permissions request

if you move the permission check into the applications constructor you don't need an invokelater.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 107
Registered: ‎10-06-2010
My Device: Not Specified

Re: BlackBerry freezes on rejected permissions request

[ Edited ]

Hi Simon,

 

Thank you very much for sticking with.

 

After spending halft a day, I am still at the place where I started - Cannot run on simulator and on device - freezing with please wait screen.

 

I am not sure where things are going wrong.

 

Here is the code for your reference - its crappy as i have been trying different things

 

Main Applications main method:

 

public static void main(String[] args)
{
   if (args != null && args.length>0 && args[0].equals("assertpermission"))
   {
      new AutoStartApplication().enterEventDispatcher();		
   }
   else
   {
          Main app = new Main();
	app.enterEventDispatcher();
   }
}

Code that starts new application - If the application doesn't have the required permission, I invoke following line of code

ApplicationManager.getApplicationManager().launchApplication("MainAppName?assertpermission");

 

The AutoStartApplication - which invokes permission screen

 

public AutoStartApplication()
{
final ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance(); apm.addReasonProvider(ApplicationDescriptor.currentApplicationDescriptor(), new ReasonProvider() { public String getMessage(int i) { String msg = "PERMISSION REQUIRED"; if(i == ApplicationPermissions.PERMISSION_PHONE) msg = "WHY PHONE PERMISSION MESSAGE!"; return msg; } }); boolean permissionsOk = false; ApplicationPermissions permRequest = new ApplicationPermissions(); permRequest.addPermission(ApplicationPermissions.PERMISSION_PHONE); permissionsOk = apm.invokePermissionsRequest(permRequest); System.exit(0);
}

 

 

 Dmitry: I tried your method as well but unfortunately no luck.

 

This is really annoying. I wonder why there is no good documentation available from RIM about this.

 

Nitin

 

 

 

 

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: BlackBerry freezes on rejected permissions request

your code looks ok to me. i run mine in an alternate entry point on autostart, maybe your call with applicationmanager causes problems.

i would suggest you add an alternate entry point in your BlackBerry_App_Descriptor.xml (if you use the plugin), check autorun and don't display icon.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter