我想通过twitter,facebook或设备上提供的其他方式分享短信.我写了下一个代码:
Intent share = new Intent(Intent.ACTION_SEND); share.putExtra(Intent.EXTRA_TEXT,"Here's some text for Twitter."); startActivity(Intent.createChooser(share,"Share this via"));
但是,如果没有可以执行此操作的应用程序,屏幕上会显示“无此类应用程序”对话框.如果找不到处理程序,我想检测这些应用程序并禁用此功能.我怎么能这样做?
解决方法
Intent intent = new Intent... PackageManager manager = mContext.getPackageManager(); List<ResolveInfo> list = manager.queryIntentActivities(intent,0); if (list != null && list.size() > 0) { //You have at least one activity to handle the intent } else { //No activity to handle the intent. }