Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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找不到它.

大佬总结

以上是大佬教程为你收集整理的android – 无法在BroadcastReceiver SMS中实例化接收器全部内容,希望文章能够帮你解决android – 无法在BroadcastReceiver SMS中实例化接收器所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。