「Unity/画像共有/SocialConnector」の版間の差分
提供: 初心者エンジニアの簡易メモ
| 行13: | 行13: | ||
string imagePath = Application.persistentDataPath + "/image.png"; | string imagePath = Application.persistentDataPath + "/image.png"; | ||
| + | ScreenCapture.CaptureScreenshot("image.png"); | ||
SocialConnector.SocialConnector.Share(message, "https://github.com/anchan828/social-connector", imagePath); | SocialConnector.SocialConnector.Share(message, "https://github.com/anchan828/social-connector", imagePath); | ||
2020年3月1日 (日) 07:45時点における版
注意:android,iosともにテキストのshereはできたが、画像キャプチャのshareは確認ができなかった・・・。
SocialConnectorとは
unityから共有できるライブラリ
公式
https://github.com/anchan828/social-connector
組み込み方法
- SocialConnector.unitypackage をAssets/Import/CustomImportを選択
- SocialConnector/Plugins/Android/AndroidManifest.xmlをPlugins/Andoird/AndroidManifest.xmlへ移動
- SocialConnector/Plugins/Android/resをPlugins/Andoird/resへ移動
- 以下のように呼び出し。
string imagePath = Application.persistentDataPath + "/image.png";
ScreenCapture.CaptureScreenshot("image.png");
SocialConnector.SocialConnector.Share(message, "https://github.com/anchan828/social-connector", imagePath);
注意:android,iosともにテキストのshereはできたが、画像キャプチャのshareは確認ができなかった・・・。
androidx対応
以下ファイルのandroid.support.v4.content.fileproviderからandroidx.core.content.FileProviderへ置換
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name">
<activity android:label="@string/app_name" android:name="com.unity3d.player.UnityPlayerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:enabled="true" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/filepaths" />
</provider>
</application>
</manifest>
SocialConnector/SocialConnector.cs
var fileProvider = new AndroidJavaClass("androidx.core.content.FileProvider");
ios対応
以下エラーが出る場合
'autorelease' is unavailable: not available in automatic reference counting mode
Build Phases/Compile SourcesのSocialConnector.mmをダブルクリックして -fno-objc-arc を追加
参考
http://nn-hokuson.hatenablog.com/entry/2018/05/16/195527
