Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 许可证检查库出现问题_Android - Fatal编程技术网

Android 许可证检查库出现问题

Android 许可证检查库出现问题,android,Android,我在使用授权库实现授权时遇到问题。我的代码似乎总是转到“检查网络访问”部分或“不允许”部分。我正在使用设置许可文章()中提到的方法进行测试。我有我的代码下面的许可位,让我知道如果你需要看到任何其他东西。 注意:此代码大部分来自库附带的示例应用程序 public class Reminder_list extends ListActivity { Global variables .... private static final String BASE64_PUBLIC_KEY

我在使用授权库实现授权时遇到问题。我的代码似乎总是转到“检查网络访问”部分或“不允许”部分。我正在使用设置许可文章()中提到的方法进行测试。我有我的代码下面的许可位,让我知道如果你需要看到任何其他东西。 注意:此代码大部分来自库附带的示例应用程序

   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" /> 

我不知道我做错了什么。所有这些都完全基于示例应用程序

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

感谢您抽出时间阅读此文章,并感谢您提供的任何帮助


干杯。

您好,您的清单中也有互联网权限吗?IAB不需要互联网权限,有一个单独的过程可以调解对Play Store的访问。是的,我有互联网。。。我的应用程序需要它,即使许可证检查没有。