是否有任何处理ACTION_RESPONSE_VIA_MESSAGE的服务示例

时间:2014-03-24 13:09:13

标签: android android-intent sms intentservice

尝试将我的应用设为默认短信应用(在KitKat中需要)。 instructions非常清楚,而不是指出:

  

在服务中,包括ACTION_RESPONSE_VIA_MESSAGE的意图过滤器   (" android.intent.action.RESPOND_VIA_MESSAGE")with schemas,sms:,   smsto:,mms:和mmsto:。这项服务还必须要求   SEND_RESPOND_VIA_MESSAGE权限。

真的不懂如何编写此服务吗?我试图关注Android来源,但目前还不清楚。

任何人都能指出我的好榜样吗?

1 个答案:

答案 0 :(得分: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);