在本文中,我们将给您介绍关于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 9-KeyStore异常android.os.ServiceSpecificException
- Android accessibility service detect notification
- Android getActiveNotifications抛出SecurityException
- Android Robolectric – ContentProvider中queryBuilder.query()中的RuntimeException / InstantiationException
Android NotificationListenerService抛出DeadObjectException(android抛出异常)
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); } }
糟糕的是堆栈跟踪是没用的.出了什么问题?
解决方法
或者,检查崩溃日志以查看服务是否崩溃或其进程是否已被终止.我相信有一个错误,如果您的NotificaitonListerService死亡,系统将不会重新绑定,直到您重新启动手机或在安全设置中切换通知权限.
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
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:
NotificationService.java
Thanks for any help. ![]()
|
||||||||
|
|
2 Answers
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
res/xml/accessibilityservice.xml
There was an error in your feedbackType. Corrected below. Still, consider using a more specific feedback type. NotificationService.java
|
||||||
|
|


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
我在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
正在测试的方法在实际应用中起作用!
这是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消息中,难道不是梦幻般的吗?
解决方法
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抛出DeadObjectException和android抛出异常的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Android 9-KeyStore异常android.os.ServiceSpecificException、Android accessibility service detect notification、Android getActiveNotifications抛出SecurityException、Android Robolectric – ContentProvider中queryBuilder.query()中的RuntimeException / InstantiationException等相关知识的信息别忘了在本站进行查找喔。
本文标签: