考慮到2人擁有該應用程序。當其中一個用戶想知道另一個用戶的位置時,他發送一個短信(內容可以是任何或特定的)。現在當另一個用戶得到短信時(他不應該知道他收到了它)。然後他的位置被髮回給請求它的用戶。 希望解釋清楚。一個會在後臺運行的服務嗎?
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();
}
}
我得到了這段代碼......我應該在這裏做些什麼改變..?
:那麼您需要通過擴展服務類來創建服務有什麼問題? – 2012-04-06 08:13:47
我想創建一個始終運行的服務。並隨時檢查用戶的位置。你能幫我解碼嗎? – 2012-04-06 08:20:19