@capawesome/capacitor-sms-composer 0.0.1
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/CapawesomeCapacitorSmsComposer.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +200 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/SmsComposer.java +52 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/SmsComposerPlugin.java +96 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/classes/CustomExceptions.java +9 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/classes/options/ComposeSmsOptions.java +45 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/classes/results/CanComposeSmsResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/classes/results/ComposeSmsResult.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +177 -0
- package/dist/esm/definitions.d.ts +92 -0
- package/dist/esm/definitions.js +13 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +6 -0
- package/dist/esm/web.js +10 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +37 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +40 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Options/ComposeSmsOptions.swift +12 -0
- package/ios/Plugin/Classes/Results/CanComposeSmsResult.swift +16 -0
- package/ios/Plugin/Classes/Results/ComposeSmsResult.swift +16 -0
- package/ios/Plugin/Enums/CustomError.swift +26 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/ios/Plugin/SmsComposer.swift +52 -0
- package/ios/Plugin/SmsComposerPlugin.swift +62 -0
- package/package.json +91 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapawesomeCapacitorSmsComposer'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robin Genz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapawesomeCapacitorSmsComposer",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapawesomeCapacitorSmsComposer",
|
|
10
|
+
targets: ["SmsComposerPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "SmsComposerPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Plugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "SmsComposerPluginTests",
|
|
25
|
+
dependencies: ["SmsComposerPlugin"],
|
|
26
|
+
path: "ios/PluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# @capawesome/capacitor-sms-composer
|
|
2
|
+
|
|
3
|
+
Capacitor plugin to open the native SMS composer prefilled with recipients and a message body.
|
|
4
|
+
|
|
5
|
+
<div class="capawesome-z29o10a">
|
|
6
|
+
<a href="https://cloud.capawesome.io/" target="_blank">
|
|
7
|
+
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
|
|
8
|
+
</a>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- ✉️ **Compose**: Open the native SMS composer prefilled with recipients and a message body.
|
|
14
|
+
- ✅ **Capability check**: Check whether the device is able to compose and send SMS messages.
|
|
15
|
+
- 🔒 **Privacy-friendly**: The user always reviews and sends the message. The plugin never sends SMS on its own.
|
|
16
|
+
- 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
|
|
17
|
+
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
18
|
+
|
|
19
|
+
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
20
|
+
|
|
21
|
+
## Newsletter
|
|
22
|
+
|
|
23
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
24
|
+
|
|
25
|
+
## Compatibility
|
|
26
|
+
|
|
27
|
+
| Plugin Version | Capacitor Version | Status |
|
|
28
|
+
| -------------- | ----------------- | -------------- |
|
|
29
|
+
| 0.x.x | >=8.x.x | Active support |
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
34
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Then use the following prompt:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-sms-composer` plugin in my project.
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install @capawesome/capacitor-sms-composer
|
|
50
|
+
npx cap sync
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This plugin is only available on **Android** and **iOS**. On Web, all methods reject as unimplemented.
|
|
54
|
+
|
|
55
|
+
### Android
|
|
56
|
+
|
|
57
|
+
No additional configuration is required. The plugin declares the necessary `<queries>` element for the `smsto` scheme in its `AndroidManifest.xml`, so the SMS capability can be detected on Android 11 (API level 30) and higher.
|
|
58
|
+
|
|
59
|
+
## Configuration
|
|
60
|
+
|
|
61
|
+
No configuration required for this plugin.
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { SmsComposer } from '@capawesome/capacitor-sms-composer';
|
|
67
|
+
|
|
68
|
+
const canComposeSms = async () => {
|
|
69
|
+
const { canCompose } = await SmsComposer.canComposeSms();
|
|
70
|
+
return canCompose;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const composeSms = async () => {
|
|
74
|
+
const { status } = await SmsComposer.composeSms({
|
|
75
|
+
recipients: ['+41791234567'],
|
|
76
|
+
body: 'Hello from Capacitor!',
|
|
77
|
+
});
|
|
78
|
+
return status;
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## API
|
|
83
|
+
|
|
84
|
+
<docgen-index>
|
|
85
|
+
|
|
86
|
+
* [`canComposeSms()`](#cancomposesms)
|
|
87
|
+
* [`composeSms(...)`](#composesms)
|
|
88
|
+
* [Interfaces](#interfaces)
|
|
89
|
+
* [Type Aliases](#type-aliases)
|
|
90
|
+
|
|
91
|
+
</docgen-index>
|
|
92
|
+
|
|
93
|
+
<docgen-api>
|
|
94
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
95
|
+
|
|
96
|
+
### canComposeSms()
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
canComposeSms() => Promise<CanComposeSmsResult>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Check whether the device is able to compose and send SMS messages.
|
|
103
|
+
|
|
104
|
+
On devices without SMS capability (e.g. Wi-Fi-only tablets or iPads),
|
|
105
|
+
this resolves with `canCompose` set to `false`.
|
|
106
|
+
|
|
107
|
+
Only available on Android and iOS.
|
|
108
|
+
|
|
109
|
+
**Returns:** <code>Promise<<a href="#cancomposesmsresult">CanComposeSmsResult</a>></code>
|
|
110
|
+
|
|
111
|
+
**Since:** 0.1.0
|
|
112
|
+
|
|
113
|
+
--------------------
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
### composeSms(...)
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
composeSms(options: ComposeSmsOptions) => Promise<ComposeSmsResult>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Open the native SMS composer prefilled with the given recipients and body.
|
|
123
|
+
|
|
124
|
+
The user reviews the message and decides whether to send it. The plugin
|
|
125
|
+
never sends the message itself.
|
|
126
|
+
|
|
127
|
+
The call resolves once the composer is dismissed. If the device is not
|
|
128
|
+
able to compose SMS messages, the call rejects as unavailable.
|
|
129
|
+
|
|
130
|
+
Only available on Android and iOS.
|
|
131
|
+
|
|
132
|
+
| Param | Type |
|
|
133
|
+
| ------------- | --------------------------------------------------------------- |
|
|
134
|
+
| **`options`** | <code><a href="#composesmsoptions">ComposeSmsOptions</a></code> |
|
|
135
|
+
|
|
136
|
+
**Returns:** <code>Promise<<a href="#composesmsresult">ComposeSmsResult</a>></code>
|
|
137
|
+
|
|
138
|
+
**Since:** 0.1.0
|
|
139
|
+
|
|
140
|
+
--------------------
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
### Interfaces
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
#### CanComposeSmsResult
|
|
147
|
+
|
|
148
|
+
| Prop | Type | Description | Since |
|
|
149
|
+
| ---------------- | -------------------- | ------------------------------------------------------------ | ----- |
|
|
150
|
+
| **`canCompose`** | <code>boolean</code> | Whether the device is able to compose and send SMS messages. | 0.1.0 |
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
#### ComposeSmsResult
|
|
154
|
+
|
|
155
|
+
| Prop | Type | Description | Since |
|
|
156
|
+
| ------------ | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
|
|
157
|
+
| **`status`** | <code><a href="#smscomposestatus">SmsComposeStatus</a></code> | The status of the SMS composer after it was dismissed. On Android, the status is always `unknown` because the system does not report whether the message was sent. | 0.1.0 |
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
#### ComposeSmsOptions
|
|
161
|
+
|
|
162
|
+
| Prop | Type | Description | Since |
|
|
163
|
+
| ---------------- | --------------------- | ---------------------------------------------------------- | ----- |
|
|
164
|
+
| **`body`** | <code>string</code> | The message body to prefill in the composer. | 0.1.0 |
|
|
165
|
+
| **`recipients`** | <code>string[]</code> | The recipients (phone numbers) to prefill in the composer. | 0.1.0 |
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
### Type Aliases
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
#### SmsComposeStatus
|
|
172
|
+
|
|
173
|
+
The status of the SMS composer after it was dismissed.
|
|
174
|
+
|
|
175
|
+
- `sent`: The user sent the message.
|
|
176
|
+
- `canceled`: The user canceled the composer without sending the message.
|
|
177
|
+
- `unknown`: The result is unknown. This is always the case on Android.
|
|
178
|
+
|
|
179
|
+
<code>'canceled' | 'sent' | 'unknown'</code>
|
|
180
|
+
|
|
181
|
+
</docgen-api>
|
|
182
|
+
|
|
183
|
+
## Result Status
|
|
184
|
+
|
|
185
|
+
The `composeSms(...)` method resolves with a `status` once the composer is dismissed:
|
|
186
|
+
|
|
187
|
+
- On **iOS**, the status reflects the actual outcome (`sent`, `canceled`).
|
|
188
|
+
- On **Android**, the status is always `unknown` because the system does not report whether the message was sent.
|
|
189
|
+
|
|
190
|
+
## Multiple Recipients
|
|
191
|
+
|
|
192
|
+
Multiple recipients are joined with a semicolon (`;`) in the underlying `smsto:` URI on Android. Some messaging apps expect a comma (`,`) instead, so multi-recipient prefilling may not work reliably across all Android messaging apps.
|
|
193
|
+
|
|
194
|
+
## Changelog
|
|
195
|
+
|
|
196
|
+
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/sms-composer/CHANGELOG.md).
|
|
197
|
+
|
|
198
|
+
## License
|
|
199
|
+
|
|
200
|
+
See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/sms-composer/LICENSE).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace = "io.capawesome.capacitorjs.plugins.smscomposer"
|
|
22
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError = false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.smscomposer;
|
|
2
|
+
|
|
3
|
+
import android.content.ActivityNotFoundException;
|
|
4
|
+
import android.content.Intent;
|
|
5
|
+
import android.net.Uri;
|
|
6
|
+
import android.text.TextUtils;
|
|
7
|
+
import androidx.annotation.NonNull;
|
|
8
|
+
import androidx.annotation.Nullable;
|
|
9
|
+
import io.capawesome.capacitorjs.plugins.smscomposer.classes.CustomExceptions;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.smscomposer.classes.options.ComposeSmsOptions;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.smscomposer.classes.results.ComposeSmsResult;
|
|
12
|
+
import io.capawesome.capacitorjs.plugins.smscomposer.interfaces.NonEmptyResultCallback;
|
|
13
|
+
import java.util.List;
|
|
14
|
+
|
|
15
|
+
public class SmsComposer {
|
|
16
|
+
|
|
17
|
+
public static final String STATUS_UNKNOWN = "unknown";
|
|
18
|
+
|
|
19
|
+
private final SmsComposerPlugin plugin;
|
|
20
|
+
|
|
21
|
+
public SmsComposer(@NonNull SmsComposerPlugin plugin) {
|
|
22
|
+
this.plugin = plugin;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public boolean canComposeSms() {
|
|
26
|
+
Intent intent = createSendToIntent(null);
|
|
27
|
+
return intent.resolveActivity(plugin.getContext().getPackageManager()) != null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public void composeSms(@NonNull ComposeSmsOptions options, @NonNull NonEmptyResultCallback<ComposeSmsResult> callback) {
|
|
31
|
+
Intent intent = createSendToIntent(options.getRecipients());
|
|
32
|
+
String body = options.getBody();
|
|
33
|
+
if (body != null) {
|
|
34
|
+
intent.putExtra("sms_body", body);
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
plugin.getActivity().startActivity(intent);
|
|
38
|
+
callback.success(new ComposeSmsResult(STATUS_UNKNOWN));
|
|
39
|
+
} catch (ActivityNotFoundException exception) {
|
|
40
|
+
callback.error(CustomExceptions.COMPOSE_FAILED);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@NonNull
|
|
45
|
+
private Intent createSendToIntent(@Nullable List<String> recipients) {
|
|
46
|
+
String uri = "smsto:";
|
|
47
|
+
if (recipients != null && !recipients.isEmpty()) {
|
|
48
|
+
uri += TextUtils.join(";", recipients);
|
|
49
|
+
}
|
|
50
|
+
return new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
|
|
51
|
+
}
|
|
52
|
+
}
|
package/android/src/main/java/io/capawesome/capacitorjs/plugins/smscomposer/SmsComposerPlugin.java
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.smscomposer;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.Logger;
|
|
6
|
+
import com.getcapacitor.Plugin;
|
|
7
|
+
import com.getcapacitor.PluginCall;
|
|
8
|
+
import com.getcapacitor.PluginMethod;
|
|
9
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.smscomposer.classes.CustomException;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.smscomposer.classes.options.ComposeSmsOptions;
|
|
12
|
+
import io.capawesome.capacitorjs.plugins.smscomposer.classes.results.CanComposeSmsResult;
|
|
13
|
+
import io.capawesome.capacitorjs.plugins.smscomposer.classes.results.ComposeSmsResult;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.smscomposer.interfaces.NonEmptyResultCallback;
|
|
15
|
+
import io.capawesome.capacitorjs.plugins.smscomposer.interfaces.Result;
|
|
16
|
+
|
|
17
|
+
@CapacitorPlugin(name = "SmsComposer")
|
|
18
|
+
public class SmsComposerPlugin extends Plugin {
|
|
19
|
+
|
|
20
|
+
public static final String ERROR_UNKNOWN_ERROR = "An unknown error has occurred.";
|
|
21
|
+
public static final String TAG = "SmsComposerPlugin";
|
|
22
|
+
|
|
23
|
+
private SmsComposer implementation;
|
|
24
|
+
|
|
25
|
+
@Override
|
|
26
|
+
public void load() {
|
|
27
|
+
super.load();
|
|
28
|
+
this.implementation = new SmsComposer(this);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@PluginMethod
|
|
32
|
+
public void canComposeSms(PluginCall call) {
|
|
33
|
+
try {
|
|
34
|
+
CanComposeSmsResult result = new CanComposeSmsResult(implementation.canComposeSms());
|
|
35
|
+
resolveCall(call, result);
|
|
36
|
+
} catch (Exception exception) {
|
|
37
|
+
rejectCall(call, exception);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@PluginMethod
|
|
42
|
+
public void composeSms(PluginCall call) {
|
|
43
|
+
try {
|
|
44
|
+
if (!implementation.canComposeSms()) {
|
|
45
|
+
rejectCallAsUnavailable(call);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
ComposeSmsOptions options = new ComposeSmsOptions(call);
|
|
50
|
+
NonEmptyResultCallback<ComposeSmsResult> callback = new NonEmptyResultCallback<>() {
|
|
51
|
+
@Override
|
|
52
|
+
public void success(@NonNull ComposeSmsResult result) {
|
|
53
|
+
resolveCall(call, result);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@Override
|
|
57
|
+
public void error(Exception exception) {
|
|
58
|
+
rejectCall(call, exception);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
implementation.composeSms(options, callback);
|
|
63
|
+
} catch (Exception exception) {
|
|
64
|
+
rejectCall(call, exception);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
|
|
69
|
+
String message = exception.getMessage();
|
|
70
|
+
if (message == null) {
|
|
71
|
+
message = ERROR_UNKNOWN_ERROR;
|
|
72
|
+
}
|
|
73
|
+
String code = null;
|
|
74
|
+
if (exception instanceof CustomException) {
|
|
75
|
+
code = ((CustomException) exception).getCode();
|
|
76
|
+
}
|
|
77
|
+
Logger.error(TAG, message, exception);
|
|
78
|
+
call.reject(message, code);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private void rejectCallAsUnavailable(@NonNull PluginCall call) {
|
|
82
|
+
call.unavailable("This method is not available on this platform.");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private void resolveCall(@NonNull PluginCall call) {
|
|
86
|
+
call.resolve();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
|
|
90
|
+
if (result == null) {
|
|
91
|
+
call.resolve();
|
|
92
|
+
} else {
|
|
93
|
+
call.resolve(result.toJSObject());
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.smscomposer.classes;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
public class CustomException extends Exception {
|
|
7
|
+
|
|
8
|
+
@Nullable
|
|
9
|
+
private final String code;
|
|
10
|
+
|
|
11
|
+
public CustomException(@Nullable String code, @NonNull String message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Nullable
|
|
17
|
+
public String getCode() {
|
|
18
|
+
return code;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.smscomposer.classes;
|
|
2
|
+
|
|
3
|
+
public class CustomExceptions {
|
|
4
|
+
|
|
5
|
+
public static final CustomException COMPOSE_FAILED = new CustomException(
|
|
6
|
+
"COMPOSE_FAILED",
|
|
7
|
+
"The SMS composer failed to compose or present the message."
|
|
8
|
+
);
|
|
9
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.smscomposer.classes.options;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.JSArray;
|
|
6
|
+
import com.getcapacitor.PluginCall;
|
|
7
|
+
import java.util.List;
|
|
8
|
+
import org.json.JSONException;
|
|
9
|
+
|
|
10
|
+
public class ComposeSmsOptions {
|
|
11
|
+
|
|
12
|
+
@Nullable
|
|
13
|
+
private final String body;
|
|
14
|
+
|
|
15
|
+
@Nullable
|
|
16
|
+
private final List<String> recipients;
|
|
17
|
+
|
|
18
|
+
public ComposeSmsOptions(@NonNull PluginCall call) {
|
|
19
|
+
this.recipients = getRecipientsFromCall(call);
|
|
20
|
+
this.body = call.getString("body");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Nullable
|
|
24
|
+
public String getBody() {
|
|
25
|
+
return body;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Nullable
|
|
29
|
+
public List<String> getRecipients() {
|
|
30
|
+
return recipients;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Nullable
|
|
34
|
+
private static List<String> getRecipientsFromCall(@NonNull PluginCall call) {
|
|
35
|
+
JSArray array = call.getArray("recipients");
|
|
36
|
+
if (array == null) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
return array.toList();
|
|
41
|
+
} catch (JSONException exception) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.smscomposer.classes.results;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import io.capawesome.capacitorjs.plugins.smscomposer.interfaces.Result;
|
|
6
|
+
|
|
7
|
+
public class CanComposeSmsResult implements Result {
|
|
8
|
+
|
|
9
|
+
private final boolean canCompose;
|
|
10
|
+
|
|
11
|
+
public CanComposeSmsResult(boolean canCompose) {
|
|
12
|
+
this.canCompose = canCompose;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Override
|
|
16
|
+
@NonNull
|
|
17
|
+
public JSObject toJSObject() {
|
|
18
|
+
JSObject result = new JSObject();
|
|
19
|
+
result.put("canCompose", canCompose);
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.smscomposer.classes.results;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import io.capawesome.capacitorjs.plugins.smscomposer.interfaces.Result;
|
|
6
|
+
|
|
7
|
+
public class ComposeSmsResult implements Result {
|
|
8
|
+
|
|
9
|
+
@NonNull
|
|
10
|
+
private final String status;
|
|
11
|
+
|
|
12
|
+
public ComposeSmsResult(@NonNull String status) {
|
|
13
|
+
this.status = status;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Override
|
|
17
|
+
@NonNull
|
|
18
|
+
public JSObject toJSObject() {
|
|
19
|
+
JSObject result = new JSObject();
|
|
20
|
+
result.put("status", status);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
File without changes
|