Jump to content
WestyOz

Delphi 10.3 | Android : registerIntentAction -> java.lang.UnsupportedOperationException

Recommended Posts

It appears that when using Delphi 10.3 and targeting the latest Android API (26) the following call no longer works:  MainActivity.registerIntentAction(TJIntent.JavaClass.ACTION_VIEW);

 

The exception is raise 'java.lang.UnsupportedOperationException'.

 

This was required when facilitating the handling the opening of an associated file using an <intent-filter> within the AndroidManifest.template.xml.  The full code sequence is as follows:

 

	  // Register the type of intent action that we want to be able to receive.
      // Note: A corresponding <action> tag must also exist in the <intent-filter> section of AndroidManifest.template.xml.
      MainActivity.registerIntentAction(TJIntent.JavaClass.ACTION_VIEW);
      TMessageManager.DefaultManager.SubscribeToMessage(TMessageReceivedNotification, HandleActivityMessage);

I've had the same challenge when running the AndroidIntents project from the supplied Samples. 

 

Has anyone else encountered this and managed to solve for it?

Share this post


Link to post

I can't see how it could have ever worked. The code for registerIntentAction in FMXNativeActivity.java:

 

    public void registerIntentAction(String action) {
        mRegisteredIntentActions.add(action);
    }

 

..and where it is initialized:

 

    private List<String> mRegisteredIntentActions = Arrays.asList(NotificationInfo.ACTION_NOTIFICATION,
                                                                  NotificationPublisher.ACTION_GCM_NOTIFICATION);

Arrays.asList returns a fixed size list:

 

https://developer.android.com/reference/java/util/Arrays.html#asList(T...)

 

i.e. it cannot be added to. Attempting to add anything will raise the error that you're seeing.

Share this post


Link to post

Thanks for the reply and insights Dave it is much appreciated - and indeed you are exactly right.  With your reference I went back to Delphi 10.2.3 and inspected FMXNativeActivity.java and note the declaration as:

 

private List<String> mRegisteredIntentActions;

and in the onCreate() it is updated as:

 

.
.
.
	mRegisteredIntentActions = new ArrayList<String>();
	mRegisteredIntentActions.add(NotificationInfo.ACTION_NOTIFICATION);
	mRegisteredIntentActions.add(NotificationPublisher.ACTION_GCM_NOTIFICATION);
.
.
.      

So there has been a step change between versions, which must have been for a reason?

Share this post


Link to post

Thanks Brian for the unofficial fix - I've applied this and it works.

 

Just a couple of things I had to tweak though.  In the .bat file I had to adjust as follows:
 

rem set SDK_PATH=%PUBLIC%\Documents\Embarcadero\Studio\20.0\PlatformSDKs\android-sdk-windows
set SDK_PATH=%PUBLIC%\Documents\Embarcadero\Studio\20.0\CatalogRepository\AndroidSDK-2525_20.0.32429.4364\

 

And in the FMXNativeActivity.java, I had to explicitly add the import of java.util.ArrayList (got an exception otherwise)

 

import java.util.ArrayList; 
.
.
.
	private List<String> mRegisteredIntentActions;
.
.      
. 
protected void onCreate(Bundle savedInstanceState) {
        // Check device architecture
        DeviceArchitectureChecker.check();

        // Debugger
        if (CLASSES_DEX_DEBUGGER_SUPPORT) {
            DebuggerUtils debuggerUtils = new DebuggerUtils(this);
            debuggerUtils.tryStartDebugger();
        }

        virtualKeyboard = new VirtualKeyboard(this);

		mRegisteredIntentActions = new ArrayList<String>();
		mRegisteredIntentActions.add(NotificationInfo.ACTION_NOTIFICATION);
		mRegisteredIntentActions.add(NotificationPublisher.ACTION_GCM_NOTIFICATION);
		
        super.onCreate(savedInstanceState);      

I am no expert in this space - so not sure if this is the ideal approach but it seemed to work.

Share this post


Link to post
Quote

And in the FMXNativeActivity.java, I had to explicitly add the import of java.util.ArrayList (got an exception otherwise)

So using the fully qualified class name didn't work (mRegisteredIntentActions = new java.util.ArrayList<String>();)? That's odd. I'm pretty sure it did for me....

 

And by exception do you mean a runtime exception, or a compile-time error?

 

Quote

In the .bat file I had to adjust as follows

Ah, so that SDK path I assume is from an ESD install? My path came from an ISO install. Useful to know another possible default path - I'll add that into the text later, thanks!

Share this post


Link to post

In regards to the java error it was compile time error -> 'Cannot find symbol'.  Again, I'm no expert with java - so I just applied the first Dr Google suggestion and got a result.

 

Also it was the Web Install rather than the ISO.  First time I've gone this way on a Delphi install and the paths are different between versions (compared to 10.2 on my machine at least).

 

And again, thanks for taking the time to document and supply a fix for the Delphi community.  I'm sure I'm not the only one that has had a headache over this so to get a solid resolution whilst a patch is developed was gratefully received.

Share this post


Link to post
4 hours ago, WestyOz said:

Also it was the Web Install rather than the ISO.  First time I've gone this way on a Delphi install and the paths are different between versions (compared to 10.2 on my machine at least).

I am trying to fathom why the web install and ISO install apparently has different versions of .DCUs (or perhaps source). Check the last comment, here:

 

  https://quality.embarcadero.com/browse/RSP-18836

 

They must be being packaged from different sources; the question is why on Earth are they?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×