안드로이드 개발 질문/답변
(글 수 45,052)
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
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]);
str = msgs[i].getMessageBody().toString();
}
Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); //메세지 확인
/////////////////////////////////////////////////////////////////////////
if(str.equals(",")) // 이부분 문자 을 받으면 , " , " 이걸 포함하면 실행 아니면 종료
{
Intent i = new Intent(context, SaveText.class); //데이터를 넘겨주기위한 인텐트 설정
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("smsMessge", str); //데이터 저장
context.startActivity(i); // 액티브 실행
////////////////// SmsReceiver.clss 실행
PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_ONE_SHOT);
try {
pi.send();
} catch (CanceledException e) {
e.printStackTrace();
}
}
}
}
}메세지를 받았을때 특정 문자 가 있을시에 if 문을 돌리고싶은데요..
if(str.equals(",")) // 이부분 문자 을 받으면 , " , " 이걸 포함하면 실행 아니면 종료
이렇게 하니깐.. 조건문에 걸리지도 않고.. 그냥 실행해버리네요 ^^;;..
어찌 해야될까요. 아님 다른방법으로 해야하는지.. 답변좀 부탁드리겠습니다.




str.match('')를 써보셈