Iir*_*kka 3 android android-lvl
所以我想制作一个加载了全部功能的免费应用程序.在应用程序检测到许可的专业密钥之前,专业版功能将被禁用.当然我想让pro key使用LVL检查它的许可证.虽然我知道如何在此之前做正确的事情,但我不知道如何使专业密钥与应用程序通信它应该启用专业功能.
这是主应用程序代码(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();
}
}
Run Code Online (Sandbox Code Playgroud)
虽然这会阻止其他人为我的应用程序制作假钥匙,但他们仍然可以在线共享关键应用程序,并且它可以正常工作.因为我们不能从另一个应用程序执行LVL检查,我希望许可证密钥应用程序检查它自己的许可证,如果它是正确的,那么只有用户才能获得专业功能.如何让许可证密钥应用程序与主应用程序相互通信?
我试图获得的功能就像Titanium Backup一样.
Kuf*_*ffs 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();
}
}
Run Code Online (Sandbox Code Playgroud)
您可以在两个应用程序中设置广播接收器以启动许可证检查并处理结果.例如
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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
您应该使用基于证书的权限来限制对意图的访问,以防止其他应用程序发送欺骗性的"许可证成功"意图.
http://developer.android.com/reference/android/content/BroadcastReceiver.html#Permissions
精简版.
在清单中定义权限
< permission android:name="my.package.LicenseCheck" android:protectionLevel="signature"/>
Run Code Online (Sandbox Code Playgroud)
在接收者声明中使用权限:
<receiver android:name="name.of.your.receiver" android:permission="my.package.LicenseCheck">
<intent-filter>
<action android:name="name.of.intent"/>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3721 次 |
| 最近记录: |