0

我在使用许可库实施许可时遇到问题。我的代码似乎总是进入“检查网络访问”部分或“不允许”部分。我正在使用设置许可文章 ( http://developer.android.com/google/play/licensing/setting-up.html ) 中提到的方法进行测试。我在下面有我的代码的许可位,如果您需要查看其他内容,请告诉我。注意:大部分代码来自库附带的示例应用程序。

   public class Reminder_list extends ListActivity {

  Global variables ....

  private static final String BASE64_PUBLIC_KEY = "bla,bla,bla";

    // Generate your own 20 random bytes, and put them here.
    private static final byte[] SALT = new byte[] {
        -46, 65, 30, -118, -103, -57, 74, -14, 51, 88, -95, -45, 77, -17, -36, -113, -11, 32, -64,
        19
    };


    private LicenseCheckerCallback mLicenseCheckerCallback;
    private LicenseChecker mChecker;
    // A handler on the UI thread.
    private Handler mHandler;

   /** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 mHandler = new Handler();


    String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    // LicencingLibrary calls this when it's done.
    mLicenseCheckerCallback = new MyLicenseCheckerCallback();
    mChecker = new LicenseChecker(
     this, new ServerManagedPolicy(this,
                new AESObfuscator(SALT, getPackageName(), deviceId)),
            BASE64_PUBLIC_KEY);
      doCheck();

 ...
the rest of the stuff in the onCreate.
 ...
}

// this dialog is for the licence check.
 protected Dialog onCreateDialog(int id) {
        final boolean bRetry = id == 1;
        return new AlertDialog.Builder(this)
            .setTitle(R.string.unlicensed_dialog_title)
            .setMessage(bRetry ? R.string.unlicensed_dialog_retry_body : R.string.unlicensed_dialog_body)
            .setPositiveButton(bRetry ? R.string.retry_button : R.string.buy_button, new DialogInterface.OnClickListener() {
                boolean mRetry = bRetry;
                public void onClick(DialogInterface dialog, int which) {
                    if ( mRetry ) {
                        doCheck();
                    } else {
                        Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                "market:///details?id=" + getPackageName()));
                            startActivity(marketIntent);                        
                    }
                }
            })
            .setNegativeButton(R.string.quit_button, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            }).create();
    }


 // this is the actual method that called for the licence check.
 private void doCheck() {

        mChecker.checkAccess(mLicenseCheckerCallback);
    }

 // this is used to display the result of he licence check
 private void displayResult(final String result) {
        mHandler.post(new Runnable() {
            public void run() {
                Toast.makeText(getApplicationContext(), result ,Toast.LENGTH_SHORT).show();
            }
        });
    }


 // this shows the dialog if the licence check came back with a problem. Either the user did not pay for it or we did an error.
 private void displayDialog(final boolean showRetry) {
        mHandler.post(new Runnable() {
            @SuppressWarnings("deprecation")
            public void run() {

                showDialog(showRetry ? 1 : 0);//calls the dialog

            }
        });
    }    

...
...
the rest of the class

主类中的 LicenseCheckerCallback 类:

  // this is an internal class that should be inside the main activity that is used for   license checking. The licensing lib call this when 
 // it is done with checking the license 
 private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
        public void allow(int policyReason) {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // Should allow user access.
            displayResult(getString(R.string.allow));
        }

        public void dontAllow(int policyReason) {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            displayResult(getString(R.string.dont_allow));
            // Should not allow access. In most cases, the app should assume
            // the user has access unless it encounters this. If it does,
            // the app should inform the user of their unlicensed ways
            // and then either shut down the app or limit the user to a
            // restricted set of features.
            // In this example, we show a dialog that takes the user to Market.
            // If the reason for the lack of license is that the service is
            // unavailable or there is another problem, we display a
            // retry button on the dialog and a different message.
            displayDialog(policyReason == Policy.RETRY);
        }

        public void applicationError(int errorCode) {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // This is a polite way of saying the developer made a mistake
            // while setting up or calling the license checker library.
            // Please examine the error code and fix the error.
            String result = String.format(getString(R.string.application_error), errorCode);
            displayResult(result);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mChecker.onDestroy();
    }


 }

我正在使用 ServerManagedPolicy 。所以我没有更改库文件中的任何内容(我不必这样做吗?)。我确实在清单中有。

<uses-permission android:name="com.android.vending.CHECK_LICENSE" /> 

我无法弄清楚我做错了什么。所有这些都完全基于示例应用程序。

我的问题是:如何让许可证检查正常工作?注意:如果您打算投票,请告诉我原因。

感谢您花时间阅读本文以及您可以提供的任何帮助。

干杯。

4

0 回答 0