How to get default application for an action

后端 未结 2 1038
没有蜡笔的小新
没有蜡笔的小新 2021-01-21 23:45

How can I determine which application is the default application for a certain action? For example I want to know which application is used for making calls or receiving text me

2条回答
  •  遇见更好的自我
    2021-01-22 00:06

    Use Intent Filters and resolveActivity().

    From Android's documentation on Intent Filters:

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage);
    sendIntent.setType(HTTP.PLAIN_TEXT_TYPE); // "text/plain" MIME type
    
    ComponentName compName = sendIntent.resolveActivity();
    

    And here's the documentation on ComponentName

提交回复
热议问题