@capacitor/app-launcher 7.0.3 → 7.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,12 +6,18 @@ On iOS you can only open apps if you know their url scheme.
6
6
 
7
7
  On Android you can open apps if you know their url scheme or use their public package name.
8
8
 
9
- **Note:** On [Android 11](https://developer.android.com/about/versions/11/privacy/package-visibility) and newer you have to add the app package names you want to query in the `AndroidManifest.xml` inside the `queries` tag.
9
+ **Note:** On [Android 11](https://developer.android.com/about/versions/11/privacy/package-visibility) and newer you have to add the app package names or url schemes you want to query in the `AndroidManifest.xml` inside the `queries` tag.
10
10
 
11
11
  Example:
12
12
  ```xml
13
13
  <queries>
14
- <package android:name="com.getcapacitor.myapp" />
14
+ <!-- Query by package name -->
15
+ <package android:name="com.twitter.android" />
16
+ <!-- Query by url scheme -->
17
+ <intent>
18
+ <action android:name="android.intent.action.VIEW"/>
19
+ <data android:scheme="twitter"/>
20
+ </intent>
15
21
  </queries>
16
22
  ```
17
23
 
@@ -27,14 +33,26 @@ npx cap sync
27
33
  ```typescript
28
34
  import { AppLauncher } from '@capacitor/app-launcher';
29
35
 
30
- const checkCanOpenUrl = async () => {
31
- const { value } = await AppLauncher.canOpenUrl({ url: 'com.getcapacitor.myapp' });
32
-
36
+ const checkCanOpenTwitterUrl = async () => {
37
+ const { value } = await AppLauncher.canOpenUrl({ url: 'twitter://timeline' });
33
38
  console.log('Can open url: ', value);
34
39
  };
35
40
 
36
- const openPortfolioPage = async () => {
37
- await AppLauncher.openUrl({ url: 'com.getcapacitor.myapp://page?id=portfolio' });
41
+ const openTwitterUrl = async () => {
42
+ const { completed } = await AppLauncher.openUrl({ url: 'twitter://timeline' });
43
+ console.log('openUrl completed: ', completed);
44
+ };
45
+
46
+ // Android only
47
+ const checkCanOpenTwitterPackage = async () => {
48
+ const { value } = await AppLauncher.canOpenUrl({ url: 'com.twitter.android' });
49
+ console.log('Can open package: ', value);
50
+ };
51
+
52
+ // Android only
53
+ const openTwitterPackage = async () => {
54
+ const { completed } = await AppLauncher.openUrl({ url: 'com.twitter.android' });
55
+ console.log('openUrl package completed: ', completed);
38
56
  };
39
57
  ```
40
58
 
@@ -68,6 +86,12 @@ This method always returns false for undeclared schemes, whether or not an
68
86
  appropriate app is installed. To learn more about the key, see
69
87
  [LSApplicationQueriesSchemes](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/plist/info/LSApplicationQueriesSchemes).
70
88
 
89
+ On Android the URL can be a known URLScheme or an app package name.
90
+
91
+ On [Android 11](https://developer.android.com/about/versions/11/privacy/package-visibility)
92
+ and newer you have to add the app package names or url schemes you want to query in the `AndroidManifest.xml`
93
+ inside the `queries` tag.
94
+
71
95
  | Param | Type |
72
96
  | ------------- | --------------------------------------------------------------- |
73
97
  | **`options`** | <code><a href="#canopenurloptions">CanOpenURLOptions</a></code> |
@@ -42,7 +42,7 @@ android {
42
42
  buildTypes {
43
43
  release {
44
44
  minifyEnabled false
45
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
45
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
46
46
  }
47
47
  }
48
48
  lintOptions {
@@ -3,6 +3,7 @@ package com.capacitorjs.plugins.applauncher;
3
3
  import android.content.Context;
4
4
  import android.content.Intent;
5
5
  import android.content.pm.PackageManager;
6
+ import android.content.pm.ResolveInfo;
6
7
  import android.net.Uri;
7
8
  import com.getcapacitor.JSObject;
8
9
  import com.getcapacitor.Logger;
@@ -35,11 +36,19 @@ public class AppLauncherPlugin extends Plugin {
35
36
  } catch (PackageManager.NameNotFoundException e) {
36
37
  Logger.error(getLogTag(), "Package name '" + url + "' not found!", null);
37
38
  }
38
-
39
- ret.put("value", false);
39
+ if (!canResolve(pm, new Intent(Intent.ACTION_VIEW, Uri.parse(url)))) {
40
+ ret.put("value", canResolve(pm, new Intent(url)));
41
+ } else {
42
+ ret.put("value", true);
43
+ }
40
44
  call.resolve(ret);
41
45
  }
42
46
 
47
+ private boolean canResolve(PackageManager pm, Intent intent) {
48
+ ResolveInfo resolve = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
49
+ return resolve != null;
50
+ }
51
+
43
52
  @PluginMethod
44
53
  public void openUrl(PluginCall call) {
45
54
  String url = call.getString("url");
@@ -47,24 +56,28 @@ public class AppLauncherPlugin extends Plugin {
47
56
  call.reject("Must provide a url to open");
48
57
  return;
49
58
  }
50
-
51
59
  JSObject ret = new JSObject();
52
60
  final PackageManager manager = getContext().getPackageManager();
53
61
  Intent launchIntent = new Intent(Intent.ACTION_VIEW);
54
62
  launchIntent.setData(Uri.parse(url));
55
-
56
- try {
57
- getActivity().startActivity(launchIntent);
58
- ret.put("completed", true);
59
- } catch (Exception ex) {
60
- launchIntent = manager.getLaunchIntentForPackage(url);
61
- try {
62
- getActivity().startActivity(launchIntent);
63
+ if (!canLaunchIntent(launchIntent)) {
64
+ if (!canLaunchIntent(manager.getLaunchIntentForPackage(url))) {
65
+ ret.put("completed", canLaunchIntent(new Intent(url)));
66
+ } else {
63
67
  ret.put("completed", true);
64
- } catch (Exception expgk) {
65
- ret.put("completed", false);
66
68
  }
69
+ } else {
70
+ ret.put("completed", true);
67
71
  }
68
72
  call.resolve(ret);
69
73
  }
74
+
75
+ private boolean canLaunchIntent(Intent intent) {
76
+ try {
77
+ getActivity().startActivity(intent);
78
+ return true;
79
+ } catch (Exception ex) {
80
+ return false;
81
+ }
82
+ }
70
83
  }
package/dist/docs.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "text": "1.0.0"
23
23
  }
24
24
  ],
25
- "docs": "Check if an app can be opened with the given URL.\n\nOn iOS you must declare the URL schemes you pass to this method by adding\nthe `LSApplicationQueriesSchemes` key to your app's `Info.plist` file.\nLearn more about configuring\n[`Info.plist`](https://capacitorjs.com/docs/ios/configuration#configuring-infoplist).\n\nThis method always returns false for undeclared schemes, whether or not an\nappropriate app is installed. To learn more about the key, see\n[LSApplicationQueriesSchemes](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/plist/info/LSApplicationQueriesSchemes).",
25
+ "docs": "Check if an app can be opened with the given URL.\n\nOn iOS you must declare the URL schemes you pass to this method by adding\nthe `LSApplicationQueriesSchemes` key to your app's `Info.plist` file.\nLearn more about configuring\n[`Info.plist`](https://capacitorjs.com/docs/ios/configuration#configuring-infoplist).\n\nThis method always returns false for undeclared schemes, whether or not an\nappropriate app is installed. To learn more about the key, see\n[LSApplicationQueriesSchemes](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/plist/info/LSApplicationQueriesSchemes).\n\nOn Android the URL can be a known URLScheme or an app package name.\n\nOn [Android 11](https://developer.android.com/about/versions/11/privacy/package-visibility)\nand newer you have to add the app package names or url schemes you want to query in the `AndroidManifest.xml`\ninside the `queries` tag.",
26
26
  "complexTypes": [
27
27
  "CanOpenURLResult",
28
28
  "CanOpenURLOptions"
@@ -11,6 +11,12 @@ export interface AppLauncherPlugin {
11
11
  * appropriate app is installed. To learn more about the key, see
12
12
  * [LSApplicationQueriesSchemes](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/plist/info/LSApplicationQueriesSchemes).
13
13
  *
14
+ * On Android the URL can be a known URLScheme or an app package name.
15
+ *
16
+ * On [Android 11](https://developer.android.com/about/versions/11/privacy/package-visibility)
17
+ * and newer you have to add the app package names or url schemes you want to query in the `AndroidManifest.xml`
18
+ * inside the `queries` tag.
19
+ *
14
20
  * @since 1.0.0
15
21
  */
16
22
  canOpenUrl(options: CanOpenURLOptions): Promise<CanOpenURLResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface AppLauncherPlugin {\n /**\n * Check if an app can be opened with the given URL.\n *\n * On iOS you must declare the URL schemes you pass to this method by adding\n * the `LSApplicationQueriesSchemes` key to your app's `Info.plist` file.\n * Learn more about configuring\n * [`Info.plist`](https://capacitorjs.com/docs/ios/configuration#configuring-infoplist).\n *\n * This method always returns false for undeclared schemes, whether or not an\n * appropriate app is installed. To learn more about the key, see\n * [LSApplicationQueriesSchemes](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/plist/info/LSApplicationQueriesSchemes).\n *\n * @since 1.0.0\n */\n canOpenUrl(options: CanOpenURLOptions): Promise<CanOpenURLResult>;\n\n /**\n * Open an app with the given URL.\n * On iOS the URL should be a known URLScheme.\n * On Android the URL can be a known URLScheme or an app package name.\n *\n * @since 1.0.0\n */\n openUrl(options: OpenURLOptions): Promise<OpenURLResult>;\n}\n\nexport interface CanOpenURLOptions {\n url: string;\n}\n\nexport interface CanOpenURLResult {\n value: boolean;\n}\n\nexport interface OpenURLOptions {\n url: string;\n}\n\nexport interface OpenURLResult {\n completed: boolean;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface AppLauncherPlugin {\n /**\n * Check if an app can be opened with the given URL.\n *\n * On iOS you must declare the URL schemes you pass to this method by adding\n * the `LSApplicationQueriesSchemes` key to your app's `Info.plist` file.\n * Learn more about configuring\n * [`Info.plist`](https://capacitorjs.com/docs/ios/configuration#configuring-infoplist).\n *\n * This method always returns false for undeclared schemes, whether or not an\n * appropriate app is installed. To learn more about the key, see\n * [LSApplicationQueriesSchemes](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/plist/info/LSApplicationQueriesSchemes).\n *\n * On Android the URL can be a known URLScheme or an app package name.\n *\n * On [Android 11](https://developer.android.com/about/versions/11/privacy/package-visibility)\n * and newer you have to add the app package names or url schemes you want to query in the `AndroidManifest.xml`\n * inside the `queries` tag.\n *\n * @since 1.0.0\n */\n canOpenUrl(options: CanOpenURLOptions): Promise<CanOpenURLResult>;\n\n /**\n * Open an app with the given URL.\n * On iOS the URL should be a known URLScheme.\n * On Android the URL can be a known URLScheme or an app package name.\n *\n * @since 1.0.0\n */\n openUrl(options: OpenURLOptions): Promise<OpenURLResult>;\n}\n\nexport interface CanOpenURLOptions {\n url: string;\n}\n\nexport interface CanOpenURLResult {\n value: boolean;\n}\n\nexport interface OpenURLOptions {\n url: string;\n}\n\nexport interface OpenURLResult {\n completed: boolean;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/app-launcher",
3
- "version": "7.0.3",
3
+ "version": "7.0.4",
4
4
  "description": "The AppLauncher API allows to open other apps",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -81,5 +81,5 @@
81
81
  "publishConfig": {
82
82
  "access": "public"
83
83
  },
84
- "gitHead": "e492876ac85661078e39664652b01ac9e0ab08c7"
84
+ "gitHead": "8b8d7e5bc406a4ac00545131dcf4287a7964f208"
85
85
  }