3

所以我想制作一个加载了全部功能的免费应用程序。在应用程序检测到许可的专业密钥之前,专业功能将被禁用。当然,我想让 pro key 使用 LVL 检查它的许可证。虽然在此之前我知道如何正确地做事,但我不知道如何使 pro 密钥与应用程序通信,它应该启用 pro 功能。

这是主要的应用程序代码(com.test.mainapp):

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    context = getApplicationContext();

    final PackageManager pacman = getPackageManager();
    final int signatureMatch = pacman.checkSignatures(getPackageName(),
            "com.test.mainapp_key");

    if (signatureMatch == PackageManager.SIGNATURE_MATCH) {
        Toast.makeText(context, "Pro key detected!", Toast.LENGTH_SHORT)
                .show();
    } else {
        Toast.makeText(context, "Free version", Toast.LENGTH_SHORT).show();
    }
}

虽然这可以阻止其他人为我的应用程序制作假密钥,但他们仍然可以在线与其他人共享密钥应用程序并且它会起作用。因为我们不能从另一个应用程序进行 LVL 检查,所以我希望许可证密钥应用程序检查它自己的许可证,如果它是正确的,那么只有这样用户才能获得专业功能。我怎样才能让许可证密钥应用程序和主应用程序像这样相互通信?

例如,我试图在这里实现的功能就像 Titanium Backup 一样。

4

2 回答 2

10

您可以在主应用程序和关键应用程序之间发送意图。如果您在关键应用程序中使用 LVL,则示例回调将是:

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();
    }
}

您将在两个应用程序中设置广播接收器以启动许可证检查并处理结果。例如

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;
    }
}

} 

您应该使用基于证书的权限来限制对意图的访问,以防止其他应用程序能够发送欺骗性的“许可成功”意图。

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

简洁版本。

在清单中定义权限

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

在接收者声明中使用权限:

<receiver android:name="name.of.your.receiver" android:permission="my.package.LicenseCheck"> 
<intent-filter>
    <action android:name="name.of.intent"/>
</intent-filter>
</receiver>
于 2011-11-07T10:17:03.000 回答
1

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

创建 LvlValidationHandler.class,其中包含:

Intent i = new Intent("myapp.action.VALIDATION_RESPONSE");
sendBroadcast(i);
于 2012-09-05T06:42:48.750 回答