GVKun编程网logo

Android NotificationListenerService抛出DeadObjectException(android抛出异常)

12

在本文中,我们将给您介绍关于AndroidNotificationListenerService抛出DeadObjectException的详细内容,并且为您解答android抛出异常的相关问题,此外

在本文中,我们将给您介绍关于Android NotificationListenerService抛出DeadObjectException的详细内容,并且为您解答android抛出异常的相关问题,此外,我们还将为您提供关于Android 9-KeyStore异常android.os.ServiceSpecificException、Android accessibility service detect notification、Android getActiveNotifications抛出SecurityException、Android Robolectric – ContentProvider中queryBuilder.query()中的RuntimeException / InstantiationException的知识。

本文目录一览:

Android NotificationListenerService抛出DeadObjectException(android抛出异常)

Android NotificationListenerService抛出DeadObjectException(android抛出异常)

我有一个简单的NotificationListenerService实现来测试新的4.3 API.服务本身曾经工作过.之后,我添加了在添加特定包的通知时发送广播.现在,只要我启动该服务,它就会抛出一个DeadobjectException.这是堆栈跟踪:
E/NotificationService﹕ unable to notify listener (posted): android.service.notification.INotificationListener$Stub$Proxy@42c047a0
    android.os.DeadobjectException
    at android.os.BinderProxy.transact(Native Method)
    at android.service.notification.INotificationListener$Stub$Proxy.onNotificationPosted(INotificationListener.java:102)
    at com.android.server.notificationmanagerService$NotificationListenerInfo.notifyPostedIfUserMatch(notificationmanagerService.java:241)
    at com.android.server.notificationmanagerService$2.run(notificationmanagerService.java:814)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at com.android.server.ServerThread.run(SystemServer.java:1000)

这就是我启动服务的方式

@Override
public boolean onoptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_start_service:
            startService(new Intent(this,ConnectService.class));
            return true;
        default:
            return super.onoptionsItemSelected(item);
    }
}

我可以验证服务是否启动,因为我登录了onCreate()和onDestroy().
以下是如何处理通知发布的方式:

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    Log.i(TAG,sbn.getNotification().toString());
    if (sbn != null && sbn.getPackageName().equalsIgnoreCase(PKG)) {
        Intent intent = new Intent(ConnectService.NOTIFY);
        intent.putExtra("notification",sbn.getNotification().toString());
        bManager.sendbroadcast(intent);
    }
}

糟糕的是堆栈跟踪是没用的.出了什么问题?

解决方法

尽量不要自己启动服务.如果已在安全设置中启用NotificationListenerService,则系统应自动绑定到它.

或者,检查崩溃日志以查看服务是否崩溃或其进程是否已被终止.我相信有一个错误,如果您的NotificaitonListerService死亡,系统将不会重新绑定,直到您重新启动手机或在安全设置中切换通知权限.

Android 9-KeyStore异常android.os.ServiceSpecificException

Android 9-KeyStore异常android.os.ServiceSpecificException

如果我在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 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 getActiveNotifications抛出SecurityException

Android getActiveNotifications抛出SecurityException

我有一个监听通知的NotificationService类.但是,当我调用getActiveNotifications()时,它会抛出SecurityException.是的,我在调用此方法之前已经检查了许可.

我在NotificationService中使用AsyncTask来获取通知.代码如下.

private class AsyncProcessNotification extends AsyncTask<Void,Void,Void> {

        @Override
        protected Void doInBackground(Void... params) {
            int notificationType = MainApplication.settingNotificationType;
            MainApplication.clearNotificationItems();

            if (MainApplication.settingNotificationType == Constants.KEY_NOTIFICATION_TYPE_disABLED) {
                Log.i(TAG,"Notifications disabled");
                return null;
            }

            if (PermissionHelper.isNotificationPermissionGranted(getApplicationContext())) {
                if (getActiveNotifications() == null || getActiveNotifications().length == 0) {
                    Log.i(TAG,"No notifications found");
                    return null;
                }

                Log.i(TAG,"Getting " + getActiveNotifications().length +" notifications");
                Log.i(TAG,"Notification type  " + notificationType);
                for (StatusBarNotification statusBarNotification : getActiveNotifications()) {
                    // Process notifications
                }
            } else {
                //
            }

            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            Intent notify = new Intent(Constants.ACTION_NOTIFICATION_LISTENER);
            sendbroadcast(notify);
        }
    }

奇怪的是根据
Crashlytics,有时它在if(getActiveNotifications()== null || getActiveNotifications().length == 0)失败,有时它在Log.i失败(TAG,“获取”getActiveNotifications().length“notifications”);

