android – 无法在BroadcastReceiver SMS中实例化接收器

前端之家收集整理的这篇文章主要介绍了android – 无法在BroadcastReceiver SMS中实例化接收器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么我有这个错误
  1. ERROR/AndroidRuntime(854): Uncaught handler: thread main exiting due to uncaught exception
  2. ERROR/AndroidRuntime(854): java.lang.RuntimeException: Unable to instantiate receiver com.android.GPS21.SmsReceiver: java.lang.ClassNotFoundException: com.android.GPS21.SmsReceiver in loader dalvik.system.PathClassLoader@43d02ef0
  3. ERROR/AndroidRuntime(854): Caused by: java.lang.ClassNotFoundException: com.android.GPS21.SmsReceiver in loader dalvik.system.PathClassLoader@43d02ef0

这是我的onReceive活动:

  1. public void onReceive(Context context,Intent intent) {
  2. // TODO Auto-generated method stub
  3. Log.i(LOG_TAG,"Recieved a message");
  4. if (intent.getAction().equals(ACTION)) {
  5. // if(message starts with SMStretcher recognize BYTE)
  6. StringBuilder sb = new StringBuilder();
  7.  
  8. // The SMS-Messages are 'hiding' within the extras of the Intent.
  9. Bundle bundle = intent.getExtras();
  10. if (bundle != null) {
  11.  
  12. // Get all messages contained in the Intent
  13. // Telephony.Sms.Intents.getMessagesFromIntent(intent) does not
  14. // work anymore hence the below changes
  15.  
  16. Object[] pduObj = (Object[]) bundle.get("pdus");
  17. SmsMessage[] messages = new SmsMessage[pduObj.length];
  18. for (int i = 0; i < pduObj.length; i++)
  19. messages[i] = SmsMessage.createFromPdu((byte[]) pduObj[i]);
  20. // Feed the StringBuilder with all Messages found.
  21. for (SmsMessage currentMessage : messages) {
  22. sb.append("SMS Received From: ");
  23. // Sender-Number
  24. sb.append(currentMessage.getDisplayOriginatingAddress());
  25. sb.append("\nMessage : ");
  26. // Actual Message-Content
  27. sb.append(currentMessage.getDisplayMessageBody());
  28. }
  29. }
  30. // Logger Debug-Output
  31. Log.i(LOG_TAG,"[SMSApp] onReceive: " + sb);
  32.  
  33. // Show the Notification containing the Message.
  34. Toast.makeText(context,sb.toString(),Toast.LENGTH_LONG).show();
  35. }

在调试中,onReceive()是错误的.

我只是让BroadcastReceiver收到短信,并通知Toast ..

我尝试从DDMS发送短信,出现错误.

解决方法

你的清单声称你有一个名为com.android.GPS21.SmsReceiver的类,Android找不到它.

猜你在找的Android相关文章