我正在尝试检测何时安装新的应用程序但仅在我的应用程序正在运行时.我设法通过制作BroadcastReceiver并在AndroidManifest文件中激活它来检测应用程序的安装,但即使我的应用程序已关闭,这也会检测到.这就是为什么我需要手动激活和停用broadcastreveiver.要做到这一点,我有这个代码:
br = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.i("Enter", "Enters here");
Toast.makeText(context, "App Installed!!!!.", Toast.LENGTH_LONG).show();
}
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
registerReceiver(br, intentFilter);
Run Code Online (Sandbox Code Playgroud)
这应该在安装新应用程序时举杯.但遗憾的是,事实并非如此.它不会进入onReceive方法.任何帮助表示赞赏.
我有一个应用程序,提供安装CA证书的选项,它存储在可信凭据的用户选项卡中,它按预期工作.
仅供参考 (这是我安装证书的方式):
Intent installIntent = KeyChain.createInstallIntent();
javax.security.cert.X509Certificate x509 = javax.security.cert.X509Certificate.getInstance(caRootCertBytes);
installIntent.putExtra(KeyChain.EXTRA_CERTIFICATE, x509.getEncoded());
installIntent.putExtra(KeyChain.EXTRA_NAME,caRootCertName);
startActivity(installIntent);
Run Code Online (Sandbox Code Playgroud)
如果卸载了应用程序,则证书仍保留在受信任的凭据中.
我希望在卸载应用程序时卸载证书.
我想过使用deleteEntry方法删除证书KeyStore.
仅供参考 (我没有测试过.希望它能够正常工作......我测试后会更新)
javax.security.cert.X509Certificate x509 = javax.security.cert.X509Certificate.getInstance(caRootCertBytes);
KeyStore ks = KeyStore.getInstance("AndroidCAStore")
if (ks != null)
{
ks.load(null, null);
Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements())
{
String alias = (String) aliases.nextElement();
java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate) ks.getCertificate(alias);
String name = x509.getIssuerDN().getName();
if (cert.getIssuerDN().getName().contains(name))
{
ks. deleteEntry(alias)
}
}
}
Run Code Online (Sandbox Code Playgroud)
即使你考虑上面的代码工作AFAIK我无法注册广播接收器卸载我自己的应用程序.
在卸载我的应用程序时,如何删除我的应用程序安装的证书?
任何帮助表示赞赏!