|
1 | 1 | package org.scid.android;
|
2 | 2 |
|
3 |
| -import java.util.ArrayList; |
4 |
| -import java.util.List; |
5 |
| - |
6 | 3 | import android.app.Activity;
|
7 |
| -import android.content.ComponentName; |
8 | 4 | import android.content.Intent;
|
9 |
| -import android.content.pm.PackageManager; |
10 |
| -import android.content.pm.ResolveInfo; |
11 |
| -import android.os.Parcelable; |
12 | 5 |
|
13 | 6 | public class Sharer {
|
14 | 7 |
|
15 |
| - private ComponentName caller; |
16 | 8 | private Activity context;
|
17 | 9 | private Intent intent = null;
|
18 | 10 |
|
19 |
| - Sharer(Activity context, ComponentName caller) { |
| 11 | + Sharer(Activity context) { |
20 | 12 | this.context = context;
|
21 |
| - this.caller = caller; |
22 | 13 | }
|
23 | 14 |
|
24 | 15 | void createShareIntent(String type, String data) {
|
25 |
| - // put all possible intents into one list |
26 |
| - List<Intent> targets = getTargetIntentsForType(type, data, caller); |
27 |
| - if (!targets.isEmpty()) { |
28 |
| - List<Intent> extraTargets = getTargetIntentsForType("text/plain", |
29 |
| - data, caller); |
30 |
| - Intent firstIntent = targets.get(targets.size() - 1); |
31 |
| - Intent chooser = Intent.createChooser(firstIntent, context |
32 |
| - .getResources().getText(R.string.menu_share_game)); |
33 |
| - if (!extraTargets.isEmpty()) { |
34 |
| - // add all extra targets if they are not already in the list |
35 |
| - for (Intent extra : extraTargets) { |
36 |
| - boolean found = false; |
37 |
| - for (Intent target : targets) { |
38 |
| - if (target.getPackage().equals(extra.getPackage())) { |
39 |
| - found = true; |
40 |
| - break; |
41 |
| - } |
42 |
| - } |
43 |
| - if (!found) { |
44 |
| - targets.add(extra); |
45 |
| - } |
46 |
| - } |
47 |
| - targets.remove(firstIntent); |
48 |
| - chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, |
49 |
| - targets.toArray(new Parcelable[] {})); |
50 |
| - } |
51 |
| - this.intent = chooser; |
52 |
| - } else { |
53 |
| - Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); |
54 |
| - shareIntent.setType("text/plain"); |
55 |
| - shareIntent.putExtra(Intent.EXTRA_TEXT, data); |
56 |
| - this.intent = Intent.createChooser(shareIntent, context |
57 |
| - .getResources().getText(R.string.menu_share_game)); |
58 |
| - } |
59 |
| - } |
60 |
| - |
61 |
| - private List<Intent> getTargetIntentsForType(String type, String data, |
62 |
| - ComponentName caller) { |
63 |
| - PackageManager packageManager = this.context.getPackageManager(); |
64 | 16 | Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
|
65 | 17 | shareIntent.setType(type);
|
66 |
| - List<Intent> targetedShareIntents = new ArrayList<>(); |
67 |
| - List<ResolveInfo> resInfo = packageManager.queryIntentActivityOptions( |
68 |
| - caller, null, shareIntent, PackageManager.MATCH_DEFAULT_ONLY); |
69 |
| - for (ResolveInfo resolveInfo : resInfo) { |
70 |
| - Intent targetedShareIntent = new Intent(Intent.ACTION_SEND); |
71 |
| - targetedShareIntent.setType(type); |
72 |
| - targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, |
73 |
| - data); |
74 |
| - targetedShareIntent |
75 |
| - .setPackage(resolveInfo.activityInfo.packageName); |
76 |
| - targetedShareIntents.add(targetedShareIntent); |
77 |
| - } |
78 |
| - return targetedShareIntents; |
| 18 | + shareIntent.putExtra(Intent.EXTRA_TEXT, data); |
| 19 | + this.intent = Intent.createChooser(shareIntent, context |
| 20 | + .getResources().getText(R.string.menu_share_game)); |
79 | 21 | }
|
80 | 22 |
|
81 | 23 | public Intent getIntent() {
|
|
0 commit comments