无法实例接收器BroadcastReceiver的短信 [英] Unable to instantiate receiver in BroadcastReceiver SMS

查看:153
本文介绍了无法实例接收器BroadcastReceiver的短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我有这样的错误:

Why I have this error :

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事件:

This is my onReceive events:

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()是错误。

In debug that onReceive() is error.

我只是做了BroadcastReceiver接收短信,并显示在通知吐司..

I just make BroadcastReceiver to receive SMS and show in notification Toast..

和我试着从DDMS发送短信和错误出现。

And I try send SMS from DDMS and that error appear..

推荐答案

您的清单要求你有一类名为 com.android.GPS21.SmsReceiver ,和Android无法找到吧。

Your manifest claims you have a class named com.android.GPS21.SmsReceiver, and Android cannot find it.

这篇关于无法实例接收器BroadcastReceiver的短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