嗨:)我正在用短信在android。我有问题与我的短信接收器类。当我第一次在模拟器上运行我的应用程序时,它可以正常工作,因为我已将它编程为工作。但是当我每次运行应用程序时,它都不起作用,因为我更新了它的工作。我被困在最后2天。有人可以指导我或提供一些帮助。我的基本的接收机类是:我更新的短信接收器不工作Android
public class SMSreceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
String Sender = null;
String str = "";
SmsMessage [] msgs = null;
if(bundle != null)
{
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int i=0;i<msgs.length;i++)
{
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
Sender = msgs[i].getOriginatingAddress();
str = "SMS From: " + msgs[i].getOriginatingAddress();
str += ":";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
//Toast.makeText(context, str, Toast.LENGTH_LONG).show();
Toast.makeText(context, Sender, Toast.LENGTH_LONG).show();
}
}
在上面的代码中,我曾经评论,显示了味精敬酒,并试图显示,显示发送者的号码敬酒。但它仍然显示新的味精文本。这很奇怪。
这里是我的清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pingpongsmsremote"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="12" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.pingpongsmsremote.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.pingpongsmsremote.SMSScheduler"
android:label="@string/title_activity_smsscheduler" >
</activity>
<activity
android:name="com.example.pingpongsmsremote.FilterSMS"
android:label="@string/title_activity_filter_sms" >
</activity>
<activity
android:name="com.example.pingpongsmsremote.SMSRemote"
android:label="@string/title_activity_smsremote" >
</activity>
<activity
android:name="com.example.pingpongsmsremote.SendSms"
android:label="@string/title_activity_send_sms" >
</activity>
</application>
</manifest>
你能告诉你在哪里注册的接收器?它是否在清单文件或活动中注册? – akhalsa 2013-05-03 13:52:10
@akhalsa是的,我gona编辑与清单我的问题文本。看看它 – Zeeshan 2013-05-03 13:56:49
@akhalsa我编辑我的问题与清单文件。你可以现在看看它,并告诉问题在哪里?谢谢:) – Zeeshan 2013-05-03 14:02:37