Androidで新しいGoogleマップV2 APIを使用すると、Google Play(サービス)アプリがインストールされていないデバイスにエラーメッセージが表示されます。このエラーメッセージのスタイルを何とかオーバーライドして、あまり気にならないようにし、アプリのスタイルをより適切に適合させることができるかどうかは疑問です。AndroidでGoogle Playサービスエラーのスタイルを設定するには
これは、エラーは次のようになります。いくつかの調査を行った後
Androidで新しいGoogleマップV2 APIを使用すると、Google Play(サービス)アプリがインストールされていないデバイスにエラーメッセージが表示されます。このエラーメッセージのスタイルを何とかオーバーライドして、あまり気にならないようにし、アプリのスタイルをより適切に適合させることができるかどうかは疑問です。AndroidでGoogle Playサービスエラーのスタイルを設定するには
これは、エラーは次のようになります。いくつかの調査を行った後
、私は最善の解決策は、手動でサービスライブラリはGoogle Playの存在をチェックし、カスタムエラーを表示するようにしたことが決定しましたダイアログまたはエラーレイアウト。 GooglePlayServicesUtil
には、これをかなり簡単にするユーティリティメソッドがいくつかあります。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int statusCode =
GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (statusCode == ConnectionResult.SUCCESS) {
// Continue with your regular activity/fragment configuration.
} else {
// Hide the map fragment so the default error message is not
// visible.
findViewById(R.id.map).setVisibility(View.GONE);
// Show a custom error message
showErrorMessage(statusCode);
}
}
private void showErrorMessage(final int statusCode) {
// I've outlined two solutions below. Pick which one works best for
// you and remove the if-block.
boolean showDialog = false;
if (showDialog) {
// This is the easiest method and simply displays a pre-configured
// error dialog
GooglePlayServicesUtil.getErrorDialog(statusCode, this, 0).show();
} else {
// Show a completely custom layout
findViewById(R.id.error).setVisibility(View.VISIBLE);
// Wire up the button to install the missing library
Button errorButton = (Button) findViewById(R.id.error_button);
errorButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
// Perform the correct action for the given status
// code!
GooglePlayServicesUtil.getErrorPendingIntent(
statusCode, getActivity(), 0).send();
} catch (CanceledException e1) {
// Pass
}
}
});
}
}
ボタンに適したテキストを設定する方法は? –
アラートを表示するには、最初に「GooglePlayServicesUtil.isUserRecoverableError(statusCode)」を確認することをおすすめします。 – bryant1410
GooglePlayServiceUtil
推奨されていません。最新のインターフェイスについてはGoogleApiAvailability
をご覧ください。エラーAlertDialog
の代わりにDialogFragment
を直接使用することをお勧めします。これにより、アクティビティが適切に管理できるようになります。
public static boolean checkPlayServices(FragmentActivity activity) {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(activity);
if (resultCode != ConnectionResult.SUCCESS) {
if (googleApiAvailability.isUserResolvableError(resultCode)) {
// "user resolvable" means Google Play is available to download the last version of Play Services APK
// This will open Google dialog fragment displaying the proper message depending on "resultCode"
googleApiAvailability.showErrorDialogFragment(activity, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST);
} else {
// Should not happen. This device does not support Play Services.
// Let's show an ultimate warning.
MyCustomPlayServicesErrorDialogFragment playServicesErrorDialog = new MyCustomPlayServicesErrorDialogFragment();
playServicesErrorDialog.show(activity.getFragmentManager(), TAG);
}
return false;
}
return true;
}
どのようにあなたがそれを育てていますか? 'getErrorDialog()'の結果は、あまりにも不快なものではありません。つまり、私はUIのこの部分に影響を与えていることは記録されていません。 – CommonsWare
私はちょうどXMLレイアウトに埋め込まれたマップフラグメントを持っています。再生サービスがない場合は、このコンテンツが表示されます。私はエラーダイアログオプションについて知らなかった!それは良い解決策のようです。 – twaddington
ええ、 'getErrorDialog()'ルートに行きます。マップV2のこの部分はうまくいきましたが、 'getErrorDialog()'は私には一番嫌な感じでした。 :-) – CommonsWare