GVKun编程网logo

Android 9-KeyStore异常android.os.ServiceSpecificException(android出现错误)

23

在本文中,我们将给您介绍关于Android9-KeyStore异常android.os.ServiceSpecificException的详细内容,并且为您解答android出现错误的相关问题,此外,

在本文中,我们将给您介绍关于Android 9-KeyStore异常android.os.ServiceSpecificException的详细内容,并且为您解答android出现错误的相关问题,此外,我们还将为您提供关于android -------- java.net.UnknownServiceException、android --------System.err: java.net.UnknownServiceException: CLEARTEXT .....、Android accessibility service detect notification、Android In-App Billing Error InvalidKeySpecException的知识。

本文目录一览:

Android 9-KeyStore异常android.os.ServiceSpecificException(android出现错误)

Android 9-KeyStore异常android.os.ServiceSpecificException(android出现错误)

如果我在Android 9上运行此代码,则会收到以下异常:

private static KeyStore.PrivateKeyEntry getPrivateKeyEntry(String alias) {        try {            KeyStore ks = KeyStore                    .getInstance(SecurityConstants.KEYSTORE_PROVIDER_ANDROID_KEYSTORE);            ks.load(null);            KeyStore.Entry entry = ks.getEntry(alias, null);            if (entry == null) {                Log.w(TAG, "No key found under alias: " + alias);                Log.w(TAG, "Exiting signData()...");                return null;            }            if (!(entry instanceof KeyStore.PrivateKeyEntry)) {                Log.w(TAG, "Not an instance of a PrivateKeyEntry");                Log.w(TAG, "Exiting signData()...");                return null;            }            return (KeyStore.PrivateKeyEntry) entry;        } catch (Exception e) {            Log.e(TAG, e.getMessage(), e);            return null;        }    }

例外:

KeyStore异常android.os.ServiceSpecificException:(代码7)在android.os.Parcel.createException(Parcel.java:1956)在android.os.Parcel.readException(Parcel.java:1910)在android.os.Parcel.readException
(Parcel.java:1860)在android.security.IKeystoreService $ Stub $
Proxy.get(IKeystoreService.java:786)在android.security.KeyStore.get(KeyStore.java:195)在android.security.keystore.AndroidKeyStoreSpi。在com.phenodev.testenc.KeyStoreHelper.getPrivateKeyEntry(KeyStoreHelper
.java:151)com.phenodev.testenc.KeyStoreHelper.encrypt(KeyStoreHelper.java:173)。phenodev.testenc.KeyStoreEncryptor.encrypt(KeyStoreEncryptor.java:19)

请帮助修复它。

答案1

小编典典

终于我找到了解决方案。由于Android P (KeyStore.PrivateKeyEntry) keyStore.getEntry("alias",null)并不是获取私钥的正确方法,因此看起来。

我可以通过这种方式访问​​私钥/公钥来摆脱此警告

KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");keyStore.load(null);PrivateKey privateKey = (PrivateKey) keyStore.getKey("alias", null);PublicKey publicKey = keyStore.getCertificate("alias").getPublicKey();

android -------- java.net.UnknownServiceException

android -------- java.net.UnknownServiceException

 最近升级了Android的API版本时 ,导致我的网络请求失败了,

出现了这个错误 java.net.UnknownServiceException,

 

这个错误,我在网上查到这个主要是由于,我们的OkHttp3会默认使用密文传输,而我们的代码中使用Http协议,也就是使用明文传输,所以OkHttp3会主动的报错,然后阻止线程的运行。所以我们现在就是要修改配置文件,使OkHttp3允许使用明文传输,或者我们直接使用Https协议。

 

解决方法:

在 res 下新建一个 xml 目录,然后创建一个名为:network_security_config.xml 文件 

 

该文件内容如下:

 

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>

    <base-config cleartextTrafficPermitted="true" />

</network-security-config>

然后在 AndroidManifest.xml application 标签内应用上面的xml配置:
<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:networkSecurityConfig="@xml/network_security_config"
        android:theme="@style/AppTheme"
        >
</application>

 

这样就欧克了

官方文档: https://developer.android.com/training/articles/security-config

android --------System.err: java.net.UnknownServiceException: CLEARTEXT .....

android --------System.err: java.net.UnknownServiceException: CLEARTEXT .....

1,当调用远程接口进行网络通信时,报如下错误:

W/System.err: java.net.UnknownServiceException: 
CLEARTEXT communication to 10.240.35.113 not permitted by network security policy

这是因为新的保护机制对于仅使用安全通信的应用,Android 6.0 Marshmallow(API 级别 23)引入了两种机制来解决回退到明文通信的问题:(1) 在生产/安装库中,禁止明文通信,以及 (2) 在开发/QA 期间,在遇到任何非 TLS/SSL 通信时,予以记录或者触发崩溃。下文将更详细地介绍这两种机制。

2,解决方法:

