您可以在主应用程序和关键应用程序之间发送意图。如果您在密钥应用程序中使用 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 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>