微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

为什么我有这个错误
ERROR/AndroidRuntime(854): Uncaught handler: thread main exiting due to uncaught exception
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
ERROR/AndroidRuntime(854): Caused by: java.lang.classNotFoundException: com.android.GPS21.SmsReceiver in loader dalvik.system.PathClassLoader@43d02ef0

这是我的onReceive活动:

public void onReceive(Context context,Intent intent) {
  // Todo Auto-generated method stub
  Log.i(LOG_TAG,"Recieved a message");
  if (intent.getAction().equals(ACTION)) {
   // if(message starts with SMStretcher recognize BYTE)
   StringBuilder sb = new StringBuilder();

   // The SMS-Messages are 'hiding' within the extras of the Intent.
   Bundle bundle = intent.getExtras();
   if (bundle != null) {

    // Get all messages contained in the Intent
    // Telephony.Sms.Intents.getMessagesFromIntent(intent) does not
    // work anymore hence the below changes

    Object[] pduObj = (Object[]) bundle.get("pdus");
    SmsMessage[] messages = new SmsMessage[pduObj.length];
    for (int i = 0; i < pduObj.length; i++)
     messages[i] = SmsMessage.createFromPdu((byte[]) pduObj[i]);
    // Feed the StringBuilder with all Messages found.
    for (SmsMessage currentMessage : messages) {
     sb.append("SMS Received From: ");
     // Sender-Number
     sb.append(currentMessage.getdisplayOriginatingAddress());
     sb.append("\nMessage : ");
     // Actual Message-Content
     sb.append(currentMessage.getdisplayMessageBody());
    }
   }
   // Logger Debug-Output
   Log.i(LOG_TAG,"[SMSApp] onReceive: " + sb);

   // Show the Notification containing the Message.
   Toast.makeText(context,sb.toString(),Toast.LENGTH_LONG).show();
  }

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

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

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

解决方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