HMS在混合应用程序,AppGallery和华为电话仿真上的支持的10个问题





哈Ha!每年华为移动服务(HMS)生态系统中的服务数量。从9增长到31,开发人员开始对混合应用程序的支持,与AppGallery的交互,个人服务和鲸鱼的使用提出越来越多的疑问。我们与全球社区进行交流的主要平台是StackoverflowRedditXDA-Developers以及华为开发人员门户上的支持部分特别是对于那些对我们的平台感兴趣的人,我们从这些站点收集了10个有关使用华为移动服务的问题。 



1. React-native和Firebase SDK是否可以在没有Google服务且无需更改代码的华为手机上使用? 



是的,React-native应用程序无需修改即可运行,只需提交APK即可上传到华为应用程序库。Firebase SDK稍微复杂一些。应用程序的性能取决于您尝试在应用程序中包含的服务。例如,在没有Google移动服务的手机(例如Huawei Mate 30 Pro)上,将不支持使用Firebase身份验证模块登录到Google。



如果要对GMS和HMS使用相同的APK,则需要先检查服务可用性。 

对于GMS:



val gmsAvailable = GooglePlayServicesUtil.getInstance().isGooglePlayServicesAvailable(mContext)


对于HMS:



val hmsAvailable = HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(mContext)


尝试使用Google Login,Huawei Login或任何其他服务时:



if gmsAvailable {
   // execute GMS Code
} else if hmsAvailable {
   // execute HMS Code
}


2.支持额外的生态系统的真正隐性成本是什么?



在HMS中维护应用程序的成本取决于您如何设计系统以及应用程序需要哪些服务。平均而言,集成时间可能从几小时到几周不等,具体取决于应用程序以及原始应用程序中Google和Firebase服务的数量。



如果您的应用程序没有集成的GMS,则可以不做任何修改就下载它-Facebook,Yandex和其他服务都可以使用。



3. HMS支持哪些混搭? 



自HMS Core 5.0.0起,第三方平台支持的鲸鱼数量增加了:

 

Apache Cordova:





React Native:





Xamarin:





扑:





4.您能在华为手机上读取深度传感器(TOF)数据吗?



是的,可以使用AR Engine SDK来实现华为AR Engine提供场景网格的实时渲染,结果包括手机在空间中的位置。当前相机视图的3D网格仅支持Honor V20和P30Pro模型,它们可以接收深度信息,并且支持的扫描场景是静态的。 



以下设备支持TOF:
  • P: P30 / P30Pro / P40 / P40Pro / P40Pro +

  • Mate: Mate20 / Mate20Pro / Mate20RS / Mate 20X / Mate20X (5G) / Mate30 / Mate30Pro / Mate30RS / Mate30 (5G) / Mate30Pro (5G) / Mate X / Mate XS

  • Nova: Nova6 / Nova6-5G / Nova7 / Nova7Pro

  • Honor: Honor V20 / Honor 20 / Honor 20Pro / Honor V30 / Honor V30Pro / Honor 30S / Honor 30 Pro / Honor 30 Pro +

  • : Tablet M6


要从TOF接收数据,您需要通过以下方法使用ARSceneMesh



public ShortBuffer getSceneDepth()
        // Get the depth image of current frame(optimized).
public int getSceneDepthHeight()
        // Get the height of the depth image.
public int getSceneDepthWidth()
        // Get the width of the depth image.


还有其他有关如何计算深度的选项。您可以获取ARFrame类对象,并使用其方法hitTest,acquireDepthImage。ARSceneMesh类的GetSceneDepth方法还返回已处理的深度图。它更准确,但只能在2.5米范围内工作。



5.如何直接从应用程序打开AppGallery?



应用程序中的AppGallery的打开方式与Google Play商店相同。请注意,AppGallery使用其自己的appmarket://方案:



  • 方案:appmarket://
  • 包装:com.huawei.appmarket


这是AppGallery的片段



