Hướng dẫn các bước tích hợp AppRater vào dự án Cocos Creator cho Android:
A. Các bước chuẩn bị
Tải file AppRater.java tại đây: https://github.com/delight-im/AppRater
Copy file AppRater.java vào thư mục proj.android-studio/app/src/im/delight/apprater”
B. Thực hiện các thay đổi
1. proj.android-studio\app\src\org\cocos2dx\javascript\AppActivity.java
// AppRater import im.delight.apprater.AppRater; import com.workleast.GoMoTungKinh.R; public class AppActivity extends Cocos2dxActivity { private static AppActivity app = null; private static AppRater appRater = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // DO OTHER INITIALIZATION BELOW SDKWrapper.getInstance().init(this); app = this; ... // initialize AppRater appRater = new AppRater(this); // localize the messages appRater.setPhrases(getString(R.string.apprater_title),getString(R.string.apprater_explaination), getString(R.string.apprater_now), getString(R.string.apprater_later), getString(R.string.apprater_never)); appRater.show(); } // This function to be called from javascript (Cocos Creator project) public static void rateNow() { //we must use runOnUiThread here app.runOnUiThread(new Runnable() { @Override public void run() { appRater.demo(); } }); }
2. proj.android-studio\res\values\strings.xml
<string name="apprater_title" translatable="true">Rate this app</string> <string name="apprater_explaination" translatable="true">Find this app useful? Please take a minute to rate and share your thought to other people. Thank you so much for your support!</string> <string name="apprater_now" translatable="true">Rate</string> <string name="apprater_later" translatable="true">Later</string> <string name="apprater_never" translatable="true">No, thanks</string>
3. Trong file Scripts/Main.js file
... goRating: function() { // Only run on mobile if (cc.sys.os == cc.sys.OS_ANDROID) { jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "rateNow","()V"); } } ...