Skip to content

Commit 9a9752b

Browse files
authored
Real world example
1 parent fef49eb commit 9a9752b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,49 @@ There is `JavaObject` class with some internal methods for JNI access. For examp
7878
}
7979
```
8080

81+
## Real world example
82+
Assume you want to start sharing `Intent` and filter app to show. Easy:
83+
```csharp
84+
public static void Share(string body, string subject, string mimeType = "text/plain", string chooserTitle = "Choose application") {
85+
Intent intent = new Intent(Intent.ACTION_SEND);
86+
intent.SetType(mimeType)
87+
.PutExtra(Intent.EXTRA_SUBJECT, subject)
88+
.PutExtra(Intent.EXTRA_TEXT, body);
89+
90+
var intentList = new List<Intent>();
91+
92+
var activity = Internal.GetCurrentActivity();
93+
var pm = activity.GetPackageManager();
94+
var resInfo = pm.QueryIntentActivities(intent, 0);
95+
96+
97+
for (int i = 0; i < resInfo.Count; i++) {
98+
ResolveInfo ri = resInfo[i];
99+
string packageName = ri.ActivityInfo.GetPackageName();
100+
if (packageName.Contains("vkontakte") || packageName.Contains("instagram") || packageName.Contains("skype")) {
101+
Intent newIntent = new Intent(Intent.ACTION_SEND);
102+
newIntent.SetPackage(packageName)
103+
.PutExtra(Intent.EXTRA_SUBJECT, subject)
104+
.PutExtra(Intent.EXTRA_TEXT, body)
105+
.SetType(mimeType);
106+
107+
intentList.Add(newIntent);
108+
}
109+
}
110+
111+
Intent intentt = intentList[0];
112+
intentList.RemoveAt(0);
113+
Parcelable[] extraIntents = new Parcelable[intentList.Count];
114+
115+
for (int i = 0; i < intentList.Count; i++) {
116+
extraIntents[i] = intentList[i];
117+
}
118+
119+
var chooser = Intent.CreateChooser(intentt, chooserTitle);
120+
chooser.PutExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
121+
activity.StartActivity(chooser);
122+
}
123+
```
124+
81125
## P.S.
82126
There are not much you can do with this lib right now. But I'm going add new classes/methods from time to time.

0 commit comments

Comments
 (0)