Update key names; Separate method in Utility

This commit is contained in:
Anna Kocheshkova 2019-05-15 10:55:14 +03:00
Родитель 26431be772
Коммит 09c9699e09
10 изменённых файлов: 43 добавлений и 45 удалений

Просмотреть файл

@ -44,7 +44,7 @@ public class AppCenterLoader extends ContentProvider {
private static final String APP_SECRET_KEY = "appcenter_app_secret";
private static final String TRANSMISSION_TARGET_TOKEN_KEY = "appcenter_transmission_target_token";
private static final String STARTUP_TYPE_KEY = "appcenter_startup_type";
private static final String STARTUP_TYPE_SHARED_PREFERENCES_KEY = "start-target-user-defaults-key";
private static final String STARTUP_TYPE_SHARED_PREFERENCES_KEY = "AppCenter.Unity.StartTargetKey";
private static final String TRUE_VALUE = "True";
private static final String TAG = "AppCenterLoader";

Просмотреть файл

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Assets.AppCenter.Plugins.Android.Utility
{
class AndroidUtility
{
private static AndroidJavaObject _context;
private static string PREFS_NAME = "AppCenterUserPrefs";
public static AndroidJavaObject GetAndroidContext()
{
if (_context != null)
{
return _context;
}
var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
_context = activity.Call<AndroidJavaObject>("getApplicationContext");
return _context;
}
public static void SetPreferenceInt(string prefKey, int prefValue)
{
AndroidJavaObject context = GetAndroidContext();
AndroidJavaObject sharedPreferences = context.Call<AndroidJavaObject>("getSharedPreferences", new object[] { PREFS_NAME, 0 });
AndroidJavaObject editor = sharedPreferences.Call<AndroidJavaObject>("edit");
editor = editor.Call<AndroidJavaObject>("putInt", new object[] { prefKey, prefValue });
editor.Call("apply");
}
}
}

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
#if UNITY_ANDROID && !UNITY_EDITOR
using Assets.AppCenter.Plugins.Android.Utility;
using System;
using System.Collections.Generic;
using UnityEngine;
@ -11,8 +12,6 @@ namespace Microsoft.AppCenter.Unity.Internal
class AppCenterInternal
{
private static AndroidJavaClass _appCenter = new AndroidJavaClass("com.microsoft.appcenter.AppCenter");
private static AndroidJavaObject _context;
private static String PREFS_NAME = "AppCenterUserPrefs";
public static void SetLogLevel(int logLevel)
{
@ -132,32 +131,12 @@ namespace Microsoft.AppCenter.Unity.Internal
});
}
private static AndroidJavaObject GetAndroidContext()
{
if (_context != null)
{
return _context;
}
var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
_context = activity.Call<AndroidJavaObject>("getApplicationContext");
return _context;
}
public static void SetPreferenceInt(string prefKey, int prefValue) {
AndroidJavaObject context = GetAndroidContext();
AndroidJavaObject sharedPreferences = context.Call<AndroidJavaObject>("getSharedPreferences", new object[] { PREFS_NAME, 0 });
AndroidJavaObject editor = sharedPreferences.Call<AndroidJavaObject>("edit");
editor = editor.Call<AndroidJavaObject>("putInt", new object[] { prefKey, prefValue });
editor.Call("apply");
}
public static void StartFromLibrary(IntPtr servicesArray)
{
var startMethod = AndroidJNI.GetStaticMethodID(_appCenter.GetRawClass(), "startFromLibrary", "(Landroid/content/Context;[Ljava/lang/Class;)V");
AndroidJNI.CallStaticVoidMethod(_appCenter.GetRawClass(), startMethod, new jvalue[]
{
new jvalue { l = GetAndroidContext().GetRawObject() },
new jvalue { l = AndroidUtility.GetAndroidContext().GetRawObject() },
new jvalue { l = servicesArray }
});
}

Просмотреть файл

@ -37,10 +37,6 @@ namespace Microsoft.AppCenter.Unity.Internal
{
}
public static void SetPreferenceInt(string prefKey, int prefValue)
{
}
public static void Start(string appSecret, ServiceType[] services)
{
}

Просмотреть файл

@ -38,11 +38,6 @@ namespace Microsoft.AppCenter.Unity
AppCenterInternal.StartFromLibrary(AppCenterInternal.ServicesToNativeTypes(servicesArray));
}
public static void SetPreferenceInt(string prefKey, int prefValue)
{
AppCenterInternal.SetPreferenceInt(prefKey, prefValue);
}
public static AppCenterTask<bool> IsEnabledAsync()
{
return AppCenterInternal.IsEnabledAsync();

Просмотреть файл

@ -31,10 +31,6 @@ namespace Microsoft.AppCenter.Unity.Internal
UWPAppCenter.Start(appSecret, nativeServiceTypes);
}
public static void SetPreferenceInt(string prefKey, int prefValue)
{
}
public static void Start(Type[] services)
{
var nativeServiceTypes = ServicesToNativeTypes(services);

Просмотреть файл

@ -28,10 +28,6 @@ namespace Microsoft.AppCenter.Unity.Internal
return appcenter_unity_get_log_level();
}
public static void SetPreferenceInt(string prefKey, int prefValue)
{
}
public static string GetSdkVersion()
{
return appcenter_unity_get_sdk_version();

Просмотреть файл

@ -40,7 +40,7 @@ static NSString *const kMSTargetToken = @"appcenter-transmission-target-token";
static NSString *const kMSCustomLogUrl = @"custom-log-url";
static NSString *const kMSCustomApiUrl = @"custom-api-url";
static NSString *const kMSCustomInstallUrl = @"custom-install-url";
static NSString *const kMSStartTargetKey = @"start-target-user-defaults-key";
static NSString *const kMSStartTargetKey = @"MSAppCenterStartTargetUnityKey";
static const int kMSLogLevel = 0/*LOG_LEVEL*/;
static const int kMSStartupType = 0/*STARTUP_TYPE*/;

Просмотреть файл

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using Assets.AppCenter.Plugins.Android.Utility;
using Microsoft.AppCenter.Unity;
using Microsoft.AppCenter.Unity.Distribute;
using Microsoft.AppCenter.Unity.Push;
@ -28,7 +29,8 @@ public class PuppetAppCenter : MonoBehaviour
public const string TextAttachmentKey = "text_attachment";
public const string BinaryAttachmentKey = "binary_attachment";
public const string UserIdKey = "user_id";
private const string StartupModeKey = "start-target-user-defaults-key";
private const string StartupModeAndroidKey = "AppCenter.Unity.StartTargetKey";
private const string StartupModeKey = "MSAppCenterStartTargetUnityKey";
public GameObject CustomProperty;
public RectTransform PropertiesList;
public Toggle DistributeEnabled;
@ -177,7 +179,7 @@ public class PuppetAppCenter : MonoBehaviour
PlayerPrefs.SetInt(StartupModeKey, startupMode);
PlayerPrefs.Save();
#if UNITY_ANDROID && !UNITY_EDITOR
AppCenter.SetPreferenceInt(StartupModeKey, startupMode);
AndroidUtility.SetPreferenceInt(StartupModeAndroidKey, startupMode);
#endif
}

Просмотреть файл

@ -345,7 +345,6 @@ public class PuppetTransmission : MonoBehaviour
public void TrackEventTypedPropertiesDefaultTransmission()
{
var properties = PropertiesHelper.GetTypedProperties(EventPropertiesList);
if (properties == null)
{