발신자가 누구냐에따라 액션이 발생하는 코드입니다.
전화중에 액션이 발생하게 되었는데, 이 리시버가 폰을 재부팅 하면
이게 중지되었습니다. 하는 대화상자가 나타납니다. 그러나 그 후에도 리시버 실행은 잘 됩니다.
제 생각엔 SharedPreferences가 문제인 것 같은데, 정확히 찾아내지 못하겠습니다..
고수님들 조언좀 부탁드리겠습니다!
public class MyReceiver extends BroadcastReceiver {
static String incomingNum;
int num = 0;
D_Diary parent;
Context context =null;
static String xml;
static String url;
static String NumberCheck;
static String phone_flag ="0"; //수신, 발신 구분 플래그
static String fff;
SharedPreferences pref;
SharedPreferences pref2;
public void onReceive(Context context, Intent intent){
this.context = context;
Bundle b =intent.getExtras();
pref = context.getSharedPreferences("flag", 0);
pref2 = context.getSharedPreferences("phoneflag", 0);
final String newState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if(newState.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
incomingNum = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
phone_flag = "1";
SharedPreferences.Editor editor = pref.edit();
SharedPreferences.Editor editor2 = pref2.edit();
editor.putString("flag",incomingNum);
editor2.putString("phoneflag",phone_flag);
editor.commit();
editor2.commit();
}
if(newState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
{
incomingNum = pref.getString("flag", "");
phone_flag = pref2.getString("phoneflag","");
if(phone_flag.equals("1")){
url = "http://rainbow-bridge.appspot.com/member?action=checkPhone" + "&phone=" + incomingNum;
xml = DownloadHtml(url);
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
SaxHandler handler = new SaxHandler();
reader.setContentHandler(handler);
InputStream istream = new ByteArrayInputStream(xml.getBytes("utf-8"));
reader.parse(new InputSource(istream));
NumberCheck = handler.result.toString();
}
catch (Exception e) {
}
if(NumberCheck.equals("failed"))
{
Intent intent4 = new Intent(context, Dialog.class);
intent4.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent4);
}
}
else{
return;
}
}
if(newState.equals(TelephonyManager.EXTRA_STATE_IDLE))
{
phone_flag = "0";
SharedPreferences.Editor editor = pref.edit();
SharedPreferences.Editor editor2 = pref2.edit();
editor.remove("flag");
editor.commit();
editor2.putString("phoneflag",phone_flag);
editor2.commit();
}
}