こんにちは:) AndroidでSMSを使用しています。SMS レシーバー クラスに問題があります。エミュレータで初めてアプリを実行すると、動作するようにプログラムしたとおりに動作します。しかし、アプリを再度実行するたびに、更新して機能するように機能しません。私は過去2日間立ち往生しています。誰かが私を案内したり、助けを提供してくれませんか。私の基本的なレシーバークラスは次のとおりです。
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>