2010-08-22 96 views

回答

0

对于Android,答案是否定的。您可以实现一个BroadcastReceiver,该设备在设备收到SMS文本消息但无法让其他应用程序(例如内置消息传送应用程序)也无法接收它们时被调用。

1

在Android中,您可以做的是注册BroadcastReceiver,以通知已收到SMS,将该消息标记为已在SMS Content Provider中读取,然后从内容提供者中删除该特定消息。这会阻止任何其他应用程序在删除该消息后才能够阅读该消息,并且通知空间中不会显示任何通知。也就是说,我不知道接收Intent的应用程序会发生什么情况,表明收到了一条消息,但无法在数据库中访问它。这可能会导致不可预知的行为,由于一些竞争条件。

0

在Android中,一旦你在你的应用程序接收短信,你可以使用一个Intent对象的消息的细节传递给作进一步处理其他活动/应用。如果您需要将消息传递给您自己的应用程序,请使用sendBroadcast()方法广播Intent对象。在你的活动中,你只需要使用registerReceiver()方法来监听广播。

希望它有帮助! 李伟明

1

是的。这是可能的Android。我正在开发一个应用程序。 你需要做的是:

public class SMSService extends BroadcastReceiver { 
public static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED"; 
private String phoneNumber; 
private String sms; 
private Context context; 

@Override 
public void onReceive(Context context, Intent intent) { 
    this.context = context; 
    if (intent.getAction().equals(SMS_RECEIVED)) { 
     Bundle bundle = intent.getExtras(); 
     SmsMessage[] msgs = null; 

     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]); 

       // get sms message 
       sms = msgs[i].getMessageBody(); 

       // get phone number 
       phoneNumber = msgs[i].getOriginatingAddress(); 

       if (phoneNumber.equals("Some other phone number")){ 
        // the sms will not reach normal sms app 
        abortBroadcast(); 

       Thread thread = new Thread(null, 
         doBackgroundThreadProcessing, "Background"); 
       thread.start(); 
       } 

      } 
     } 
    } 
} 

private Runnable doBackgroundThreadProcessing = new Runnable() { 
    // do whatever you want 
}; 

重要: 清单文件,你必须有大量的短信定义优先级。我相信最大值为100.

<!-- SMS Service --> 
    <service android:name=".SMSService" /> 
    <receiver android:name=".SMSService"> 
     <intent-filter android:priority="100"> 
      <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
     </intent-filter> 
    </receiver> 
+0

android:priority的最大值为1000.请参见:http://developer.android.com/guide/topics/manifest/intent-filter-element.html – 2013-08-16 12:04:16