要检查权限,我使用以下方法.

public static boolean isNotificationPermissionGranted(Context context) {
        Set<String> appList = notificationmanagerCompat.getEnabledListenerPackages(context);
        for (String l:appList) {
            if (l.equals(context.getPackageName())) {
                return true;
            }
        }

        return false;
    }

堆栈跟踪:

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:309)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)
Caused by java.lang.SecurityException: disallowed call from unkNown notification listener: android.service.notification.INotificationListener$Stub$Proxy@3e9880d
       at android.os.Parcel.readException(Parcel.java:1599)
       at android.os.Parcel.readException(Parcel.java:1552)
       at android.app.Inotificationmanager$Stub$Proxy.getActiveNotificationsFromListener(Inotificationmanager.java:1046)
       at android.service.notification.NotificationListenerService.getActiveNotifications(NotificationListenerService.java:467)
       at android.service.notification.NotificationListenerService.getActiveNotifications(NotificationListenerService.java:420)
       at com.afd.app.lockscreen.ios11.lib.service.NotificationService$AsyncProcessNotification.doInBackground(NotificationService.java:120)
       at com.afd.app.lockscreen.ios11.lib.service.NotificationService$AsyncProcessNotification.doInBackground(NotificationService.java:97)
       at android.os.AsyncTask$2.call(AsyncTask.java:295)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)

我知道我必须做一些愚蠢但却无法弄清楚是什么.有人可以帮忙吗?谢谢!

解决方法

I hit the same error in my notification listener service. I was able
to solve it by waiting for the listener service to get connected to the
notification manager before calling any of the
NotificationListenerService methods.

@Override
public void onListenerConnected() {
    Log.i(TAG,"Listener connected");
    listenerConnected = true;
}

private class AsyncProcessNotification extends AsyncTask<Void,Void> {
    protected Void doInBackground(Void... params) {
              ...
            // wait until our notification listener service is connected
            // to the notification manager
            Log.i(TAG,"Waiting for listener to be connected...");

            while(!listenerConnected);

            // Call getActiveNotifications after this
            for (StatusBarNotification sbn : getActiveNotifications()) {
                   processNotifications(sbn);
            }
    }

    // rest of the AsyncTask here
}

Android Robolectric – ContentProvider中queryBuilder.query()中的RuntimeException / InstantiationException

Android Robolectric – ContentProvider中queryBuilder.query()中的RuntimeException / InstantiationException

我在ContentProvider上进行了大约十次测试,只使用了sqlite; all pass保存在Content Provider的query()方法中通过queryBuilder.query()的两个.

正在测试的方法在实际应用中起作用!

这是API 17 r2和RoboLectric:
robolectric-2.0-α-3-20130417.013705-46-罐与 – dependencies.jar

@Override
public Cursor query(Uri uri,String[] projection,String selection,String[] selectionArgs,String sortOrder) {
    Log.d(Constants.TAG,"MyContentProvider.query()");
    switch(matcher.match(uri)) {
    case ITEM: // OK
        selection = "_id = ?";
        selectionArgs = new String[]{ Long.toString(ContentUris.parseId(uri)) };
    case ITEMS: // OK
        break;
    default:
        throw new IllegalArgumentException("Did not recognize URI " + uri);
    }
    // build the query with sqliteQueryBuilder
    sqliteQueryBuilder qBuilder = new sqliteQueryBuilder();
    qBuilder.setTables(TABLE_NAME);

    // query the database and get result in cursor
    final sqliteDatabase db = mDatabase.getReadableDatabase();
    Cursor resultCursor = qBuilder.query(db,// Line 112 in trace
            projection,selection,selectionArgs,null,sortOrder,null);
    resultCursor.setNotificationUri(getContext().getContentResolver(),uri);
    return resultCursor;
}

这是追溯:

