cordova-plugin-sms-retriever-manager 1.0.3 → 1.0.5
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/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "cordova-plugin-sms-retriever-manager",
|
3
|
-
"version": "1.0.
|
4
|
-
"description": "
|
3
|
+
"version": "1.0.5",
|
4
|
+
"description": "Easily retrieve SMS messages using the Google SMS Retriever API with our cross-platform plugin designed for Ionic/Cordova. This powerful tool streamlines the process and is specifically available for Android devices.",
|
5
5
|
"cordova": {
|
6
6
|
"id": "cordova-plugin-sms-retriever-manager",
|
7
7
|
"platforms": [
|
@@ -26,7 +26,7 @@
|
|
26
26
|
}
|
27
27
|
],
|
28
28
|
"author": "Haresh Hanat",
|
29
|
-
"license": "
|
29
|
+
"license": "MIT",
|
30
30
|
"bugs": {
|
31
31
|
"url": "https://github.com/hanatharesh2712/ionic-native-sms-retriever-plugin-master/issues"
|
32
32
|
},
|
package/plugin.xml
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
3
|
-
id="cordova-plugin-sms-retriever-manager" version="1.0.
|
4
|
-
<name>
|
5
|
-
<description>
|
3
|
+
id="cordova-plugin-sms-retriever-manager" version="1.0.5">
|
4
|
+
<name>Cordova SMS Retriver Plugin</name>
|
5
|
+
<description>Easily retrieve SMS messages using the Google SMS Retriever API with our cross-platform plugin designed for Ionic/Cordova. This powerful tool streamlines the process and is specifically available for Android devices.</description>
|
6
6
|
<license>MIT</license>
|
7
7
|
<keywords>ionic, ionic3, cordova, cordova-plugin, phonegap-plugin, ionic-framework, ionic-cordova, sms, sms-verificationm automatic SMS receive</keywords>
|
8
8
|
|
package/readme.md
CHANGED
@@ -29,62 +29,58 @@ HTML
|
|
29
29
|
Javascript
|
30
30
|
|
31
31
|
```js
|
32
|
-
|
33
32
|
document.querySelector('.hashCode').addEventListener('click', this.getAppHash);
|
34
33
|
document.querySelector('.startWatching').addEventListener('click', this.retriveSMS);
|
35
34
|
|
36
35
|
var app = {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
36
|
+
getAppHash: function() {
|
37
|
+
window['cordova']['plugins']['smsRetriever']['getAppHash'](
|
38
|
+
(result) => {
|
39
|
+
// Once you get this hash code of your app. Please remove this code.
|
40
|
+
alert(result);
|
41
|
+
console.log('Hash', result);
|
42
|
+
},
|
43
|
+
(err) => {
|
44
|
+
console.log(err);
|
45
|
+
});
|
46
|
+
},
|
47
|
+
|
48
|
+
retriveSMS: function() {
|
49
|
+
window['cordova']['plugins']['smsRetriever']['startWatching'](
|
50
|
+
// the first callback is the success callback. We got back the native code’s result here.
|
51
|
+
(result) => {
|
52
|
+
alert(result.Message);
|
53
|
+
console.log('Message', result);
|
54
|
+
},
|
55
|
+
// the second is the error callback where we get back the errors
|
56
|
+
(err) => {
|
57
|
+
console.log(err);
|
58
|
+
});
|
59
|
+
}
|
61
60
|
};
|
62
61
|
```
|
63
62
|
You can find working Demo for Ionic 4 here: https://github.com/hanatharesh2712/sms-plugin-test
|
64
63
|
|
65
64
|
Typescript (Ionic 4)
|
66
65
|
```typescript
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
constructor(private smsRetriever: SmsRetriever) { }
|
71
|
-
|
72
|
-
...
|
73
|
-
|
74
|
-
// This function is to get hash string of APP.
|
75
|
-
// * @return {Promise<string>} Returns a promise that resolves when successfully generate hash of APP.
|
76
|
-
this.smsRetriever.getAppHash()
|
77
|
-
.then((res: any) => console.log(res))
|
78
|
-
.catch((error: any) => console.error(error));
|
66
|
+
import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
|
79
67
|
|
68
|
+
constructor(private smsRetriever: SmsRetriever) { }
|
69
|
+
|
70
|
+
...
|
71
|
+
|
72
|
+
// This function is to get hash string of APP.
|
73
|
+
// * @return {Promise<string>} Returns a promise that resolves when successfully generate hash of APP.
|
74
|
+
this.smsRetriever.getAppHash()
|
75
|
+
.then((res: any) => console.log(res))
|
76
|
+
.catch((error: any) => console.error(error));
|
80
77
|
|
81
78
|
// * This function start wathching message arrive event and retrive message text.
|
82
79
|
// * @return {Promise<string>} Returns a promise that resolves when retrives SMS text or TIMEOUT after 5 min.
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
```
|
80
|
+
this.smsRetriever.startWatching()
|
81
|
+
.then((res: any) => console.log(res))
|
82
|
+
.catch((error: any) => console.error(error));
|
83
|
+
```
|
88
84
|
|
89
85
|
You can find working Demo for Ionic 3 here: https://github.com/hanatharesh2712/sms-plugin-test-ionic-3
|
90
86
|
|
@@ -93,37 +89,38 @@ You can find working Demo for Ionic 3 here: https://github.com/hanatharesh2712/s
|
|
93
89
|
|
94
90
|
import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
|
95
91
|
var smsRetriever = window['cordova']['plugins']['smsRetriever'];
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
92
|
+
|
93
|
+
public smsTextmessage: string = '';
|
94
|
+
public appHashString: string = '';
|
95
|
+
constructor(private smsRetriever: SmsRetriever) { }
|
96
|
+
|
97
|
+
...
|
98
|
+
|
99
|
+
getHashCode() {
|
100
|
+
smsRetriever['getAppHash'](
|
101
|
+
(res) => {
|
105
102
|
this.appHashString = res;
|
106
103
|
console.log(res);
|
107
104
|
}, (err) => {
|
108
105
|
console.warn(err);
|
109
106
|
}
|
110
|
-
|
111
|
-
|
107
|
+
);
|
108
|
+
}
|
112
109
|
|
113
|
-
|
114
|
-
|
110
|
+
getSMS() {
|
111
|
+
smsRetriever['startWatching'](
|
112
|
+
(res) => {
|
115
113
|
this.smsTextmessage = res.Message;
|
116
114
|
console.log(res);
|
117
115
|
}, (err) => {
|
118
116
|
console.warn(err);
|
119
117
|
}
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
Flow to test:
|
124
|
-
[](https://raw.githubusercontent.com/hanatharesh2712/automatic-sms-cordova/main/hello/res/ref-images/sms%20plugin%20demo.png)
|
118
|
+
);
|
119
|
+
}
|
120
|
+
```
|
125
121
|
|
126
|
-
|
122
|
+
Flow to test:
|
123
|
+
[](https://raw.githubusercontent.com/hanatharesh2712/automatic-sms-cordova/main/hello/res/ref-images/sms%20plugin%20demo.png)
|
127
124
|
|
128
125
|
You need to send your application hash in SMS when you are sending from your backend. to generate the hash of your application read this: https://developers.google.com/identity/sms-retriever/verify
|
129
126
|
|
@@ -132,9 +129,6 @@ To get your application hash code:
|
|
132
129
|
* Without the correct hash, your app won't recieve the message callback. This only needs to be
|
133
130
|
* generated once per app and stored. Then you can remove this function from your code.
|
134
131
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
132
|
BUILD FAILED
|
139
133
|
|
140
134
|
The problem is that you need to make sure that you set the target to android-19 or later in your ./platforms/android/project.properties file like this:
|
@@ -11,6 +11,7 @@ import android.content.BroadcastReceiver;
|
|
11
11
|
import android.content.Intent;
|
12
12
|
import android.content.IntentFilter;
|
13
13
|
import android.os.Bundle;
|
14
|
+
import android.os.Build;
|
14
15
|
import android.util.Log;
|
15
16
|
import android.widget.Toast;
|
16
17
|
|
@@ -30,6 +31,7 @@ import com.google.android.gms.tasks.Task;
|
|
30
31
|
import java.util.ArrayList;
|
31
32
|
|
32
33
|
import static com.google.android.gms.common.api.CommonStatusCodes.*;
|
34
|
+
import static android.content.Context.RECEIVER_EXPORTED;
|
33
35
|
|
34
36
|
import android.content.ContextWrapper;
|
35
37
|
import android.content.pm.PackageManager;
|
@@ -151,7 +153,12 @@ public class AndroidSmsRetriever extends CordovaPlugin {
|
|
151
153
|
|
152
154
|
IntentFilter intentFilter = new IntentFilter();
|
153
155
|
intentFilter.addAction(SmsRetriever.SMS_RETRIEVED_ACTION);
|
154
|
-
|
156
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
157
|
+
cordova.getActivity().getApplicationContext().registerReceiver(mMessageReceiver, intentFilter, RECEIVER_EXPORTED);
|
158
|
+
} else {
|
159
|
+
cordova.getActivity().getApplicationContext().registerReceiver(mMessageReceiver, intentFilter);
|
160
|
+
}
|
161
|
+
|
155
162
|
}
|
156
163
|
});
|
157
164
|
|
@@ -208,6 +215,7 @@ public class AndroidSmsRetriever extends CordovaPlugin {
|
|
208
215
|
case CommonStatusCodes.SUCCESS:
|
209
216
|
final String message = extra.getString(SmsRetriever.EXTRA_SMS_MESSAGE);
|
210
217
|
//if (!StringUtils.hasContent(message)) return;
|
218
|
+
if(message == null) return;
|
211
219
|
|
212
220
|
Log.d(TAG, message);
|
213
221
|
|
@@ -231,4 +239,4 @@ public class AndroidSmsRetriever extends CordovaPlugin {
|
|
231
239
|
}
|
232
240
|
};
|
233
241
|
};
|
234
|
-
}
|
242
|
+
}
|