浏览代码

Merge pull request #4 from Unity-Technologies/update

Update
/main
GitHub 4 年前
当前提交
bf9d1338
共有 18 个文件被更改,包括 315 次插入54 次删除
  1. 6
      Assets/HuaweiHms/README.md
  2. 20
      Assets/HuaweiHms/src/Editor/AfterBuildToDo.cs
  3. 7
      Assets/HuaweiHms/src/hms/Android/service/IPushServiceListener.cs
  4. 10
      Assets/HuaweiHms/src/hms/JavaCode/javaClass/ads/RewardAd.cs
  5. 16
      Assets/HuaweiHms/src/hms/JavaCode/javaClass/base/AGConnectServicesConfig.cs
  6. 20
      Assets/HuaweiHms/src/hms/JavaCode/javaClass/base/Map.cs
  7. 20
      Assets/HuaweiHms/src/hms/JavaCode/javaClass/base/Task.cs
  8. 4
      Assets/HuaweiHms/src/hms/JavaCode/special.cs/HiAnalyticsInstance.cs
  9. 95
      Assets/HuaweiHmsDemo/demo/test/AnalyticTest.cs
  10. 6
      Assets/HuaweiHmsDemo/demo/test/PushTest.cs
  11. 36
      Assets/HuaweiHmsDemo/demo/test/ads/AdsListener.cs
  12. 11
      Assets/HuaweiHmsDemo/demo/test/ads/AdsTest.cs
  13. 14
      Assets/HuaweiHmsDemo/demo/test/location/ActiveConvertionTest.cs
  14. 41
      Assets/HuaweiHmsDemo/demo/test/location/GetLocationTest.cs
  15. 22
      Assets/HuaweiHmsDemo/demo/test/location/LocationListener.cs
  16. 1
      Assets/HuaweiHmsDemo/demo/test/location/LocationUpdateTest.cs
  17. 18
      Assets/HuaweiHms/src/hms/JavaCode/javaClass/base/Set.cs
  18. 22
      Assets/HuaweiHms/src/hms/JavaCode/javaClass/base/Toast.cs

6
Assets/HuaweiHms/README.md


enable `Custom Main Manifest`
`We should enable AndroidManifest when we use push or location sdk.`
**If Unity Version is 2018, there is not AndroidManifest checkbox, but you can put `AndroidManifest.xml` under `Assets/Plugins/Android`.**
**If Unity Version is 2019.2 or before, there is not AndroidManifest checkbox, but you can put `AndroidManifest.xml` under `Assets/Plugins/Android`.**
**If unity version is 2018, you should add implement and other configuration on `MainGradleTemplate`.**
**If unity version is 2019.2 or before, you should add implement and other configuration on `MainGradleTemplate`.**
**If unity version is 2018, you should add implement and other configuration on `MainGradleTemplate`.**
**If unity version is 2019.2 or before, you should add implement and other configuration on `MainGradleTemplate`.**
### 4. Enable unity library gradle
Edit -> Project Settings -> Player -> Android(icon) -> Publishing Settings -> Build

20
Assets/HuaweiHms/src/Editor/AfterBuildToDo.cs


using UnityEngine;
using System;
using UnityEngine;
using UnityEditor;
using System.IO;
using UnityEditor.Callbacks;