如果一定要使用明文通信的话,则可以打开AndroidManifest.xml 文件,在 application 元素中添加:

android:usesCleartextTraffic=”true” 

备注:

1)为了安全,不建议上面的使用明文的通信方式,不过上面的这种方法可以作为一种临时的通信策略

2)如果声明不使用明文通信,则可以在application元素中添加:

android:usesCleartextTraffic=”false” 
 

此声明指示该应用不使用明文网络通信,并使 Android Marshmallow 的平台网络堆栈禁止该应用中的明文通信。例如,如果您的应用意外尝试通过 HTTP 明文请求登录用户,该请求将被阻止,该用户的身份和密码信息不会泄露到网络上。

另一种方式请看博客

 

android -------- java.net.UnknownServiceException

Android accessibility service detect notification

Android accessibility service detect notification

0 down vote favorite

I''m trying to make my app detect whenever a notification is displayed. I''ve enabled it in the settings app andonServiceConnecteddoes get called, however when I create a notification or receive an e-mail through the gmail app nothing happens,onAccessibilityEventdoes not get called.

Android manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test.slide" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission android:name="android.permission.GET_TASKS"/> <application android:label="Slide" android:icon="@drawable/ic_launcher" android:theme="@style/AppTheme"> <activity android:name=".Settings" android:label="Slide"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name=".Tools" android:label="Slide" android:theme="@android:style/Theme.Translucent.NoTitleBar"> </activity> <service android:name=".LocalService"/> <service android:name=".NotificationService" android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" android:label="Slide" android:enabled="true" android:exported="false"> <intent-filter> <action android:name="android.accessibilityservice.AccessibilityService"/> </intent-filter> </service> </application>

NotificationService.java

package com.test.slide; import android.accessibilityservice.AccessibilityService; import android.accessibilityservice.AccessibilityServiceInfo; import android.view.accessibility.AccessibilityEvent; public class NotificationService extends AccessibilityService { @Override public void onAccessibilityEvent(AccessibilityEvent event) { System.out.println("onAccessibilityEvent"); if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) { System.out.println("notification: " + event.getText()); } } @Override protected void onServiceConnected() { System.out.println("onServiceConnected"); AccessibilityServiceInfo info = new AccessibilityServiceInfo(); info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED; info.notificationTimeout = 100; info.feedbackType = AccessibilityEvent.TYPES_ALL_MASK; setServiceInfo(info); } @Override public void onInterrupt() { System.out.println("onInterrupt"); } }

Thanks for any help.

android notifications accessibility
share | improve this question
edited Sep 26 ''12 at 12:20

asked Sep 23 ''12 at 17:18
ng93
396 1 4 20


Did you found the solution? i have exactly the same problem. –  Daniel Martinus Sep 25 ''12 at 17:24

alanv''s answer worked for me –  ng93 Sep 26 ''12 at 12:29

For what system version are you programming? ICS? jelly bean? –  Daniel Martinus Sep 27 ''12 at 11:33

Jelly bean 4.1.1 –  ng93 Oct 1 ''12 at 14:56

2 Answers

active oldest votes
up vote 2 down vote accepted

Accessibility services in Android 4.0 and above can behave strangely if there is no accessibility-service meta-data tag defined in the manifest. Try defining the meta-data as in the examples below. You should continue to use setServiceInfo() to maintain backward compatibility with pre-4.0 devices.

Also, I would recommend specifying a feedback type that is specific to your service, rather than using "all".

AndroidManifest.xml

 <service . . . android:name=".NotificationService" android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" > <intent-filter> <action android:name="android.accessibilityservice.AccessibilityService" /> </intent-filter> <meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibilityservice" /> </service>

res/xml/accessibilityservice.xml

<?xml version="1.0" encoding="utf-8"?> <accessibility-service xmlns:android="http://schemas.android.com/apk/res/android" android:accessibilityEventTypes="typeNotificationStateChanged" android:accessibilityFeedbackType="feedbackAllMask" android:notificationTimeout="100" />

There was an error in your feedbackType. Corrected below. Still, consider using a more specific feedback type.

NotificationService.java

@Override protected void onServiceConnected() { AccessibilityServiceInfo info = new AccessibilityServiceInfo(); info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED; info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK; info.notificationTimeout = 100; setServiceInfo(info); }
share | improve this answer
edited Sep 24 ''12 at 8:37

answered Sep 24 ''12 at 1:33
alanv
442 1 10


Now you are defining theserviceInfoin XML and code. You may leave out the code part of AccessibilityServiceInfo because the xml is defined in the manifest. –  Daniel Martinus Sep 24 ''12 at 5:57
1  
On the contrary, you must define it in both places for compatibility with pre-ICS devices. –  alanv Sep 24 ''12 at 8:01
up vote 1 down vote

The app using AccessibilityService needed to have a permission from settings>Accessibility in order to access the system events. Allow permission from settings . This may work

check this link

accessibility service is not started

Android In-App Billing Error InvalidKeySpecException