private void startHuaweiAppGallery() {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("appmarket://details?id=" + getPackageName()));
    List<ResolveInfo> otherApps = getPackageManager().queryIntentActivities(intent, 0);

    boolean agFound = false;

    for (ResolveInfo app : otherApps) {
        if (app.activityInfo.applicationInfo.packageName.equals("com.huawei.appmarket")) {
            ComponentName psComponent = new ComponentName(app.activityInfo.applicationInfo.packageName, app.activityInfo.name);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.setComponent(psComponent);
            startActivity(intent);

            agFound = true;
            break;
        }
    }

    //Optional, Or copy the Google Play Store URL here (See below)
    if (!agFound) {
        //Your Huawei app ID can be found in the Huawei developer console
        final string HUAWEI_APP_ID = "100864605";

        //ex. https://appgallery.cloud.huawei.com/marketshare/app/C100864605
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://appgallery.cloud.huawei.com/marketshare/app/C" + HUAWEI_APP_ID));
        startActivity(intent);
    }
}


6.如何创建华为Android模拟器?



华为向华为开发人员免费提供云调试服务。如果使用的是华为SDK,则必须有华为开发者帐号。只需登录华为开发者控制台并按照说明进行操作即可



云调试功能非常易于使用。它允许在真实设备上进行远程调试。在此过程中,您可以查看设备信息,将APK下载并安装到远程设备,接收操作日志,并将日志保存到本地计算机进行分析。



7.如何访问HMS推送通知的有效负载?



要访问有效负载,您需要实现HmsMessageService类并重写onMessageReceived方法。您可以从RemoteMessage对象访问有效负载。要访问令牌,请重写onNewToken方法。



Java代码:



import android.util.Log;

import com.huawei.hms.push.HmsMessageService;
import com.huawei.hms.push.RemoteMessage;

public class HService extends HmsMessageService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);

        if (remoteMessage != null) {
            if (!remoteMessage.getData().isEmpty()) {
                Log.d("HMS", "Payload" + remoteMessage.getData());
            }

            if (remoteMessage.getNotification() != null) {
                Log.d("HMS", "Message Notification Body: " + remoteMessage.getNotification().getBody());
            }
        }
    }
}


Kotlin代码:



override fun onMessageReceived(remoteMessage: RemoteMessage?) {
        super.onMessageReceived(remoteMessage)

        if (remoteMessage!!.data.isNotEmpty()) {
            Log.i(TAG, "Message data payload: " + remoteMessage.data)
        }

        if (remoteMessage.notification != null) {
            Log.i(TAG, "Message Notification Body: " + remoteMessage.notification.body)
        }
    }


确保您注册了服务:



<service
            android:name=".service.HService"
            android:enabled="true"
            android:exported="true"
            android:permission="${applicationId}.permission.PROCESS_PUSH_MSG"
            android:process=":HmsMessageService">
            <intent-filter>
                <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
            </intent-filter>
   </service>


8.在为华为手机开发Android应用程序时使用哪些工具?



对于应用程序开发,可以同时使用Android Studio和其他IDE(例如Eclipse,Intelliji IDEA)。如果您已经具有使用GMS的应用程序,请使用HMS Toolkit将与GMS一起使用的代码转换为与HMS一起使用。应该记住,HMS Toolkit不支持所有服务的转换,在使用它之前,最好先弄清楚它可以转移哪些服务。



9.如何在没有agconnect-services.json的情况下初始化HMS服务? 



HMS尚未提供单个基于代码的初始化解决方案。使用以下服务时,可以在不使用json文件的情况下进行初始化:



  • 推套件:



<meta-data        
    android:name="com.huawei.hms.client.appid"        
    <!-- Replace value xxx with the actual appid.-->         
    android:value="appid=xxx">         
</meta-data>


  • 地图套件:



MapsInitializer.setApiKey("Your API Key");


  • 网站套件:



SearchService searchService = SearchServiceFactory.create(this, "API key");


  • ML套件:



MLApplication.getInstance().setApiKey("your ApiKey");


10.产品管理系统(PMS)在HMS应用内购买中可以做什么?



产品管理系统(PMS)API允许您创建和管理产品信息。通过它,您可以:



  • 创建产品:包括具有自动续订的订阅。

  • 查询产品信息:例如,您可以基于App ID和Product ID查询特定产品,或查询符合指定条件的所有产品。

  • 更新产品信息:产品名称,语言,价格和状态。您可以同时使用一种或多种产品。

  • 促销产品:使用API,您可以按地区对广告系列进行分类,设置促销时间和设置价格。



到目前为止,如果您对使用HMS有任何疑问,请在评论中提问。



All Articles