Jump to content
hackbrew

Delphi 11.3, Android 13 send mapping navigation app intent

Recommended Posts

I'm trying to send a user from my app to the device's default mapping app (Google Maps, Waze,...) on an Android device using an intent. It worked fine in previous Android versions (below v11), but the same code is not working in Android 13. From what I've read about permissions, it appears as though there are many more restrictions beyond Andriod 11.

 

Anyway, when I click the Navigate button in the app, I keep getting the 'Receiver not found' message.

 

My AndroidManifest.xml shows these locations permissions:

android:targetSdkVersion="32" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />

Here's my code for the Navigate button click event:

procedure TMainForm.NavigateBtnClick(Sender: TObject);
var
  {$IFDEF ANDROID}
    Intent: JIntent;  //Declares the intent object
  {$ENDIF}
  LGoogleMapsURL: String;
begin
   // Populate a string to send to Mapping app
   LGoogleMapsURL:= 'google.navigation:q=37.422219,-122.08364&mode=d';
  
  {$IFDEF MSWINDOWS}
    WebBrowser1.Navigate(LGoogleMapsURL);
  {$ENDIF}

  {$IFDEF ANDROID}
      Intent := TJIntent.Create;
      Intent.setData(StrToJURI(LGoogleMapsURL));
      Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
      Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString(LGoogleMapsURL));
      if MainActivity.getPackageManager.queryIntentActivities(Intent, TJPackageManager.JavaClass.MATCH_DEFAULT_ONLY).size > 0 then
        begin          
          MainActivity.startActivity(Intent);
        end
      else
        ShowMessage('Receiver not found');
  {$ENDIF}
end;

Is this no longer valid for Android 13?

Share this post


Link to post

Credit goes to @Dave Nottage for assistance. I had to modify the AndroidManifest.template.xml, to change the <queries> tag to:

<queries>
<%queries-child-elements%>
        <package android:name="com.google.android.apps.maps" />
    </queries>

In my OnClick event I added:

URI := TJnet_Uri.JavaClass.parse(StringToJString('google.navigation:q=37.422219,-122.08364&mode=d'));
  Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW, URI);
  Intent.setPackage(StringToJString('com.google.android.apps.maps'));
  if Intent.resolveActivity(TAndroidHelper.Context.getPackageManager) <> nil then
    TAndroidHelper.Context.startActivity(Intent);

That works great for the Google mapping app, but I'd like a way to call the user's preferred/default mapping app on the device.

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

×