从上一篇获取符合默认短信应用来看,获取思路是正确的,但是还很不完善,但是这归根结底是google整出来的一套规范,如何去找到符合规范的应用呢,这得google告诉我们。
因此,我看了一下android源码,关键是SmsApplication中的SmsApplicationData, 里面有个函数叫getApplicationCollection(Context context),这就是android4.4中系统用于获取符合默认短信应用要求的应用信息的代码,如下:
/**
* Returns the list of available SMS apps defined as apps that are registered for both the
* SMS_RECEIVED_ACTION (SMS) and WAP_PUSH_RECEIVED_ACTION (MMS) broadcasts (and their broadcast
* receivers are enabled)
*
* Requirements to be an SMS application:
* Implement SMS_DELIVER_ACTION broadcast receiver.
* Require BROADCAST_SMS permission.
*
* Implement WAP_PUSH_DELIVER_ACTION broadcast receiver.
* Require BROADCAST_WAP_PUSH permission.
*
* Implement RESPOND_VIA_MESSAGE intent.
* Support smsto Uri scheme.
* Require SEND_RESPOND_VIA_MESSAGE permission.
*
* Implement ACTION_SENDTO intent.
* Support smsto Uri scheme.
*/
public static Collection<SmsApplicationData> getApplicationCollection(Context context) {
PackageManager packageManager = cont