Licence check for a pro key

后端 未结 2 1483
暗喜
暗喜 2021-02-03 15:53

So I would like to make a free app with full functionality loaded in. The pro functionality will be disabled until the app detects a licensed pro key. And of course I would like

相关标签:
2条回答
  • 2021-02-03 16:33

    @MainApp

    <permission android:name="myapp.permission.RESPOND" protectionLevel="signature" />
    
    <receiver android:name=".receiver.WhichHandlesValidationResponse" android:permisssion="myapp.permission.RESPOND">
        <intent-filter>
                <action android:name="myapp.action.VALIDATION_RESPONSE" />
        </intent-filter>
    </receiver>
    

    @KeyApp

    <uses-permission android:name="myapp.permission.RESPOND" />
    

    Create LvlValidationHandler.class that contains:

    Intent i = new Intent("myapp.action.VALIDATION_RESPONSE");
    sendBroadcast(i);
    
    0 讨论(0)
  • 2021-02-03 16:38

    You can send intents between the main app and the key app. If you are using LVL in the key app then an example callback would be:

    private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
        public void allow() {
            Log.i("Key", "License Accepted");
            Intent i = new Intent();
            i.setAction("intent.to.call.on.success");
            i.putExtra("licenseresult", 0);
            c.sendBroadcast(i);
            mChecker.onDestroy();
        }
    
        public void dontAllow() {
            Log.e("Key", "License Denied");
            Intent i = new Intent();
            i.setAction("intent.to.call.on.failure");
            i.putExtra("licenseresult", 1);
            c.sendBroadcast(i);
            mChecker.onDestroy();
        }
    
        public void applicationError(ApplicationErrorCode errorCode) {
            Log.i("Key", "LR Error");
            Intent i = new Intent();
            i.setAction("intent.to.call.on.error");
            i.putExtra("licenseresult", 2);
            c.sendBroadcast(i);
            mChecker.onDestroy();
        }
    }
    

    You would set up broadcast receivers in both apps to initiate the license check and handle the result. e.g.

    public class License extends BroadcastReceiver {
    
    @Override
    public void onReceive(Context context, Intent intent) {
    
        if (intent.getAction().equals("intent.called.to.initiate.request")) {
                    // Initiate the license request here (possibly using a service)
            return;
        }
    }
    
    } 
    

    You should limit access to the intents using certificate based permissions to prevent other apps being able to send spoofed "License Success" intents.

    http://developer.android.com/reference/android/content/BroadcastReceiver.html#Permissions

    Short version.

    Define permission in manifest

    < permission android:name="my.package.LicenseCheck" android:protectionLevel="signature"/> 
    

    Use Permission in receiver declaration:

    <receiver android:name="name.of.your.receiver" android:permission="my.package.LicenseCheck"> 
    <intent-filter>
        <action android:name="name.of.intent"/>
    </intent-filter>
    </receiver>
    
    0 讨论(0)
提交回复
热议问题