Skip to content

Commit fb65859

Browse files
committed
updated script file
1 parent 412856e commit fb65859

File tree

6 files changed

+252
-17
lines changed

6 files changed

+252
-17
lines changed

UnityClient/Assets/Plugins/Android/mainTemplate.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,8 @@ android {
8484
}
8585
}
8686
}**SPLITS_VERSION_CODE****REPOSITORIES****SOURCE_BUILD_SETUP**
87+
88+
dependencies {
89+
implementation fileTree(include: ['*.jar'], dir: 'libs')
90+
implementation 'com.android.support:appcompat-v7:28.0.0'
91+
}

UnityClient/Assets/Scenes/SharingScene.unity

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,50 @@ NavMeshSettings:
120120
debug:
121121
m_Flags: 0
122122
m_NavMeshData: {fileID: 0}
123+
--- !u!1 &241125748
124+
GameObject:
125+
m_ObjectHideFlags: 0
126+
m_CorrespondingSourceObject: {fileID: 0}
127+
m_PrefabInstance: {fileID: 0}
128+
m_PrefabAsset: {fileID: 0}
129+
serializedVersion: 6
130+
m_Component:
131+
- component: {fileID: 241125750}
132+
- component: {fileID: 241125749}
133+
m_Layer: 0
134+
m_Name: GameObject
135+
m_TagString: Untagged
136+
m_Icon: {fileID: 0}
137+
m_NavMeshLayer: 0
138+
m_StaticEditorFlags: 0
139+
m_IsActive: 1
140+
--- !u!114 &241125749
141+
MonoBehaviour:
142+
m_ObjectHideFlags: 0
143+
m_CorrespondingSourceObject: {fileID: 0}
144+
m_PrefabInstance: {fileID: 0}
145+
m_PrefabAsset: {fileID: 0}
146+
m_GameObject: {fileID: 241125748}
147+
m_Enabled: 1
148+
m_EditorHideFlags: 0
149+
m_Script: {fileID: 11500000, guid: 6416fcf60e3974c62adcb5267ab2db9d, type: 3}
150+
m_Name:
151+
m_EditorClassIdentifier:
152+
shareButton: {fileID: 1964765122}
153+
--- !u!4 &241125750
154+
Transform:
155+
m_ObjectHideFlags: 0
156+
m_CorrespondingSourceObject: {fileID: 0}
157+
m_PrefabInstance: {fileID: 0}
158+
m_PrefabAsset: {fileID: 0}
159+
m_GameObject: {fileID: 241125748}
160+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
161+
m_LocalPosition: {x: 0, y: 0, z: 0}
162+
m_LocalScale: {x: 1, y: 1, z: 1}
163+
m_Children: []
164+
m_Father: {fileID: 0}
165+
m_RootOrder: 4
166+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
123167
--- !u!1 &705507993
124168
GameObject:
125169
m_ObjectHideFlags: 0
Lines changed: 103 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,107 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using UnityEngine;
1+
using UnityEngine;
2+
using UnityEngine.UI;
3+
using System.Collections;
44

