0

我希望我的应用程序在 facebook、Gmail、twitter 上共享文本后不会泄露

它工作正常,但应用程序冻结,我做了这个代码:

 public static void shareArticleUrl(Context fromActivity,String subject,String URL){


           List<Intent> targetedShareIntents = new ArrayList<Intent>();
            Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            List<ResolveInfo> resInfo = this.fromActivity.getPackageManager().queryIntentActivities(shareIntent, 0);
            if (!resInfo.isEmpty()){
                for (ResolveInfo resolveInfo : resInfo) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
                    targetedShareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    targetedShareIntent.setType("text/plain");
                    targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);

                    if (packageName.equals("com.facebook.katana")){
                         targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT,URL);
                    }
                    else{
                         targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "TEXT HERE");
                         }

                    targetedShareIntent.setPackage(packageName);
                    targetedShareIntents.add(targetedShareIntent);


                }
                Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(targetedShareIntents.size()-1), "Choose Application");
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));

                fromActivity.startActivity(chooserIntent);
            }
       }

我在其他活动中调用这个静态函数,我怎么了?

4

0 回答 0