Android.security.KeyChainException: java.lang.IllegalStateException: uid

Mistake:

android.security.KeyChainException: java.lang.IllegalStateException: uid 10111 doesn't have permission to access the requested alias

code:

new Thread(new Runnable() {

        public void run() {
            try {
                X509Certificate[] myCertificates=KeyChain.getCertificateChain(MainActivity.this, "ServerCertificate");
                if(myCertificates!=null)
                {
                    System.out.println("myCertificates size "+myCertificates.length);

                    for(int i=0;i<myCertificates.length;i++)
                    {
                        System.out.println("myCertificates i= "+i+"    "+myCertificates[i]);
                    }
                }
            } catch (KeyChainException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }).start();
+1
source share
1 answer

The class KeyChainrequires the choosePrivateKeyAlias()application to call at least once after installing the application before calling getPrivateKey()or getCertificateChain(). Therefore, even if you know the alias in advance, it choosePrivateKeyAlias()must be called at least once, otherwise the trust relationship between the application and the internal database used KeyChaindoes not exist.

+6
source

All Articles