55
public class NativeScreenshotShareUsingFileProvider : MonoBehaviour
66
{
7-
// Start is called before the first frame update
8-
void Start()
9-
{
10-
11-
}
12-
13-
// Update is called once per frame
14-
void Update()
15-
{
16-
17-
}
7+
public Button shareButton;
8+
9+
private bool isFocus = false;
10+
11+
private string shareSubject, shareMessage;
12+
private bool isProcessing = false;
13+
private string screenshotName;
14+
15+
void Start () {
16+
shareButton.onClick.AddListener (OnShareButtonClick);
17+
}
18+
19+
20+
void OnApplicationFocus (bool focus) {
21+
isFocus = focus;
22+
}
23+
24+
public void OnShareButtonClick () {
25+
26+
screenshotName = "fireblock_highscore.png";
27+
shareSubject = "I challenge you to beat my high score in Fire Block";
28+
shareMessage = "I challenge you to beat my high score in Fire Block. " +
29+
". Get the Fire Block app from the link below. \nCheers\n" +
30+
"\nhttp://onelink.to/fireblock";
31+
32+
ShareScreenshot ();
33+
}
34+
35+
36+
private void ShareScreenshot () {
37+
38+
#if UNITY_ANDROID
39+
if (!isProcessing) {
40+
StartCoroutine (ShareScreenshotInAnroid ());
41+
}
42+
43+
#else
44+
Debug.Log("No sharing set up for this platform.");
45+
#endif
46+
}
47+
48+
49+
50+
#if UNITY_ANDROID
51+
public IEnumerator ShareScreenshotInAnroid () {
52+
53+
isProcessing = true;
54+
// wait for graphics to render
55+
yield return new WaitForEndOfFrame ();
56+
57+
string screenShotPath = Application.persistentDataPath + "/" + screenshotName;
58+
ScreenCapture.CaptureScreenshot (screenshotName, 1);
59+
yield return new WaitForSeconds (0.5f);
60+
61+
if (!Application.isEditor) {
62+
//current activity context
63+
AndroidJavaClass unity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
64+
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject> ("currentActivity");
65+
66+
//Create intent for action send
67+
AndroidJavaClass intentClass = new AndroidJavaClass ("android.content.Intent");
68+
AndroidJavaObject intentObject = new AndroidJavaObject ("android.content.Intent");
69+
intentObject.Call<AndroidJavaObject> ("setAction", intentClass.GetStatic<string> ("ACTION_SEND"));
70+
71+
//old code which is not allowed in Android 8 or above
72+
//create image URI to add it to the intent
73+
//AndroidJavaClass uriClass = new AndroidJavaClass ("android.net.Uri");
74+
//AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject> ("parse", "file://" + screenShotPath);
75+
76+
//create file object of the screenshot captured
77+
AndroidJavaObject fileObject = new AndroidJavaObject("java.io.File", screenShotPath);
78+
79+
//create FileProvider class object
80+
AndroidJavaClass fileProviderClass = new AndroidJavaClass("android.support.v4.content.FileProvider");
81+
82+
object[] providerParams = new object[3];
83+
providerParams[0] = currentActivity;
84+
providerParams[1] = "com.agrawalsuneet.unityclient.provider";
85+
providerParams[2] = fileObject;
86+
87+
//instead of parsing the uri, will get the uri from file using FileProvider
88+
AndroidJavaObject uriObject = fileProviderClass.CallStatic<AndroidJavaObject>("getUriForFile", providerParams);
89+
90+
//put image and string extra
91+
intentObject.Call<AndroidJavaObject> ("putExtra", intentClass.GetStatic<string> ("EXTRA_STREAM"), uriObject);
92+
intentObject.Call<AndroidJavaObject> ("setType", "image/png");
93+
intentObject.Call<AndroidJavaObject> ("putExtra", intentClass.GetStatic<string> ("EXTRA_SUBJECT"), shareSubject);
94+
intentObject.Call<AndroidJavaObject> ("putExtra", intentClass.GetStatic<string> ("EXTRA_TEXT"), shareMessage);
95+
96+
//additionally grant permission to read the uri
97+
intentObject.Call<AndroidJavaObject> ("addFlags", intentClass.GetStatic<int>("FLAG_GRANT_READ_URI_PERMISSION") );
98+
99+
AndroidJavaObject chooser = intentClass.CallStatic<AndroidJavaObject> ("createChooser", intentObject, "Share your high score");
100+
currentActivity.Call ("startActivity", chooser);
101+
}
102+
103+
yield return new WaitUntil (() => isFocus);
104+
isProcessing = false;
105+
}
106+
#endif
18107
}

UnityClient/ProjectSettings/GraphicsSettings.asset

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ GraphicsSettings:
3535
- {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0}
3636
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
3737
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
38+
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
39+
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
40+
- {fileID: 16003, guid: 0000000000000000f000000000000000, type: 0}
41+
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
3842
m_PreloadedShaders: []
3943
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
4044
type: 0}

