2011-01-09 5 views
19

내 앱이 들어오는 SMS를 분석하여 차단하거나 다른 SMS 폴더로 이동할 수 있도록 Android에서 코딩 할 수 있습니까? SMS가 실제로 사용자에게 새로운 SMS를 알리는 알림을 표시하기 전에? Android 2.1 이상을 타겟팅합니다.Android에서 수신 SMS를 분석하는 방법은 무엇입니까?

들어오는 SMS를 사용자가 지정한 스팸 단어로 분석하고, 발견되면 다른 폴더로 메시지 읽기/이동으로 삭제하고 싶을 것입니다.

답변

24

은 내가 브로드 캐스트 리시버로,이 코드를 사용 :

public void onReceive(Context context, Intent intent) 
{ 
    //this stops notifications to others 
    this.abortBroadcast(); 

    //---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(); 
      from = msgs[i].getOriginatingAddress(); 
      str += " :"; 
      str += msgs[i].getMessageBody().toString(); 
      msg = msgs[i].getMessageBody().toString(); 
      str += "\n"; 
     } 
     if(checksomething){ 
      //make your actions 
      //and no alert notification and sms not in inbox 
     } 
     else{ 
      //continue the normal process of sms and will get alert and reaches inbox 
      this.clearAbortBroadcast(); 
     } 
    } 

하는 매니페스트에 추가하고받은 편지함으로 먼저 가서 경고 알림을 받게됩니다 방송 또는 SMS에 대한 higgest 우선 순위 (100)를 추가해야합니다.

<receiver android:name=".SmsReceiver"> 
     <intent-filter android:priority="100"> 
      <action android:name="android.provider.Telephony.SMS_RECEIVED"></action> 
     </intent-filter> 
    </receiver> 

희망이 있습니다.

0

음 유 트랩 들어오는 SMS 할 수있는,하지만 난 u는 통지를 차단 할 수 없습니다 생각 .....
u는 여기에 SMS를 삭제하려면이 ....
도움을 줄 수있는 스레드 How to delete an SMS from the inbox in Android programmatically?

+0

잘 안드로이드 내 응용 프로그램이 이미 들어오는 SMS를 처리하는 경우 기본 '새 메시지'알림을 표시하지 않아야합니다. 그래서 그것은 최고의 사용자 경험을위한 중요한 요구 사항입니다 : ( –

+0

잘 StackOverflow에 많은 스레드가 숨겨진 것들의 자신의 확장 클래스를 사용하지 않고 가능하지 않다는 것을 말할 것이다 .......하지만 네가 완 – viv

+1

이제는 abortBroadcast(); 메서드를 사용하여 들어오는 메시지를받은 편지함으로 이동하는 데 사용할 수 있습니다. – AB1209

0

이 코드는 2.3.3 장치에서 작동합니다. HTC MyTouch 4g 슬라이드. abortBroadcast는 상태 표시 줄의 notificationsound + 알림을 + 표시하지 않고 SMS를받은 편지함으로 이동합니다. 일부 사용자는 실제 장치에서는 작동하지 않으며 에뮬레이터에서만 작동한다고 언급했는데 항상 그런 것은 아닙니다. 우선 순위가 100이면이 특정 장치에서 코드가 예상대로 작동합니다.

관련 문제