forked from valor-software/nativescript-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.android.ts
More file actions
41 lines (37 loc) · 1.55 KB
/
index.android.ts
File metadata and controls
41 lines (37 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Application, Utils } from '@nativescript/core';
import { InAppReviewCommon } from './common';
export class InAppReview extends InAppReviewCommon {
static requestReviewPopup() {
const context = Utils.android.getApplicationContext() as android.content.Context;
const manager = com.google.android.play.core.review.ReviewManagerFactory.create(context);
const request = manager.requestReviewFlow();
return new Promise<void>((resolve, reject) =>
request.addOnCompleteListener(
new com.google.android.gms.tasks.OnCompleteListener({
onComplete: (task) => {
if (!task.isSuccessful()) {
reject(new Error(task.getException()?.getMessage()));
return;
}
const reviewInfo = task.getResult();
const flow = manager.launchReviewFlow(Utils.android.getCurrentActivity(), reviewInfo);
flow.addOnCompleteListener(
new com.google.android.gms.tasks.OnCompleteListener({
onComplete: (task) => {
// The flow has finished. The API does not indicate whether the
// user reviewed or not, or even whether the review dialog was
// shown. Thus, no matter the result, we continue our app flow.
if (!task.isSuccessful()) {
reject(new Error(task.getException()?.getMessage()));
} else {
resolve();
}
},
})
);
},
})
)
);
}
}