2014-03-24 33 views
2

試圖使我的應用程序成爲默認的短信應用程序(因爲它需要在KitKat中)。 instructions是相當明確的,而不是點:是否有服務的任何示例處理ACTION_RESPONSE_VIA_MESSAGE

在服務,包括ACTION_RESPONSE_VIA_MESSAGE ( 「android.intent.action.RESPOND_VIA_MESSAGE」)的模式,短信:, smsto :,彩信:和意圖過濾器mmsto :.該服務還必須要求具有SEND_RESPOND_VIA_MESSAGE權限的 。

不能真正瞭解如何寫這個服務?我試圖關注Android來源,但目前尚不清楚。

任何人都可以指出我的好例子它是如何工作的?

回答

2

的短信應用,爲了這個目的註冊的例子:

protected void onHandleIntent(Intent intent) { 
     if (intent != null) { 
      if (TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) { 
       String num = intent.getDataString(); 
       num = num.replace("smsto:", "").replace("sms:", ""); 
       String msg = intent.getStringExtra(Intent.EXTRA_TEXT); 
       // send the data to via intent 
       Intent intentService = new Intent(this, SomeClass.class); 
       startService(intentService); 
      } 
     } 
    } 

通過SmsManeger發送味精 - smsManager.sendTextMessage(address, null, msg, piSent, piDelivered);

+0

嗯......什麼是SomeClass.java'Service'?不能真正理解它是如何工作的... – barmaley

+0

在我的情況下,SomeClass通過SmsManger.sendMessage發送該消息 –

+0

請給我看 - SomeClass.java - plz :) – barmaley

相關問題