因此,我正在使用flutter进行应用程序开发(显然是标题),这是一款付费应用程序,因此需要验证许可证。我正在使用MedthodChannel来实现此目的,因为我无法自行解决。
现在的问题是: 因此,在Java方面,我正在检查许可证验证,然后将结果发送到flutter。这就是方法通道的工作方式。 但是问题在于,即使在验证完成之前,结果也会被发送到flutter,因此,哪个flutter部分认为许可证即使未通过验证也没有得到验证。
我在下面附加了Java辅助代码
package in.navkargems.diamondtools; import android.os.Bundle; import android.os.Handler; import android.provider.Settings; import android.util.Log; import com.google.android.vending.licensing.LicenseChecker; import com.google.android.vending.licensing.LicenseCheckerCallback; import com.google.android.vending.licensing.StrictPolicy; import io.flutter.app.FlutterActivity; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugins.GeneratedPluginRegistrant; public class MainActivity extends FlutterActivity { private static final String CHANNEL = "in.navkargems.diamondtools/verify"; private static final String _key_to_verify_base64 = "MIIBIjAN..."; private Handler mHandler; private LicenseChecker mChecker; private LicenseCheckerCallback mLicenseCheckerCallback; boolean licensed; boolean checkingLicense; boolean didCheck; int message = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); GeneratedPluginRegistrant.registerWith(this); new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler( new MethodChannel.MethodCallHandler() { @Override public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) { if (methodCall.method.equals("verifyLicense")) { String deviceId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); Log.i("Device Id", deviceId); mHandler = new Handler(); mLicenseCheckerCallback = new MyLicenseCheckerCallback(); mChecker = new LicenseChecker(getApplicationContext(), new StrictPolicy(), _key_to_verify_base64); doCheck(); Log.i("License", "Check : "+didCheck); if(didCheck){ result.success(licensed); } else{ result.success(false); } } } } ); } private void doCheck() { didCheck = false; checkingLicense = true; setProgressBarIndeterminateVisibility(true); mChecker.checkAccess(mLicenseCheckerCallback); } private class MyLicenseCheckerCallback implements LicenseCheckerCallback { @Override public void allow(int reason) { if(isFinishing()){ Log.i("License", ""+isFinishing()); return; } Log.i("License","Accepted!"); message = 1; licensed = true; checkingLicense = false; didCheck = true; } @Override public void dontAllow(int reason) { if(isFinishing()){ Log.i("License", ""+isFinishing()); return; } Log.i("License", "Reason : "+reason); message = 0; licensed = false; checkingLicense = false; didCheck = true; } @Override public void applicationError(int errorCode) { Log.i("License", "Error : "+errorCode); if(isFinishing()){ Log.i("License", ""+isFinishing()); return; } message = 0; licensed = true; checkingLicense = false; didCheck = false; } } }
谢谢您的时间。