java.lang.RuntimeException: java.lang.InstantiationException
    at org.robolectric.bytecode.ShadowWrangler.createShadowFor(ShadowWrangler.java:300)
    at org.robolectric.bytecode.ShadowWrangler.initializing(ShadowWrangler.java:74)
    at org.robolectric.bytecode.RobolectricInternals.initializing(RobolectricInternals.java:90)
    at android.database.sqlite.sqliteQuery.$$robo$init(sqliteQuery.java)
    at android.database.sqlite.sqliteClosable.<init>(sqliteClosable.java:26)
    at android.database.sqlite.sqliteProgram.<init>(sqliteProgram.java:41)
    at android.database.sqlite.sqliteQuery.<init>(sqliteQuery.java:37)
    at android.database.sqlite.sqliteDirectCursorDriver.query(sqliteDirectCursorDriver.java:44)
    at android.database.sqlite.sqliteDatabase.rawQueryWithFactory(sqliteDatabase.java:1314)
    at android.database.sqlite.sqliteQueryBuilder.query(sqliteQueryBuilder.java:400)
    at android.database.sqlite.sqliteQueryBuilder.query(sqliteQueryBuilder.java:333)
    at com.example.readingsprovider.ReadingsContentProvider.query(ReadingsContentProvider.java:112)
    at com.example.readingsprovider.test.ContentProviderTest.testUpdateMultipleWithoutWhere(ContentProviderTest.java:110)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:267)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runchild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runchild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runchildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:202)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.InstantiationException
    at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.class.newInstance0(Class.java:357)
    at java.lang.class.newInstance(Class.java:310)
    at org.robolectric.bytecode.ShadowWrangler.createShadowFor(ShadowWrangler.java:293)
    at org.robolectric.bytecode.ShadowWrangler.initializing(ShadowWrangler.java:74)
    at org.robolectric.bytecode.RobolectricInternals.initializing(RobolectricInternals.java:90)
    at android.database.sqlite.sqliteQuery.$$robo$init(sqliteQuery.java)
    at android.database.sqlite.sqliteClosable.<init>(sqliteClosable.java:26)
    at android.database.sqlite.sqliteProgram.<init>(sqliteProgram.java:41)
    at android.database.sqlite.sqliteQuery.<init>(sqliteQuery.java:37)
    at android.database.sqlite.sqliteDirectCursorDriver.$$robo$$sqliteDirectCursorDriver_7ac1_query(sqliteDirectCursorDriver.java:44)
    at android.database.sqlite.sqliteDirectCursorDriver.query(sqliteDirectCursorDriver.java)
    at android.database.sqlite.sqliteDatabase.$$robo$$sqliteDatabase_ab15_rawQueryWithFactory(sqliteDatabase.java:1314)
    at android.database.sqlite.sqliteDatabase.rawQueryWithFactory(sqliteDatabase.java)
    at android.database.sqlite.sqliteQueryBuilder.$$robo$$sqliteQueryBuilder_ba4d_query(sqliteQueryBuilder.java:400)
    at android.database.sqlite.sqliteQueryBuilder.query(sqliteQueryBuilder.java)
    at android.database.sqlite.sqliteQueryBuilder.$$robo$$sqliteQueryBuilder_ba4d_query(sqliteQueryBuilder.java:333)
    at android.database.sqlite.sqliteQueryBuilder.query(sqliteQueryBuilder.java)
    at com.example.readingsprovider.ReadingsContentProvider.query(ReadingsContentProvider.java:112)
    at com.example.readingsprovider.test.ContentProviderTest.testUpdateMultipleWithoutWhere(ContentProviderTest.java:110)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    ... 21 more

可以告诉我这是否是Robolectric的限制,还是我的不好?非常感谢!

附:如果Reflection API将失败的类名放在InstantiationException消息中,难道不是梦幻般的吗?

解决方法

我的项目有同样的问题,终于能够用一些谷歌搜索和U Avalos的前一个答案来解决它

1.创建自定义sqliteShadow

@Implements(value = sqliteDatabase.class,inheritImplementationMethods = true)
public class CustomsqliteShadow extends ShadowsqliteDatabase {

    @Implementation
    public Cursor rawQueryWithFactory (sqliteDatabase.CursorFactory cursorFactory,String sql,String editTable,CancellationSignal cancellationSignal) {
      return rawQueryWithFactory(cursorFactory,sql,editTable);
    }
}

2.将@Config注释添加到测试中

要使用自定义阴影类,可以在robolectric2中使用@Config注释

@RunWith(RobolectricTestRunner.class)
@Config( shadows = {CustomsqliteShadow.class})
public class ContentProviderTest {

参考

http://robolectric.blogspot.co.at/2013/05/configuring-robolectric-20.html

关于Android NotificationListenerService抛出DeadObjectExceptionandroid抛出异常的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Android 9-KeyStore异常android.os.ServiceSpecificException、Android accessibility service detect notification、Android getActiveNotifications抛出SecurityException、Android Robolectric – ContentProvider中queryBuilder.query()中的RuntimeException / InstantiationException等相关知识的信息别忘了在本站进行查找喔。

本文标签: