Android 如果未安装应用,Wear API 会中断 Play 服务
Android Wear API breaks Play Services if app not installed
这绝对是某种错误,但我不知道将其提交到何处,我想看看其他开发人员是否有解决方法。
我制作了这个天气应用程序,我爸爸和姐姐都下载了它。它似乎工作了一段时间。然后我爸爸买了一个新的 phone(Republic Wireless 的 Moto E)。奇怪的是,应用程序启动时出现错误。 (来自 Google Play 服务的 16 个)。这意味着 API 不受支持。
我没有尝试访问太多 APIs。
gapi = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
然后上周它停止在我姐姐的 phone 上工作,给出同样的错误。这没有多大意义。我们有相同的 phone 和相同的运营商。为什么它不起作用?我确保她拥有最新版本的应用程序。基本上一切都是一样的。我发在网上。其他人得到了这个错误。我没有。
让我说清楚。我大约一个月前更新了应用程序。我没有发布任何新代码。与此同时,该应用程序在各种设备上停止运行,我不明白为什么。
在尝试了几乎所有方法来重现此错误后,我终于弄明白了。我卸载了我的 Android Wear 伴侣应用程序,这是其他人从未有过的。这样做时,我收到了这个错误。 Google Play 服务一定产生了一些不会正常失败的错误。
作为解决方法,我将尝试这样做:
if(appInstalledOrNot("com.google.android.wearable.app")) {
gapi = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
} else {
gapi = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
方法检查包是否已安装。
这不是一个很好的黑客攻击,而是一个由回归引起的黑客攻击。这是解决问题的好方法吗?
根据 Tips for Error Handling with Android Wear APIs blog post:
There are two ways that the connect() method can return ConnectionResult.API_UNAVAILABLE for wearable support with Google Play services:
- When requesting Wearable.API on any device running Android 4.2 (API level 17) or earlier
- When requesting Wearable.API when no Android Wear companion application or device is available
因此这是预期的行为。同样根据博客 post:
The best practice for developers is to implement two separate GoogleApiClient connections:
- One connection for Android Wear support, and
- A separate connection for all of the other APIs you need
This will ensure that the functionality of your app will remain for all users, whether or not there is wearable support available on their devices, as well as on older legacy devices.
这意味着您可以将可穿戴设备呼叫定向到仅连接到 Wearable.API
的 GoogleApiClient
(如果未连接则忽略)并将所有其他呼叫定向到不同的 GoogleApiClient
(不依赖于 Android Wear)。
这绝对是某种错误,但我不知道将其提交到何处,我想看看其他开发人员是否有解决方法。
我制作了这个天气应用程序,我爸爸和姐姐都下载了它。它似乎工作了一段时间。然后我爸爸买了一个新的 phone(Republic Wireless 的 Moto E)。奇怪的是,应用程序启动时出现错误。 (来自 Google Play 服务的 16 个)。这意味着 API 不受支持。
我没有尝试访问太多 APIs。
gapi = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
然后上周它停止在我姐姐的 phone 上工作,给出同样的错误。这没有多大意义。我们有相同的 phone 和相同的运营商。为什么它不起作用?我确保她拥有最新版本的应用程序。基本上一切都是一样的。我发在网上。其他人得到了这个错误。我没有。
让我说清楚。我大约一个月前更新了应用程序。我没有发布任何新代码。与此同时,该应用程序在各种设备上停止运行,我不明白为什么。
在尝试了几乎所有方法来重现此错误后,我终于弄明白了。我卸载了我的 Android Wear 伴侣应用程序,这是其他人从未有过的。这样做时,我收到了这个错误。 Google Play 服务一定产生了一些不会正常失败的错误。
作为解决方法,我将尝试这样做:
if(appInstalledOrNot("com.google.android.wearable.app")) {
gapi = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
} else {
gapi = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
方法检查包是否已安装。
这不是一个很好的黑客攻击,而是一个由回归引起的黑客攻击。这是解决问题的好方法吗?
根据 Tips for Error Handling with Android Wear APIs blog post:
There are two ways that the connect() method can return ConnectionResult.API_UNAVAILABLE for wearable support with Google Play services:
- When requesting Wearable.API on any device running Android 4.2 (API level 17) or earlier
- When requesting Wearable.API when no Android Wear companion application or device is available
因此这是预期的行为。同样根据博客 post:
The best practice for developers is to implement two separate GoogleApiClient connections:
- One connection for Android Wear support, and
- A separate connection for all of the other APIs you need
This will ensure that the functionality of your app will remain for all users, whether or not there is wearable support available on their devices, as well as on older legacy devices.
这意味着您可以将可穿戴设备呼叫定向到仅连接到 Wearable.API
的 GoogleApiClient
(如果未连接则忽略)并将所有其他呼叫定向到不同的 GoogleApiClient
(不依赖于 Android Wear)。