Unity3d Line 分享接入代码 android and ios
来源:互联网 发布:喜欢安静的男生知乎 编辑:程序博客网 时间:2024/06/05 16:14
android
private static readonly string ShareTextureFilePath = Application.persistentDataPath + "/MLShare.jpg"; //截屏地址 public void SendToLine(string text, bool isImage, uint shareType, uint id, int itemId = 0) //text 分享文本 isImage 是否有图片 line 分享只能发生文字或者图片不能一起发 {#if UNITY_ANDROID && !UNITY_EDITOR try { var Intent = new AndroidJavaClass("android.content.Intent"); var ACTION_SEND = Intent.GetStatic<string>("ACTION_SEND"); var EXTRA_TEXT = Intent.GetStatic<string>("EXTRA_TEXT"); var EXTRA_STREAM = Intent.GetStatic<string>("EXTRA_STREAM"); var intent = new AndroidJavaObject("android.content.Intent"); intent.Call<AndroidJavaObject>("setClassName", "jp.naver.line.android", "jp.naver.line.android.activity.selectchat.SelectChatActivity"); intent.Call<AndroidJavaObject>("setAction", ACTION_SEND); if (text != null && text != "") { intent.Call<AndroidJavaObject>("putExtra", EXTRA_TEXT, text); intent.Call<AndroidJavaObject>("setType", "text/*"); } else if (isImage) { using (AndroidJavaClass uri = new AndroidJavaClass("android.net.Uri")) { if(DeviceUtil.GetAndroidVersionCode()>=24) { AndroidJavaClass _unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject _currentActivity = _unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); var file = new AndroidJavaObject("java.io.File", ShareTextureFilePath); AndroidJavaClass fileProvider = new AndroidJavaClass("android.support.v4.content.FileProvider"); var imgurl = fileProvider.CallStatic<AndroidJavaObject>("getUriForFile",_currentActivity,"com.mobile.legends.fileprovider",file); intent.Call<AndroidJavaObject>("putExtra",EXTRA_STREAM, imgurl); } else { intent.Call<AndroidJavaObject>("putExtra", EXTRA_STREAM,uri.CallStatic<AndroidJavaObject>("parse", ShareTextureFilePath)); } intent.Call<AndroidJavaObject>("setType", "image/*"); } } var UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); var currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); currentActivity.Call("startActivity", intent);//Intent.CallStatic<object>("createChooser", intent, "")); } catch (Exception e) { }#elif (UNITY_IOS || UNITY_IPHONE) && !UNITY_EDITOR _IOS_SendToLine(text, ShareTextureFilePath, isImage);#endif }
IOS
void _IOS_SendToLine(const char *url,const char *imgUrl,bool isImage) { if (isImage && imgUrl != NULL) { UIImage *Image =[[UIImage alloc]initWithContentsOfFile:[NSString stringWithFormat:[NSString stringWithUTF8String:imgUrl],NSHomeDirectory()]]; UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; [pasteboard setData:UIImageJPEGRepresentation(Image , 1.0) forPasteboardType:@"public.jpeg"]; NSString *contentType = @"image"; NSString *urlString = [NSString stringWithFormat:@"line://msg/%@/%@", contentType, pasteboard.name]; NSURL *url = [NSURL URLWithString:urlString]; [[UIApplication sharedApplication] openURL:url]; } else if (url != NULL) { NSString *contentType = @"text"; NSString *urlString = [NSString stringWithFormat:@"line://msg/%@/%@", contentType, [[NSString stringWithUTF8String:url] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSURL *url = [NSURL URLWithString:urlString]; [[UIApplication sharedApplication] openURL:url]; } }
阅读全文
0 0
- Unity3d Line 分享接入代码 android and ios
- Unity3d whatsapp 分享接入代码 android and ios
- unity3d android sdk接入
- Unity3d接入IOS的调用
- Unity3d接入IOS内购
- Unity3D接入SDK - iOS篇
- Unity 接入ShareSDK Android&iOS 微信分享
- unity3d 获取使用内存大小 android and ios
- ios 接入友盟分享
- Unity3d Android SDK接入解析
- [Unity3d]Unity3D接入91SDK(iOS)完整攻略
- Unity3D开发 - Unity3d与iOS交互开发(接入平台SDK)
- 微信分享iOS接入指南
- cocos2dx接入微信分享(IOS)
- [ObjectC]分享到支付宝iOS接入
- 【Unity3d】unity接入sharesdk分享本地图片失败记录
- unity3d接入有米广告SDK----android
- Unity3d接入Admob广告教程android篇
- superset开发环境配置
- 2017年11月4日提高组T2 字典序
- 【Luogu1373】小a和uim之大逃离(动态规划)
- maven 学习记录
- 14.笔记JAVA Spring框架学习————Bean生命周期
- Unity3d Line 分享接入代码 android and ios
- c++继承
- TCP,UDP报文详解
- 判断一个数是否素数
- 1.oracle基础---(大纲)
- AGC CODE FESTIVAL 2017 qual A(部分题解)
- asp.net 首页不在根目录下怎么配置
- 深度学习入门知识
- Android日记 android:contentDescription 属性