UnityClient/ProjectSettings/ProjectSettings.asset

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ PlayerSettings:
158158
resolutionScalingMode: 0
159159
androidSupportedAspectRatio: 1
160160
androidMaxAspectRatio: 2.1
161-
applicationIdentifier: {}
161+
applicationIdentifier:
162+
Android: com.agrawalsuneet.unityclient
162163
buildNumber: {}
163164
AndroidBundleVersionCode: 1
164165
AndroidMinSdkVersion: 16
@@ -269,7 +270,99 @@ PlayerSettings:
269270
androidGamepadSupportLevel: 0
270271
resolutionDialogBanner: {fileID: 0}
271272
m_BuildTargetIcons: []
272-
m_BuildTargetPlatformIcons: []
273+
m_BuildTargetPlatformIcons:
274+
- m_BuildTarget: Android
275+
m_Icons:
276+
- m_Textures: []
277+
m_Width: 432
278+
m_Height: 432
279+
m_Kind: 2
280+
m_SubKind:
281+
- m_Textures: []
282+
m_Width: 324
283+
m_Height: 324
284+
m_Kind: 2
285+
m_SubKind:
286+
- m_Textures: []
287+
m_Width: 216
288+
m_Height: 216
289+
m_Kind: 2
290+
m_SubKind:
291+
- m_Textures: []
292+
m_Width: 162
293+
m_Height: 162
294+
m_Kind: 2
295+
m_SubKind:
296+
- m_Textures: []
297+
m_Width: 108
298+
m_Height: 108
299+
m_Kind: 2
300+
m_SubKind:
301+
- m_Textures: []
302+
m_Width: 81
303+
m_Height: 81
304+
m_Kind: 2
305+
m_SubKind:
306+
- m_Textures: []
307+
m_Width: 192
308+
m_Height: 192
309+
m_Kind: 0
310+
m_SubKind:
311+
- m_Textures: []
312+
m_Width: 144
313+
m_Height: 144
314+
m_Kind: 0
315+
m_SubKind:
316+
- m_Textures: []
317+
m_Width: 96
318+
m_Height: 96
319+
m_Kind: 0
320+
m_SubKind:
321+
- m_Textures: []
322+
m_Width: 72
323+
m_Height: 72
324+
m_Kind: 0
325+
m_SubKind:
326+
- m_Textures: []
327+
m_Width: 48
328+
m_Height: 48
329+
m_Kind: 0
330+
m_SubKind:
331+
- m_Textures: []
332+
m_Width: 36
333+
m_Height: 36
334+
m_Kind: 0
335+
m_SubKind:
336+
- m_Textures: []
337+
m_Width: 192
338+
m_Height: 192
339+
m_Kind: 1
340+
m_SubKind:
341+
- m_Textures: []
342+
m_Width: 144
343+
m_Height: 144
344+
m_Kind: 1
345+
m_SubKind:
346+
- m_Textures: []
347+
m_Width: 96
348+
m_Height: 96
349+
m_Kind: 1
350+
m_SubKind:
351+
- m_Textures: []
352+
m_Width: 72
353+
m_Height: 72
354+
m_Kind: 1
355+
m_SubKind:
356+
- m_Textures: []
357+
m_Width: 48
358+
m_Height: 48
359+
m_Kind: 1
360+
m_SubKind:
361+
- m_Textures: []
362+
m_Width: 36
363+
m_Height: 36
364+
m_Kind: 1
365+
m_SubKind:
273366
m_BuildTargetBatching:
274367
- m_BuildTarget: Standalone
275368
m_StaticBatching: 1

UnityClient/ProjectSettings/UnityConnectSettings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
UnityConnectSettings:
55
m_ObjectHideFlags: 0
66
serializedVersion: 1
7-
m_Enabled: 0
7+
m_Enabled: 1
88
m_TestMode: 0
99
m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events
1010
m_EventUrl: https://cdp.cloud.unity3d.com/v1/events

0 commit comments

Comments
 (0)