안드로이드 프로그래밍에 익숙하지 않아 문제를 해결하는 데 도움이됩니다.Android SMS 수신기가 작동하지 않음
SMS를 수신하는 코드가 작동하지 않습니다. 자바 코드
package com.android.SMS;
import android.os.Bundle;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.*;
import android.telephony.gsm.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class SMSReceiver extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
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]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
}
}
이 문제를 해결 도와주세요하면서
매니페스트 파일은
<receiver android:name=".SMSReceiver">
<intent-filter>
<action android:name=
"android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.SEND_SMS">
</uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
입니다. 나는 어제부터 이것에 집착하고 있으며 코드에 어떤 문제도 보지 못했습니다.
"작동하지 않는다"는 의미에 대해 좀 더 구체적으로 설명해 주실 수 있습니까? 예외가 발생합니까? logcat 출력에 오류/경고가 있습니까? –
에뮬레이터에서 테스트 중이십니까? – Azlam
나는 비슷한 것을하고있다 !!! http://stackoverflow.com/questions/14452808/sending-and-receiving-mms-in-android – toobsco42