Android In-App Billing Error InvalidKeySpecException

我正在尝试使用Trivial Gas教程的包装器来实现应用程序内购买.成功购买完成后应用程序崩溃,从那时起应用程序开始崩溃.

java.lang.IllegalArgumentException: java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D07209B:asn1 encoding routines:ASN1_get_object:too long
at com.nightowl.memory.Security.generatePublicKey(Security.java:85)
at com.nightowl.memory.Security.verifyPurchase(Security.java:65)
at com.nightowl.memory.IabHelper.queryPurchases(IabHelper.java:875)
at com.nightowl.memory.IabHelper.queryInventory(IabHelper.java:550)
at com.nightowl.memory.IabHelper.queryInventory(IabHelper.java:528)
at com.nightowl.memory.IabHelper$2.run(IabHelper.java:623)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D07209B:asn1 encoding routines:ASN1_get_object:too long
at com.android.org.conscrypt.OpenSSLKey.getPublicKey(OpenSSLKey.java:101)
at com.android.org.conscrypt.OpenSSlrsAKeyFactory.engineGeneratePublic(OpenSSlrsAKeyFactory.java:47)
at java.security.KeyFactory.generatePublic(KeyFactory.java:171)
at com.nightowl.memory.Security.generatePublicKey(Security.java:80)
... 6 more
Caused by: java.lang.RuntimeException: error:0D07209B:asn1 encoding routines:ASN1_get_object:too long
at com.android.org.conscrypt.NativeCrypto.d2i_PUBKEY(Native Method)
at com.android.org.conscrypt.OpenSSLKey.getPublicKey(OpenSSLKey.java:99)
... 9 more

我使用以下代码来调用它:

String base64EncodedPublicKey;
            base64EncodedPublicKey= String.valueOf(R.string.myPubKey);
            additionalSkuList = new ArrayList<String>();
            for(int i=0;i<3;i++)
            {
                for(int j=0;j<4;j++)
                {
                    if(i==0&&j>1)
                        break;
                    additionalSkuList.add(id[i][j]);
                }
            }
            mHelper = new IabHelper(this,base64EncodedPublicKey);
            mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
                public void onIabSetupFinished(IabResult result) {
                    Log.d("main","m here");
                    if (!result.isSuccess()) {
                        // Oh noes,there was a problem.
                        Log.d("main","Problem setting up in-app Billing: " + result);
                    }
                    // Hooray,IAB is fully set up!
                    isIAB = true;

                    mHelper.queryInventoryAsync(true,additionalSkuList,mQueryFinishedListener);
                    Log.d("main","" + isIAB + " " + isLoad);
                }
            });


IabHelper.QueryInventoryFinishedListener
            mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result,Inventory inventory)
        {
            Log.d("main","m here too");
            if (result.isFailure()) {
                // handle error
                return;
            }
            for(int i=0;i<3;i++)
            {
                for(int j=0;j<4;j++)
                {
                    if(i==0&&j>1)
                        break;
                    price[i][j]=inventory.getSkuDetails(id[i][j]).getPrice();
                }
            }
            isLoad=true;
            data.setPrice(price);
            data.setDataLoad(true);
            // update the UI
        }
    };

    public void onPurchaseCall()
    {
        int loc[] = data.getItem();
        mHelper.launchPurchaseFlow(this,id[loc[0]][loc[1]],100*loc[0]+loc[1],mpurchaseFinishedListener,id[loc[0]][loc[1]]);
    }
    IabHelper.OnIabPurchaseFinishedListener mpurchaseFinishedListener
            = new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result,Purchase purchase)
        {
            if (result.isFailure()) {
                Log.d("main","Error purchasing: " + result);
                return;
            }
            else if (purchase.getSku().equals(id[0][0])) {
                data.setNoads(1);
                mAdView.setVisibility(View.INVISIBLE);
                data.setNotificationState(1);
                data.setNoOfnotifications(2);
                data.setNotificationMsg(0,"Purchase Complete");
                data.setNotificationMsg(1,PurchaseMsg[0]);
                // consume the gas and update the UI
            }


        }
    };

任何人都可以帮我解决吗?我从日志中猜到的是我提供的公钥存在问题.但它第一次起作用(直到我成功购买才开始工作).我还得到了所有应用内商品的价目表.

我试图用测试帐户测试购买.成功完成购买后出现此错误,从那时起该应用程序未针对该帐户运行.

解决方法

不要使用String.valueOf(R.string.myPubKey),它会给你一个错误的值.而是使用getResources().getString(R.string.myPubKey_data))来获取您的公钥字符串.

关于Android 9-KeyStore异常android.os.ServiceSpecificExceptionandroid出现错误的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于android -------- java.net.UnknownServiceException、android --------System.err: java.net.UnknownServiceException: CLEARTEXT .....、Android accessibility service detect notification、Android In-App Billing Error InvalidKeySpecException等相关内容,可以在本站寻找。

本文标签: