cordova-plugin-sms-retriever-manager 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cordova-plugin-sms-retriever-manager",
3
- "version": "1.0.2",
4
- "description": "Cross-platform plugin for Cordova / PhoneGap to to easily retrive SMS using Google SMS retriver API. Available for Android.",
3
+ "version": "1.0.4",
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": "DEV",
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.2">
4
- <name>Device</name>
5
- <description>Cordova SMS Retriver Plugin</description>
3
+ id="cordova-plugin-sms-retriever-manager" version="1.0.4">
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
@@ -17,107 +17,110 @@ It is also possible to install via repo url directly (unstable), run :
17
17
  ```sh
18
18
  ionic cordova plugin add https://github.com/hanatharesh2712/ionic-native-sms-retriever-plugin-master.git
19
19
  ```
20
-
20
+ You can find working Demo for Cordova here: https://github.com/hanatharesh2712/automatic-sms-cordova/tree/main/hello
21
21
  ## Using the plugin
22
22
  HTML
23
23
 
24
24
  ```html
25
- <input type="button" onclick="app.retriveSMS()" value="Read OTP from SMS" />
25
+ <input type="button" class="hashCode" value="Get App Hash" />
26
+ <input type="button" class="startWatching" value="Start watching SMS" />
26
27
  ```
27
28
 
28
29
  Javascript
29
30
 
30
31
  ```js
32
+ document.querySelector('.hashCode').addEventListener('click', this.getAppHash);
33
+ document.querySelector('.startWatching').addEventListener('click', this.retriveSMS);
34
+
31
35
  var app = {
32
- retriveSMS: function() {
33
- window['cordova']['plugins']['smsRetriever']['startWatching'](
34
- // the first callback is the success callback. We got back the native code’s result here.
35
- (result) => {
36
- console.log('Message', result);
37
- },
38
- // the second is the error callback where we get back the errors
39
- (err) => {
40
- console.log(err);
41
- }
42
- );
43
- }
44
- };
45
- ```
46
- ```js
47
- var app = {
48
- getAppHash: function() {
49
- window['cordova']['plugins']['smsRetriever']['getAppHash'](
50
- (result) => {
51
- // Once you get this hash code of your app. Please remove this code.
52
- console.log('Hash', result);
53
- },
54
- (err) => {
55
- console.log(err);
56
- }
57
- );
58
- }
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
+ }
59
60
  };
60
61
  ```
61
- You can fine working Demo for Ionic 4 here: https://github.com/hanatharesh2712/sms-plugin-test
62
+ You can find working Demo for Ionic 4 here: https://github.com/hanatharesh2712/sms-plugin-test
62
63
 
63
64
  Typescript (Ionic 4)
64
65
  ```typescript
65
- import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
66
-
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));
66
+ import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
67
+
68
+ constructor(private smsRetriever: SmsRetriever) { }
69
+
70
+ ...
77
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));
78
77
 
79
78
  // * This function start wathching message arrive event and retrive message text.
80
79
  // * @return {Promise<string>} Returns a promise that resolves when retrives SMS text or TIMEOUT after 5 min.
81
- this.smsRetriever.startWatching()
82
- .then((res: any) => console.log(res))
83
- .catch((error: any) => console.error(error));
84
-
85
- ```
80
+ this.smsRetriever.startWatching()
81
+ .then((res: any) => console.log(res))
82
+ .catch((error: any) => console.error(error));
83
+ ```
86
84
 
87
- You can fine working Demo for Ionic 3 here: https://github.com/hanatharesh2712/sms-plugin-test-ionic-3
85
+ You can find working Demo for Ionic 3 here: https://github.com/hanatharesh2712/sms-plugin-test-ionic-3
88
86
 
89
87
  Typescript (Ionic 3)
90
88
  ```typescript
91
89
 
92
90
  import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
93
91
  var smsRetriever = window['cordova']['plugins']['smsRetriever'];
94
-
95
- public smsTextmessage: string = '';
96
- public appHashString: string = '';
97
- constructor(private smsRetriever: SmsRetriever) { }
98
-
99
- ...
100
-
101
- getHashCode() {
102
- smsRetriever['getAppHash']((res) => {
92
+
93
+ public smsTextmessage: string = '';
94
+ public appHashString: string = '';
95
+ constructor(private smsRetriever: SmsRetriever) { }
96
+
97
+ ...
98
+
99
+ getHashCode() {
100
+ smsRetriever['getAppHash'](
101
+ (res) => {
103
102
  this.appHashString = res;
104
103
  console.log(res);
105
104
  }, (err) => {
106
105
  console.warn(err);
107
106
  }
108
- );
109
- }
107
+ );
108
+ }
110
109
 
111
- getSMS() {
112
- smsRetriever['startWatching']((res) => {
110
+ getSMS() {
111
+ smsRetriever['startWatching'](
112
+ (res) => {
113
113
  this.smsTextmessage = res.Message;
114
114
  console.log(res);
115
115
  }, (err) => {
116
116
  console.warn(err);
117
117
  }
118
- );
119
- }
120
- ```
118
+ );
119
+ }
120
+ ```
121
+
122
+ Flow to test:
123
+ [![flow](https://raw.githubusercontent.com/hanatharesh2712/automatic-sms-cordova/main/hello/res/ref-images/sms%20plugin%20demo.png)](https://raw.githubusercontent.com/hanatharesh2712/automatic-sms-cordova/main/hello/res/ref-images/sms%20plugin%20demo.png)
121
124
 
122
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
123
126
 
@@ -126,9 +129,6 @@ To get your application hash code:
126
129
  * Without the correct hash, your app won't recieve the message callback. This only needs to be
127
130
  * generated once per app and stored. Then you can remove this function from your code.
128
131
 
129
-
130
-
131
-
132
132
  BUILD FAILED
133
133
 
134
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:
@@ -197,7 +197,7 @@ Ask, or pick an issue and comment on it announcing your desire to work on it. Id
197
197
 
198
198
  ## License
199
199
 
200
- The DEV License (DEV)
200
+ The MIT License
201
201
 
202
202
  Permission is hereby granted, free of charge, to any person obtaining a copy of
203
203
  this software and associated documentation files (the "Software"), to deal in
@@ -11,7 +11,6 @@ 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.support.annotation.NonNull;
15
14
  import android.util.Log;
16
15
  import android.widget.Toast;
17
16
 
@@ -158,7 +157,7 @@ public class AndroidSmsRetriever extends CordovaPlugin {
158
157
 
159
158
  task.addOnFailureListener(new OnFailureListener() {
160
159
  @Override
161
- public void onFailure(@NonNull Exception e) {
160
+ public void onFailure(Exception e) {
162
161
  // Failed to start retriever, inspect Exception for more details
163
162
  LOG.v(TAG, "Executing action: addOnFailureListener");
164
163
  //Toast.makeText(cordova.getActivity().getApplicationContext(),"Executing action: addOnFailureListener", Toast.LENGTH_SHORT).show();
@@ -209,7 +208,8 @@ public class AndroidSmsRetriever extends CordovaPlugin {
209
208
  case CommonStatusCodes.SUCCESS:
210
209
  final String message = extra.getString(SmsRetriever.EXTRA_SMS_MESSAGE);
211
210
  //if (!StringUtils.hasContent(message)) return;
212
-
211
+ if(message == null) return;
212
+
213
213
  Log.d(TAG, message);
214
214
 
215
215
  data = new JSONObject();
@@ -232,4 +232,4 @@ public class AndroidSmsRetriever extends CordovaPlugin {
232
232
  }
233
233
  };
234
234
  };
235
- }
235
+ }