Skip to content

Commit 8dd9e17

Browse files
committed
add the first version of kivyreview
1 parent 3e67e11 commit 8dd9e17

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
11
# Kivy In-App-Review
2+
3+
This repository contains the information to integrate in app review using the Google Play Store API for Android applications developed with Kivy.
4+
5+
## License
6+
7+
This module is licensed under the Apache License version 2.0.
8+
9+
## Integration
10+
11+
> :warning: Warning
12+
> This module has only been tested for android API versions between 28 and 34. This might not work for older versions.
13+
14+
To integrate this module in your application you have to follow a few steps:
15+
16+
1. **Copy the code inside your folders** : You have to copy the `src` folder and the `kivyreview.py` file inside your own code arborescence. If you copy them at the root of your project, you can use directly the following instructions, if you prefer to rename the `src` folder or move the files somewhere else, do not forget to adapt the paths in the instructions to match the ones you used.
17+
18+
> :warning: Warning
19+
> Do not rename the `ReviewHandler.java` file unless you know what you are doing. You will need to adapt the java code in this case.
20+
21+
2. **Update your `buildozer.spec` file** : Some modifications needs to be done in the `buildozer.spec` file:
22+
23+
Search the line allowing to include gradle dependencies during compilation.
24+
25+
```
26+
# android.gradle_dependencies =
27+
```
28+
29+
It needs to be replaced by:
30+
31+
```
32+
ndroid.gradle_dependencies = com.google.android.play:core:1.10.0
33+
```
34+
35+
> :pencil: Note
36+
> If you already have other dependencies, just add a comma between them.
37+
38+
Search the line allowing to include additional java code in your application.
39+
40+
```
41+
# android.add_src =
42+
```
43+
44+
It needs to be replaced by:
45+
46+
```
47+
android.add_src = src
48+
```
49+
50+
3. **Call the `request_review` where yo need it** : You can now import the `request_review` function from the `kivyreview` module in your code and call it where you need it.
51+
52+
## Bugs and issues
53+
54+
If you encounter a problem or a bug during this procedure, please do not hesitate to raise an issue on this github repository.

kivyreview.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from kivy.utils import platform
2+
3+
4+
if platform == "android":
5+
from android import PythonJavaClass, autoclass, java_method, mActivity
6+
from android.runnable import run_on_ui_thread
7+
8+
context = mActivity.getApplicationContext()
9+
YourReviewHandler = autoclass('org.org.kivyreview.ReviewHandler')
10+
PythonActivity = autoclass('org.kivy.android.PythonActivity')
11+
12+
def request_review(*_):
13+
activity = PythonActivity.mActivity
14+
review_handler = YourReviewHandler(activity)
15+
review_handler.requestReview()
16+
else:
17+
def request_review(*_):
18+
print("In app review is only possible on android devices.")

src/ReviewHandler.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.org.kivyreview;
2+
3+
import android.app.Activity;
4+
import com.google.android.play.core.review.ReviewInfo;
5+
import com.google.android.play.core.review.ReviewManager;
6+
import com.google.android.play.core.tasks.Task;
7+
8+
public class ReviewHandler {
9+
10+
private Activity mActivity;
11+
private ReviewManager mReviewManager;
12+
13+
public ReviewHandler(Activity activity) {
14+
mActivity = activity;
15+
mReviewManager = com.google.android.play.core.review.ReviewManagerFactory.create(mActivity);
16+
}
17+
18+
public void requestReview() {
19+
Task<ReviewInfo> request = mReviewManager.requestReviewFlow();
20+
request.addOnCompleteListener(task -> {
21+
if (task.isSuccessful()) {
22+
ReviewInfo reviewInfo = task.getResult();
23+
launchReviewFlow(reviewInfo);
24+
} else {
25+
// Handle error when requesting review flow
26+
// For example, show a fallback review prompt
27+
showFallbackReviewPrompt();
28+
}
29+
});
30+
}
31+
32+
private void launchReviewFlow(ReviewInfo reviewInfo) {
33+
Task<Void> flow = mReviewManager.launchReviewFlow(mActivity, reviewInfo);
34+
flow.addOnCompleteListener(task -> {
35+
// Review flow launched, handle success or failure here
36+
// For example, log completion or show a thank you message
37+
});
38+
}
39+
40+
private void showFallbackReviewPrompt() {
41+
// Fallback mechanism to ask for user feedback or redirect to the Play Store for
42+
// review
43+
// You can implement a custom dialog or redirect the user to the app's Play
44+
// Store page
45+
}
46+
}

0 commit comments

Comments
 (0)