{
public int callbackOrder { get { return 0; } }
private bool compareVersion(string version1, string version2)
{
string[] version1List = version1.Split('.');
string[] version2List = version2.Split('.');
int v1year = Int32.Parse(version1List[0]);
int v2year = Int32.Parse(version2List[0]);
if (v1year != v2year)
{
return v1year > v2year;
}
int v1sub = Int32.Parse(version1List[1]);
int v2sub = Int32.Parse(version2List[1]);
return v1sub > v2sub;
}
if(Application.unityVersion.StartsWith("2018")){
if(compareVersion("2019.3", Application.unityVersion)) {
return path;
}

7
Assets/HuaweiHms/src/hms/Android/service/IPushServiceListener.cs


onSendError(arg0,HmsUtil.GetHmsBase<BaseException>(arg1));
}
public virtual void onMessageDelivered(string arg0, BaseException arg1) {
}
public void onMessageDelivered(string arg0, AndroidJavaObject arg1) {
onSendError(arg0,HmsUtil.GetHmsBase<BaseException>(arg1));
}
public virtual void onTokenError(BaseException arg0) {
}

10
Assets/HuaweiHms/src/hms/JavaCode/javaClass/ads/RewardAd.cs


public bool isLoaded() {
return Call<bool>("isLoaded");
}
public void loadAd(AdParam arg0, RewardAdLoadListener arg1) {
public void loadAd(string arg0, AdParam arg1) {
public void loadAd(string arg0, AdParam arg1) {
public void loadAd(AdParam arg0, RewardAdLoadListener arg1) {
Call("loadAd", arg0, arg1);
}
public void setRewardAdListener(RewardAdListener arg0) {

Call("setRewardVerifyConfig", arg0);
}
public void show(Activity arg0, RewardAdStatusListener arg1, bool arg2) {
Call("show", arg0, arg1, arg2);
}
}
public void show(Activity arg0, RewardAdStatusListener arg1, bool arg2) {
Call("show", arg0, arg1, arg2);
}
public void show() {
Call("show");

16
Assets/HuaweiHms/src/hms/JavaCode/javaClass/base/AGConnectServicesConfig.cs


public class AGConnectServicesConfig :HmsClass<AGConnectServicesConfig_Data>
{
public AGConnectServicesConfig (): base() { }
public static AGConnectServicesConfig fromContext(Context arg0) {
return CallStatic<AGConnectServicesConfig>("fromContext", arg0);
}
public bool getBoolean(string arg0, bool arg1) {
return Call<bool>("getBoolean", arg0, arg1);
public static AGConnectServicesConfig fromContext(Context arg0) {
return CallStatic<AGConnectServicesConfig>("fromContext", arg0);
public bool getBoolean(string arg0, bool arg1) {
return Call<bool>("getBoolean", arg0, arg1);
}
public int getInt(string arg0, int arg1) {
return Call<int>("getInt", arg0, arg1);
}

public string getString(string arg0) {
return Call<string>("getString", arg0);
}
}
public string getString(string arg0) {
return Call<string>("getString", arg0);
}
}
}

20
Assets/HuaweiHms/src/hms/JavaCode/javaClass/base/Map.cs


public class Map :HmsClass<Map_Data>
{
public Map (): base() { }
public Map<K, V> toMap<K, V>()
{
var map = new Map<K,V>();
map.obj = obj;
return map;
}
}
public class Map<K,V> : Map
{
public Set<K> keySet()
{
return Call<Set<K>>("keySet");
}
public V getOrDefault(K key, V value)
{
return Call<V>("getOrDefault", key, value);
}
}
}

20
Assets/HuaweiHms/src/hms/JavaCode/javaClass/base/Task.cs


public class Task :HmsClass<Task_Data>
{
public Task (): base() { }
public Task addOnCompleteListener(Executor arg0, OnCompleteListener arg1) {
public Task addOnCompleteListener(Activity arg0, OnCompleteListener arg1) {
public Task addOnCompleteListener(Activity arg0, OnCompleteListener arg1) {
public Task addOnCompleteListener(Executor arg0, OnCompleteListener arg1) {
public Task addOnSuccessListener(OnSuccessListener arg0) {
return Call<Task>("addOnSuccessListener", arg0);
public Task addOnSuccessListener(Activity arg0, OnSuccessListener arg1) {
return Call<Task>("addOnSuccessListener", arg0, arg1);
public Task addOnSuccessListener(Activity arg0, OnSuccessListener arg1) {
return Call<Task>("addOnSuccessListener", arg0, arg1);
public Task addOnSuccessListener(OnSuccessListener arg0) {
return Call<Task>("addOnSuccessListener", arg0);
public Task addOnFailureListener(Activity arg0, OnFailureListener arg1) {
return Call<Task>("addOnFailureListener", arg0, arg1);
public Task addOnFailureListener(OnFailureListener arg0) {
return Call<Task>("addOnFailureListener", arg0);
public Task addOnFailureListener(OnFailureListener arg0) {
return Call<Task>("addOnFailureListener", arg0);
public Task addOnFailureListener(Activity arg0, OnFailureListener arg1) {
return Call<Task>("addOnFailureListener", arg0, arg1);
}
}
}

4
Assets/HuaweiHms/src/hms/JavaCode/special.cs/HiAnalyticsInstance.cs


return Call<Task>("getAAID");
}
public Map getUserProfiles(){
return Call<Map>("getUserProfiles");
public Map getUserProfiles(bool arg0){
return Call<Map>("getUserProfiles", arg0);
}
}
}

95
Assets/HuaweiHmsDemo/demo/test/AnalyticTest.cs


using HuaweiHms;
using UnityEngine;
namespace HuaweiHmsDemo
{

private bool enabled;
private int level = 0;
public AnalyticTest()
{
HiAnalyticsTools.enableLog();

registerEvent("set userId",SetUserId);
registerEvent("get user profile",getUserProfiles);
registerEvent("Set push token",SetPushToken);
registerEvent("set Min Activity Sessions",setMinActivitySessions);
registerEvent("set Session Duration",setSessionDuration);
registerEvent("get AAID",getAAID);
registerEvent("enable log",enableLog);
registerEvent("page start",pageStart);
registerEvent("page end",pageEnd);
public void SetUserId()
{
instance.setUserId("unity test Id");
Util.showToast("userId set");
}
Util.showToast("product id set");
}
public void SendAnalyticEnable()
{

public void CreateClearCache()
{
instance.clearCachedData();
Util.showToast("Clear Cache");
Util.showToast("set favorite");
}
public void SetPushToken()
{
instance.setPushToken("fffff");
Util.showToast("set push token as ffff");
}
public void setMinActivitySessions()
{
instance.setMinActivitySessions(10000);
Util.showToast("setMinActivitySessions 10000");
}
public void setSessionDuration()
{
instance.setSessionDuration(900000);
Util.showToast("setMinActivitySessions 900000");
}
public void getAAID()
{
try
{
instance.getAAID().addOnSuccessListener(new HmsSuccessListener<string>((aaidResult) =>
{
TestTip.Inst.ShowText("getAAID success:" + aaidResult);
})).addOnFailureListener(new HmsFailureListener((e) =>
{
TestTip.Inst.ShowText($"getAAID failed: {e.toString()}");
}));
}
catch (System.Exception exception)
{
TestTip.Inst.ShowText(exception.ToString());
}
}
public void getUserProfiles()
{
getUserProfiles(false);
getUserProfiles(true);
}
public void getUserProfiles(bool preDefined)
{
var profiles = instance.getUserProfiles(preDefined).toMap<string, string>();
var keySet = profiles.keySet();
var keyArray = keySet.toArray();
foreach (var key in keyArray)
{
TestTip.Inst.ShowText($"{key}: {profiles.getOrDefault(key, "default")}");
}
}
public void pageStart()
{
instance.pageStart("page test", "page test");
TestTip.Inst.ShowText("set page start: page test, page test");
}
public void pageEnd()
{
instance.pageEnd("page test");
TestTip.Inst.ShowText("set page end: page test");
}
public void enableLog()
{
HiAnalyticsTools.enableLog(level + 3);
TestTip.Inst.ShowText($"current level {level + 3}");
level = (level + 1) % 4;
}
}
}

6
Assets/HuaweiHmsDemo/demo/test/PushTest.cs


TestTip.Inst.ShowText(var1);
}
public override void onMessageDelivered(string arg0, BaseException arg1)
{
TestTip.Inst.ShowText("onSendError called, message id:" + arg0 + "+ ErrCode:"
+ arg1.getErrorCode() + ", description:" + arg1.getMessage());
}
public override void onMessageSent(string arg0)
{
TestTip.Inst.ShowText( "onMessageSent called, Message id:" + arg0);

36
Assets/HuaweiHmsDemo/demo/test/ads/AdsListener.cs


using HuaweiHms;
namespace HuaweiHmsDemo{
public class Util
{
public static void showToast(string message)
{
Toast.makeText(new Context(),message, Toast.LENGTH_SHORT).show();
}
}
public class MAdListener : AdListener
{
private InterstitialAd ad;

}
public override void onAdLoaded()
{
Util.showToast("AdListener onAdLoaded");
public override void onAdFailed(int arg0)
{
Util.showToast($"Ad failed to load with error code {arg0}.");
}
public override void onAdOpened()
{
Util.showToast("Ad Opened");
}
public override void onAdClicked()
{
Util.showToast("Ad Clicked");
}
public override void onAdLeave()
{
Util.showToast("Ad Leave");
}
public override void onAdClosed()
{
Util.showToast("Ad Closed");
}
}
public class MRewardLoadListener : RewardAdLoadListener
{

}
public override void onRewardAdFailedToLoad(int errorCode)
{
Util.showToast("RewardAdLoadListener onRewardAdFailedToLoad "+errorCode);
Util.showToast("RewardAdLoadListener onRewardedLoaded");
TestTip.Inst.ShowText("RewardAdLoadListener onRewardedLoaded");
ad.show(new Context(), new MRewardAdStatusListener());
}

11
Assets/HuaweiHmsDemo/demo/test/ads/AdsTest.cs


registerEvent("load image ads " + Screen.width,LoadImageAds);
registerEvent("load video ads " + Screen.height,LoadVideoAds);
registerEvent("load reward ads",LoadRewardAds);
registerEvent("set consent personal",() => SetConsentStatus(true));
registerEvent("set consent non personal", ()=> SetConsentStatus(false));
registerEvent("consent",checkConsentStatus);
}
public void LoadImageAds()

MRewardLoadListener rewardAdLoadListener = new MRewardLoadListener(ad);
ad.loadAd(adParam, rewardAdLoadListener);
}
public void SetConsentStatus(bool personal)
{
Consent consentInfo = Consent.getInstance(new Context());
var consentStatus = personal ? ConsentStatus.PERSONALIZED : ConsentStatus.NON_PERSONALIZED;
consentInfo.setConsentStatus(consentStatus);
Util.showToast($"set consent status as {consentStatus}");
}
public void checkConsentStatus()
{
Consent consentInfo = Consent.getInstance(new Context());

14
Assets/HuaweiHmsDemo/demo/test/location/ActiveConvertionTest.cs


ActivityConversionInfo.Builder activityTransition = new ActivityConversionInfo.Builder();
public override void RegisterEvent(TestEvent registerEvent){
registerEvent("Check Still In and Out",GetLastLocation);
registerEvent("Check Still In and Out", CheckStill);
public void GetLastLocation()
public void CheckStill()
if(pendingIntent != null){
removeActivityTransitionUpdates();
}
if(pendingIntent != null){
removeActivityTransitionUpdates();
}
List transitions = new List();
activityTransition.setActivityType(103);
activityTransition.setConversionType(0);

TestTip.Inst.ShowText("deleteActivityConversionUpdates onSuccess");
})).addOnFailureListener(new HmsFailureListener((c) =>
{
TestTip.Inst.ShowText("removeActivityTransitionUpdates exception");
TestTip.Inst.ShowText($"removeActivityTransitionUpdates exception: {c.toString()}");
pendingIntent = null;
} catch (System.Exception e) {
TestTip.Inst.ShowText("removeActivityTransitionUpdates exception:" + e.Message);
}

41
Assets/HuaweiHmsDemo/demo/test/location/GetLocationTest.cs


using UnityEngine;
using UnityEngine.UI;
namespace HuaweiHmsDemo{
public class GetLastLocationTest:Test<GetLastLocationTest>{
namespace HuaweiHmsDemo
{
public class GetLastLocationTest : Test<GetLastLocationTest>
{
public override void RegisterEvent(TestEvent registerEvent){
registerEvent("Get Last Location",GetLastLocation);
public override void RegisterEvent(TestEvent registerEvent)
{
registerEvent("Get Last Location", () => GetLastLocation(false));
registerEvent("Get Last Location with Address", () => GetLastLocation(true));
public void GetLastLocation()
public void GetLastLocation(bool withAddress)
try {
Task lastLocation = mFusedLocationProviderClient.getLastLocation();
try
{
Task lastLocation = null;
if (withAddress)
{
var request = new LocationRequest();
request.setPriority(200);
lastLocation = mFusedLocationProviderClient.getLastLocationWithAddress(request);
}
else
{
lastLocation = mFusedLocationProviderClient.getLastLocation();
}
TestTip.Inst.ShowText( "getLastLocation onSuccess location is null");
TestTip.Inst.ShowText("getLastLocation onSuccess location is null");
"getLastLocation onSuccess location[Longitude,Latitude]:" + location.getLongitude() + ","
+ location.getLatitude());
"getLastLocation onSuccess location[Longitude,Latitude]:" + location.getLongitude() + ","
+ location.getLatitude());
} catch (System.Exception e) {
}
catch (System.Exception e)
{
}
}

22
Assets/HuaweiHmsDemo/demo/test/location/LocationListener.cs


using System;
using Exception = HuaweiHms.Exception;
public delegate void SuccessCallBack<T>(T o) where T: IHmsBase, new();
public class HmsSuccessListener<T>:OnSuccessListener where T: IHmsBase, new(){
public delegate void SuccessCallBack<T>(T o);
public class HmsSuccessListener<T>:OnSuccessListener{
public void onSuccess(T arg0)
{
TestTip.Inst.ShowText("OnSuccessListener onSsssuccess");
if(CallBack != null)
{
CallBack.Invoke(arg0);
}
}
var input = new T();
input.obj = arg0;
CallBack.Invoke(input);
Type type = typeof(T);
IHmsBase ret = (IHmsBase)Activator.CreateInstance(type);
ret.obj = arg0;
CallBack.Invoke((T)ret);
}
}
}

1
Assets/HuaweiHmsDemo/demo/test/location/LocationUpdateTest.cs


public override void RegisterEvent(TestEvent registerEvent)
{
registerEvent("SetPermission", SetPermission);
// registEvent("GetLocation",GetLocation);
registerEvent("update with callback-102", () => RequestLocationUpdates(102, CALLBACK));
registerEvent("update with callback-104", () => RequestLocationUpdates(104, CALLBACK));
registerEvent("update with callback-100", () => RequestLocationUpdates(100, CALLBACK));

18
Assets/HuaweiHms/src/hms/JavaCode/javaClass/base/Set.cs


using UnityEngine;
using System.Collections.Generic;
namespace HuaweiHms
{
public class Set_Data : IHmsBaseClass{
public string name => "java.util.Map";
}
public class Set<T> :HmsClass<Set_Data>
{
public Set (): base() { }
public T[] toArray()
{
return Call<T[]>("toArray");
}
}
}

22
Assets/HuaweiHms/src/hms/JavaCode/javaClass/base/Toast.cs


using UnityEngine;
using System.Collections.Generic;
namespace HuaweiHms
{
public class Toast_Data : IHmsBaseClass{
public string name => "android.widget.Toast";
}
public class Toast :HmsClass<Toast_Data>
{
public const int LENGTH_LONG = 1;
public const int LENGTH_SHORT = 0;
public Toast (Context arg0): base(arg0) { }
public Toast (): base() { }
public static Toast makeText(Context arg0, string arg1, int arg2) {
return CallStatic<Toast>("makeText", arg0, arg1, arg2);
}
public void show() {
Call("show");
}
}
}
正在加载...
取消
保存