에 수신 된 SMS를 추가하려면 어떻게 목록보기에서받은 메시지를 표시하려면 다음 코드가 있습니다ListView에
package com.example.smsTest;
import java.util.ArrayList;
import android.app.ListActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class SMSReceiverActivity extends ListActivity {
private BroadcastReceiver mIntentReceiver;
ListView listview;
ArrayAdapter<String> arrayAdpt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_smsreceiver);
listview=this.getListView();
}
@Override
protected void onResume() {
super.onResume();
IntentFilter intentFilter = new IntentFilter("SmsMessage.intent.MAIN");
mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String msg = intent.getStringExtra("get_msg");
//Process the sms format and extract body & phoneNumber
msg = msg.replace("\n", "");
String body = msg.substring(msg.lastIndexOf(":")+1, msg.length());
String pNumber = msg.substring(0,msg.lastIndexOf(":"));
//Add it to the list or do whatever you wish to
ArrayList<String> bodyarr=new ArrayList<String>();
bodyarr.add(body);
arrayAdpt = new ArrayAdapter<String>(SMSReceiverActivity.this, android.R.layout.simple_list_item_1,
bodyarr);
listview.setAdapter(arrayAdpt);
arrayAdpt.notifyDataSetChanged();
}
};
this.registerReceiver(mIntentReceiver, intentFilter);
}
@Override
protected void onPause() {
super.onPause();
this.unregisterReceiver(this.mIntentReceiver);
}
}
그러나, 문제는 덮어 쓰기 이전의 메시지입니다. 나는 쓸모없는 arrayAdpt.notifyDataSetChanged();
코드를 추가하려고했다.
여기도 많은 답변을 읽었지만 내 코드에서는 작동하지 않습니다.
도움주세요.
놀라운! 고마워요 ... 매력처럼 작동 ... – jaypabs
아무 문제 없어, 다행스럽게 도울 수있어! – mattgmg1990