ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
509 stars 577 forks source link

[app-launcher] Android : Test for installation of Twitter and Facebook apps. canOpenUrl({ url: '...'}) always returns false #1744

Open kosso opened 1 year ago

kosso commented 1 year ago

Bug Report

Plugin(s)

app-launcher

Capacitor Version

Latest Dependencies:

  @capacitor/cli: 5.2.3
  @capacitor/core: 5.2.3
  @capacitor/android: 5.2.3
  @capacitor/ios: 5.2.3

Installed Dependencies:

  @capacitor/cli: 5.2.2
  @capacitor/android: 5.2.2
  @capacitor/core: 5.2.2
  @capacitor/ios: 5.2.2

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

Android

Current Behavior

I need to test if the Twitter/X and Facebook apps are installed.

On iOS, the code provided below works as expected and returns true if both apps are installed. (In order to make this work on iOS, I also needed to add the LSApplicationQueriesSchemes to Info.plist containing an array of strings including twitter and fb.)

On Android however, the code below returns false for both apps, despite them being installed.

I have tried adding the required entries to AndroidManifest.xml to allow querying the packages:

<queries>
    <package android:name="com.twitter.android" />
    <package android:name="com.facebook.katana" />
    <intent>
      <action android:name="android.intent.action.VIEW"/>
      <data android:scheme="twitter"/>
    </intent>
    <intent>
      <action android:name="android.intent.action.VIEW"/>
      <data android:scheme="fb"/>
    </intent>
  </queries>

I have also tried adding this permission :

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" />

Expected Behavior

I expect the result to be true when the apps are installed on the device.

What am I missing?

Code Reproduction

import { AppLauncher } from '@capacitor/app-launcher';

AppLauncher.canOpenUrl({ url: 'twitter://timeline' }).then(data => {
        console.log('AppLauncher : Is Twitter/X installed? ', data.value);
});

AppLauncher.canOpenUrl({ url: 'fb://feed' }).then(data => {
        console.log('AppLauncher : Is Facebook installed? ', data.value);
});
Ionitron commented 1 year ago

This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed.

Please see the Contributing Guide for how to create a Sample App.

Thanks! Ionitron 💙

kosso commented 1 year ago

I have provided a simple code sample above.

Please also refer to the Example Code provided in the actual documentation for this official plugin.

Simply replace the URLs with the ones that I have clearly provided above.

Sorry, but I do not understand what else you need?

This plugin does not work as documented, as I have clearly explained above.

(The documentation fails to even mention the additions to Info.plist I had to add for this to work on iOS)

I can't believe how many hours I've wasted trying to make this work as documented.

jcesarmobile commented 1 year ago

we need a full sample app that we can build and run to reproduce the issue

the additions to the Info.plist are documented here

kosso commented 1 year ago

Please find a full sample app here

https://github.com/kosso/applauncher-issue

This is built for iOS and Android and will demonstrate that the iOS version works and the Android version doesn't.

kosso commented 1 year ago

Additional information and testing a new method :

I have had a go at creating an internal custom 'Utils' plugin for Android to try a different method than the way that the app-launcher plugin tries to perform canOpenUrl() ...

.. and it works!

Please see the custom-utils-test branch of my sample app for testing and reference here :

https://github.com/kosso/applauncher-issue/tree/custom-utils-test

Here is the source to my test 'Utils' Android plugin, containing a method canOpenURLTest()

https://github.com/kosso/applauncher-issue/blob/custom-utils-test/android/app/src/main/java/com/kosso/applauncherissue/UtilsPlugin.java

ionitron-bot[bot] commented 1 year ago

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

maudvd commented 1 year ago

Same problem here. CanOpenUrl only works with a package name on Android.

PreciousBiscuit commented 6 months ago

I would like to see this bug fixed in the plugin as well. But I won't have my hopes up, because it was requested multiple times already and not fixed once. What is more surprising that openUrl() works fine for me. It's just that canOpenUrl() returns false.

For anyone stumbling on this, you can use cordova-plugin-app-launcher instead.

dtarnawsky commented 4 months ago

I can confirm that if you modify the reproduction app to: AppLauncher.canOpenUrl({ url: 'com.twitter.android' }) rather than: AppLauncher.canOpenUrl({ url: 'twitter://timeline' }) it will correctly detect Twitter (X).

And for Facebook: Launcher.canOpenUrl({ url: 'com.facebook.katana' }) rather than: AppLauncher.canOpenUrl({ url: 'fb://feed' })