private static AndroidJavaObject CallMethod(string methodName, AndroidJavaObject extrasBundle) { VerifyContentProvider(); AndroidJavaObject resultBundle; try { // Java: currentActivity.getContentResolver().call(Uri.parse("content://..."), methodName, null, extras) using (var context = UnityPlayerHelper.GetCurrentActivity()) using (var contentResolver = context.Call <AndroidJavaObject>(AndroidConstants.ContextMethodGetContentResolver)) using (var uriClass = new AndroidJavaClass(AndroidConstants.UriClass)) using (var uri = uriClass.CallStatic <AndroidJavaObject>(AndroidConstants.UriMethodParse, ContentAuthority)) { resultBundle = contentResolver.Call <AndroidJavaObject>( AndroidConstants.ContentResolverMethodCall, uri, methodName, null, extrasBundle); } } catch (AndroidJavaException ex) { throw new CookieApiException( string.Format("Failed to call {0} on the instant apps content provider.", methodName), ex); } if (resultBundle == null) { // This should only happen if the content provider is unavailable. throw new CookieApiException( string.Format("Null result calling {0} on the instant apps content provider.", methodName)); } return(resultBundle); }
/// <summary> /// Calls Play Core to show a confirmation dialog for all downloads that are currently in the /// <see cref="AssetDeliveryStatus.WaitingForWifi"/> state. If the user accepts the dialog, then those /// packs are downloaded over cellular data. /// </summary> /// <returns> /// Returns a <see cref="PlayCoreTask{ActivityResult}"/> that completes once the dialog has been accepted, /// denied or closed. A successful task result contains one of the following values: /// <ul> /// <li><see cref="ActivityResult.ResultOk"/> if the user accepted.</li> /// <li><see cref="ActivityResult.ResultCancelled"/> if the user denied or the dialog has been closed in /// any other way (e.g. backpress).</li> /// </ul> /// </returns> public PlayCoreTask <int> ShowCellularDataConfirmation() { var task = _javaAssetPackManager.Call <AndroidJavaObject>("showCellularDataConfirmation", UnityPlayerHelper.GetCurrentActivity()); return(new PlayCoreTask <int>(task)); }
private static void VerifyContentProvider() { if (_verifiedContentProvider) { return; } // Java: currentActivity.getPackageManager().resolveContentProvider("com.google.android.gms...", 0) using (var context = UnityPlayerHelper.GetCurrentActivity()) using (var packageManager = context.Call <AndroidJavaObject>(AndroidConstants.ContextMethodGetPackageManager)) using (var providerInfo = packageManager.Call <AndroidJavaObject>( AndroidConstants.PackageManagerMethodResolveContentProvider, Authority, 0)) { if (!PlaySignatureVerifier.VerifyGooglePlayServices(packageManager)) { throw new CookieApiException("Failed to verify the signature of Google Play Services."); } if (providerInfo == null) { throw new CookieApiException("Failed to resolve the instant apps content provider."); } var packageName = providerInfo.Get <string>(AndroidConstants.ProviderInfoFieldPackageName); if (!string.Equals(packageName, AndroidConstants.GooglePlayServicesPackageName)) { throw new CookieApiException( string.Format("Package \"{0}\" is an invalid instant apps content provider.", packageName)); } } Debug.Log("Verified instant apps content provider."); _verifiedContentProvider = true; }
/// <summary> /// Shows a dialog that allows the user to install the current instant app. /// <param name="referrer">Optional install referrer string.</param> /// </summary> public static void ShowInstallPrompt(string referrer = null) { using (var activity = UnityPlayerHelper.GetCurrentActivity()) using (var postInstallIntent = CreatePostInstallIntent(activity)) { ShowInstallPrompt(activity, IgnoredRequestCode, postInstallIntent, referrer); } }
/// <summary> /// Returns a <see cref="PlayCoreTask{TAndroidJava}"/> when the user completes the review or /// the dialog is dismissed. /// </summary> /// <param name="reviewInfo">The on success result of <see cref="RequestReviewFlow"/>.</param> public PlayCoreTask <AndroidJavaObject> LaunchReviewFlow(AndroidJavaObject reviewInfo) { var javaTask = _javaReviewManager.Call <AndroidJavaObject>("launchReviewFlow", UnityPlayerHelper.GetCurrentActivity(), reviewInfo); return(new PlayCoreTask <AndroidJavaObject>(javaTask)); }
/// <summary> /// This method can be called from an installed app to obtain a string that was included in /// the postInstallIntent provided by an instant app via <see cref="ShowInstallPrompt()"/>. /// It assumes that the current activity was the one that was launched by Play Store. /// </summary> /// <param name="extraKey">Key for obtaining a string extra from current activity's intent.</param> /// <returns>The string extra value.</returns> public static string GetPostInstallIntentStringExtra(string extraKey) { // Java: currentActivity.getIntent().getStringExtra(extraKey) using (var activity = UnityPlayerHelper.GetCurrentActivity()) using (var intent = activity.Call <AndroidJavaObject>(AndroidConstants.ActivityMethodGetIntent)) { return(intent.Call <string>(AndroidConstants.IntentMethodGetStringExtra, extraKey)); } }
internal ReviewPlayCoreTaskManager() { const string factoryClassName = PlayCoreConstants.PlayCorePackagePrefix + "review.ReviewManagerFactory"; using (var activity = UnityPlayerHelper.GetCurrentActivity()) using (var managerFactory = new AndroidJavaClass(factoryClassName)) { _javaReviewManager = managerFactory.CallStatic <AndroidJavaObject>("create", activity); } PlayCoreEventHandler.CreateInScene(); }
private void SetScore(int newScore) { _score = newScore; #if !UNITY_EDITOR Debug.Log("Is instant app: " + UnityPlayerHelper.IsInstantApp()); #endif Debug.Log("before setting level " + (_score % MAX_SCORE_PER_LEVEL > 0)); if (_score != 0 && _score % MAX_SCORE_PER_LEVEL == 0) { IncrementLevel(); } UpdateScoreDisplay(); }
public AssetPackManager() { const string factoryClassName = PlayCoreConstants.AssetPackPackagePrefix + "AssetPackManagerFactory"; using (var activity = UnityPlayerHelper.GetCurrentActivity()) using (var assetPackManagerFactory = new AndroidJavaClass(factoryClassName)) { _javaAssetPackManager = assetPackManagerFactory.CallStatic <AndroidJavaObject>("getInstance", activity); } if (_javaAssetPackManager == null) { throw new NullReferenceException("Play Core returned null AssetPackManager"); } }
internal AppUpdateManagerPlayCore() { const string factoryClassName = PlayCoreConstants.PlayCorePackagePrefix + "appupdate.AppUpdateManagerFactory"; using (var activity = UnityPlayerHelper.GetCurrentActivity()) using (var managerFactory = new AndroidJavaClass(factoryClassName)) { _javaAppUpdateManager = managerFactory.CallStatic <AndroidJavaObject>("create", activity); } if (_javaAppUpdateManager == null) { throw new NullReferenceException("Play Core returned null AppUpdateManager"); } PlayCoreEventHandler.CreateInScene(); }
public void DoInstallClick() { Debug.Log("DoInstallClick"); #if PLAY_INSTANT Debug.LogFormat("Cookie max size: {0}", CookieApi.GetInstantAppCookieMaxSizeBytes()); var result = CookieApi.SetInstantAppCookie("test-cookie"); Debug.LogFormat("Set cookie result: {0}", result); using (var activity = UnityPlayerHelper.GetCurrentActivity()) using (var postInstallIntent = InstallLauncher.CreatePostInstallIntent(activity)) { InstallLauncher.PutPostInstallIntentStringExtra(postInstallIntent, "payload", "test-payload-value"); InstallLauncher.ShowInstallPrompt(activity, 1234, postInstallIntent, "test-referrer"); } #else Debug.LogErrorFormat("Intent result: \"{0}\"", InstallLauncher.GetPostInstallIntentStringExtra("payload")); Debug.LogErrorFormat("Cookie: \"{0}\"", CookieApi.GetInstantAppCookie()); #endif }
/// <summary> /// Starts the desired update flow indicated by <param name="appUpdateOptions"> asynchronously. /// </summary> /// <param name="appUpdateInfo">The on success result of <see cref="GetAppUpdateInfo"/>.</param> /// <param name="appUpdateOptions"><see cref="AppUpdateOptions"/> contains update type options.</param> /// <returns> /// A <see cref="PlayCoreTask<int>"/> which gives an int result /// once the dialog has been accepted, denied or closed. /// A successful task result contains one of the following values: /// <ul> /// <li><see cref="ActivityResult.ResultOk"/> -1 if the user accepted.</li> /// <li><see cref="ActivityResult.ResultCancelled"/> 0 if the user denied or the dialog has been closed in /// any other way (e.g. backpress).</li> /// <li><see cref="ActivityResult.ResultFailed"/> 1 if the activity created to achieve has failed.</li> /// </ul> /// </returns> public PlayCoreTask <int> StartUpdateFlow(AppUpdateInfo appUpdateInfo, AppUpdateOptions appUpdateOptions) { var javaTask = _javaAppUpdateManager.Call <AndroidJavaObject>("startUpdateFlow", appUpdateInfo.GetJavaUpdateInfo(), UnityPlayerHelper.GetCurrentActivity(), appUpdateOptions.GetJavaAppUpdateOptions()); return(new PlayCoreTask <int>(javaTask)); }