• Android分享中, 过滤指定的应用,已经过滤蓝牙, 并且对不同的分享方式发送不同的内容?


                String contentDetails = "朋友快来玩 ***游戏把";                     
                        
                        Intent intent = new Intent(Intent.ACTION_SEND);  //  启动分享发送的属性
                        intent.setType("text/plain");
                        intent.setType("image/*");     //分享图片信息类型
                        List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(intent, 0);
                        
                        if(!resInfo.isEmpty()){
                            List<Intent>targetedShareIntents =  new ArrayList<Intent>();
                            for(ResolveInfo info :resInfo){
                                Intent targeted = new Intent(Intent.ACTION_SEND);
                                intent.setType("image/*");     //分享图片信息类型
                                targeted.setType("text/plain");
                                ActivityInfo activityInfo = info.activityInfo;
                                
                                if(activityInfo.packageName.contains("bluetooth")||
                                        activityInfo.name.contains("bluetooth")){
                                    continue;        //过滤蓝牙应用
                                } 
                                if(activityInfo.packageName.contains("com.my.activity")||
                                        activityInfo.name.contains("com.my.activity")){
                                    continue;      //过滤自己的应用包
                                }
                                if(activityInfo.packageName.contains("gm")||
                                        activityInfo.name.contains("mail")){
                                    targeted.putExtra(Intent.EXTRA_TEXT, contentDetails);
                                }else if(activityInfo.packageName.contains("zxing")){
                                    targeted.putExtra(Intent.EXTRA_TEXT, contentDetails);
                                }else{
                                    targeted.putExtra(Intent.EXTRA_TEXT, contentDetails);
                                }
                                targeted.setPackage(activityInfo.packageName);
                                targetedShareIntents.add(targeted);
                            }
                            //分享框标题
                            Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0),"选择程序分享");
                            if(chooserIntent == null){
                                return;
                            }
                            
                            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, 
                                    targetedShareIntents.toArray(new Parcelable[]{}));
                            try{
                                startActivity(chooserIntent);
                            }catch(android.content.ActivityNotFoundException ex){
                                 Toast.makeText(Activity_AboutMe.this, "没找到分享的应用", Toast.LENGTH_SHORT).show();                         
                            }                                       
                        }
  • 相关阅读:
    Java Math 取整的方式
    Java final 关键词修饰类、方法、变量
    Android Activity 开发常用技巧整理
    Java override 和 overload 的区别
    Android TextView 常用技巧
    Android Adb 常用命令
    Android 实现应用升级方案(暨第三方自动升级服务无法使用后的解决方案)
    Git 常用命令
    Android 常见Crash Log汇总
    Java Annotation 总结
  • 原文地址:https://www.cnblogs.com/firecode/p/2686884.html
Copyright © 2020-2023  润新知