private void Mail2() { SA_ScreenUtil.TakeScreenshot((screenshot) => { AN_Intent sendIntent = new AN_Intent(); sendIntent.SetAction(AN_Intent.ACTION_SEND_MULTIPLE); sendIntent.PutExtra(AN_Intent.EXTRA_TEXT, "This is my text to send."); sendIntent.SetType(AN_MIMEDataType.Image); sendIntent.PutExtra(AN_Intent.EXTRA_EMAIL, "*****@*****.**", "*****@*****.**"); sendIntent.PutExtra(AN_Intent.EXTRA_TEXT, "EXTRA_TEXT2"); sendIntent.PutExtra(AN_Intent.EXTRA_SUBJECT, "EXTRA_SUBJECT2s"); var list = new List <Texture2D>() { screenshot, screenshot }; sendIntent.PutExtra(AN_Intent.EXTRA_STREAM, list.ToArray()); AN_Intent chooser = AN_Intent.CreateChooser(sendIntent, "My chooser title"); AN_ProxyActivity proxy = new AN_ProxyActivity(); proxy.StartActivityForResult(chooser, (result) => { Debug.Log("Unity: Activity Result: " + result.ResultCode.ToString()); proxy.Finish(); }); }); }
protected AN_Intent GenerateChooserIntent(string title, params string[] filters) { if (filters.Length == 0) { return(AN_Intent.CreateChooser(ShareIntent, title)); } //Simple intent to get list of the apps that can support the send action var testIntent = new AN_Intent(); testIntent.SetAction(AN_Intent.ACTION_SEND); testIntent.SetType("text/plain"); var pm = AN_MainActivity.Instance.GetPackageManager(); var resolveInfoList = pm.QueryIntentActivities(testIntent); var intentShareList = new List <AN_Intent>(); foreach (var resInfo in resolveInfoList) { var packageName = resInfo.ActivityInfo.PackageName; foreach (var filterPattern in filters) { if (resInfo.ActivityInfo.PackageName.ToLower().Contains(filterPattern) || resInfo.ActivityInfo.Name.ToLower().Contains(filterPattern)) { //TODO do we need full data or only package name var intent = new AN_Intent(ShareIntent); intent.SetPackage(packageName); intentShareList.Add(intent); break; } } } if (intentShareList.Count == 0) { //we can't find packages for a provided filters, so we will use standard chooser string filterList = ""; foreach (var f in filters) { filterList += f + ";"; } AN_Logger.Log("Wasn't able to find packages for filters: " + filterList); return(AN_Intent.CreateChooser(ShareIntent, title)); } else { AN_Logger.Log("Chooser created with options count: " + intentShareList.Count); //if we have only 1 option there is no point to create hole chooser UI. Let's just use this option if (intentShareList.Count == 1) { return(intentShareList[0]); } return(AN_Intent.CreateChooser(ShareIntent, title, intentShareList.ToArray())); } }
public override void Test() { //Package Info string packageName = UnityEngine.Application.identifier; var pm = AN_MainActivity.Instance.GetPackageManager(); AN_PackageInfo packageInfo = pm.GetPackageInfo(packageName, 0); AN_Logger.Log("packageInfo.VersionName: " + packageInfo.VersionName); AN_Logger.Log("packageInfo.PackageName: " + packageInfo.PackageName); AN_Logger.Log("packageInfo.SharedUserId: " + packageInfo.SharedUserId); //Query Intent Activities TEST //Simple intent to get list of the apps that can support the send action AN_Intent testIntent = new AN_Intent(); testIntent.SetAction(AN_Intent.ACTION_SEND); testIntent.SetType("text/plain"); List <AN_ResolveInfo> resolveInfoList = pm.QueryIntentActivities(testIntent, 0); foreach (var resolveInfo in resolveInfoList) { AN_Logger.Log("resolveInfo.ActivityInfo.Name: " + resolveInfo.ActivityInfo.Name); AN_Logger.Log("resolveInfo.ActivityInfo.PackageName: " + resolveInfo.ActivityInfo.PackageName); } ///Open External App AN_Intent startAppIntent = pm.GetLaunchIntentForPackage("com.facebook.katana"); if (startAppIntent == null) { SetResult(SA_TestResult.WithError("App with Id: com.facebook.katana not found on device")); return; } startAppIntent.AddCategory(AN_Intent.CATEGORY_LAUNCHER); /* * AN_ProxyActivity proxy = new AN_ProxyActivity(); * bool started = proxy.StartActivityForResult(startAppIntent, (result) => { * SetResult(TestResult.OK); * proxy.Finish(); * }); * * if(!started) { * SetResult(TestResult.GetError("Failed to create activity")); * }*/ SetResult(SA_TestResult.OK); }
private void Mail() { AN_Intent sendIntent = new AN_Intent(); sendIntent.SetAction(AN_Intent.ACTION_SEND); sendIntent.PutExtra(AN_Intent.EXTRA_TEXT, "This is my text to send."); sendIntent.SetType("text/plain"); sendIntent.SetAction(AN_MIMEDataType.Image); sendIntent.PutExtra(AN_Intent.EXTRA_EMAIL, "*****@*****.**", "*****@*****.**"); sendIntent.PutExtra(AN_Intent.EXTRA_TEXT, "EXTRA_TEXT2"); sendIntent.PutExtra(AN_Intent.EXTRA_SUBJECT, "EXTRA_SUBJECT2s"); AN_Intent chooser = AN_Intent.CreateChooser(sendIntent, "My chooser title"); AN_ProxyActivity proxy = new AN_ProxyActivity(); proxy.StartActivityForResult(chooser, (result) => { Debug.Log("Unity: Activity Result: " + result.ResultCode.ToString()); proxy.Finish(); }); }
public void ShareWithMe() { #if UNITY_ANDROID AN_Intent sendIntent = new AN_Intent(); sendIntent.SetAction(AN_Intent.ACTION_SEND); sendIntent.PutExtra(AN_Intent.EXTRA_TEXT, "Welcome to Lime Crime https://www.limecrime.com"); sendIntent.SetType("text/plain"); AN_MainActivity.Instance.StartActivity(AN_Intent.CreateChooser(sendIntent, "Hello Lime Crime!")); #endif #if UNITY_IOS ISN_UIActivityViewController controller = new ISN_UIActivityViewController(); controller.SetText("Welcome to Lime Crime https://www.limecrime.com"); controller.Present((result) => { }); #endif }
void ShowSharingMenuAndroid(Texture2D imageToShare) { var Title = "Test Title"; var AppLink = "Test AppLink"; var PrioritizedApps = new List <string> { "whatsapp", "facebook" }; AN_Intent shareIntent = new AN_Intent(); shareIntent.SetAction(AN_Intent.ACTION_SEND); shareIntent.AddFlags(AN_Intent.FLAG_GRANT_READ_URI_PERMISSION); shareIntent.SetType(AN_MIMEDataType.Image); string sharingMessageText = "Sharing message text."; sharingMessageText = sharingMessageText + "\n\n" + AppLink; shareIntent.PutExtra(AN_Intent.EXTRA_TEXT, sharingMessageText); shareIntent.PutExtra(AN_Intent.EXTRA_STREAM, imageToShare); var pm = AN_MainActivity.Instance.GetPackageManager(); List <AN_ResolveInfo> resolveInfoList = pm.QueryIntentActivities(shareIntent, 0); if (resolveInfoList.Count == 0) { AN_Logger.Log("Could not find any app for sharing."); return; } List <AN_Intent> intentShareList = new List <AN_Intent>(); // Try to find apps from priority list to put them on the first positions foreach (string appName in PrioritizedApps) { foreach (AN_ResolveInfo resInfo in resolveInfoList) { string packageName = resInfo.ActivityInfo.PackageName; string name = resInfo.ActivityInfo.Name; if (resInfo.ActivityInfo.PackageName.ToLower().Contains(appName) || resInfo.ActivityInfo.Name.ToLower().Contains(appName)) { AN_Intent intent = new AN_Intent(shareIntent); intent.SetPackage(packageName); intentShareList.Add(intent); resolveInfoList.Remove(resInfo); break; } } } // Put all the others apps after prioritized ones for (int resInfoIndex = 0; resInfoIndex < resolveInfoList.Count; resInfoIndex++) { AN_ResolveInfo resInfo = resolveInfoList[resInfoIndex]; string packageName = resInfo.ActivityInfo.PackageName; string name = resInfo.ActivityInfo.Name; if (resInfoIndex != resolveInfoList.Count - 1) { AN_Intent intent = new AN_Intent(shareIntent); intent.SetPackage(packageName); intentShareList.Add(intent); } else { shareIntent.SetPackage(packageName); } } if (intentShareList.Count == 0) { AN_Logger.Log("Could not find any app for sharing."); } else { AN_Logger.Log("proxy.StartActivityForResult"); AN_Intent chooserIntent = AN_Intent.CreateChooser(shareIntent, Title, intentShareList.ToArray()); /* AN_ProxyActivity proxy = new AN_ProxyActivity(); * proxy.StartActivityForResult(chooserIntent, (result) => { * Debug.Log("Unity: Activity Result: " + result.ResultCode.ToString()); * proxy.Finish(); * });*/ AN_MainActivity.Instance.StartActivity(chooserIntent); } }
public static void StartFilteredChooserActivity(Texture2D screenshot) { AN_Intent shareIntent = new AN_Intent(); shareIntent.SetAction(AN_Intent.ACTION_SEND_MULTIPLE); shareIntent.SetType(AN_MIMEDataType.Image); shareIntent.PutExtra(AN_Intent.EXTRA_TEXT, "This is my text to send."); shareIntent.PutExtra(AN_Intent.EXTRA_EMAIL, "*****@*****.**", "*****@*****.**"); shareIntent.PutExtra(AN_Intent.EXTRA_TEXT, "EXTRA_TEXT2"); shareIntent.PutExtra(AN_Intent.EXTRA_SUBJECT, "EXTRA_SUBJECT2s"); var list = new List <Texture2D>() { screenshot, screenshot }; shareIntent.PutExtra(AN_Intent.EXTRA_STREAM, list.ToArray()); List <string> filters = new List <string>(); filters.Add("mail"); var pm = AN_MainActivity.Instance.GetPackageManager(); List <AN_ResolveInfo> resolveInfoList = pm.QueryIntentActivities(shareIntent, 0); if (resolveInfoList.Count == 0) { Debug.Log("No apps found"); return; } List <AN_Intent> intentShareList = new List <AN_Intent>(); foreach (AN_ResolveInfo resInfo in resolveInfoList) { string packageName = resInfo.ActivityInfo.PackageName; string name = resInfo.ActivityInfo.Name; foreach (string filterPattern in filters) { AN_Logger.Log(resInfo.ActivityInfo.PackageName); if (resInfo.ActivityInfo.PackageName.ToLower().Contains(filterPattern) || resInfo.ActivityInfo.Name.ToLower().Contains(filterPattern)) { AN_Intent intent = new AN_Intent(shareIntent); intent.SetPackage(packageName); // intent.setComponent(new ComponentName(packageName, name)); intentShareList.Add(intent); AN_Logger.Log("packageName: " + packageName); shareIntent.SetPackage(packageName); } } } if (intentShareList.Count == 0) { AN_Logger.Log("CAN'T FIND PACKAGES FOR FILTER: " + filters); } else { AN_Logger.Log("SHARE WITH FILTER: " + filters); AN_Intent chooserIntent = AN_Intent.CreateChooser(shareIntent, "Hello title", intentShareList.ToArray()); AN_MainActivity.Instance.StartActivity(chooserIntent); } }