android – Google Maps API v2法律声明字符串太长了

我正在尝试在我的 Android应用中添加Google Maps v2 API的法律声明,可以通过调用来获取:GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo()

所以,我的代码如下:

String LicenseInfo = GooglePlayServicesUtil
      .getOpenSourceSoftwareLicenseInfo(getApplicationContext());

AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(MyActivity.this);
LicenseDialog.setTitle("Lagal Notices");
LicenseDialog.setMessage(LicenseInfo);
LicenseDialog.show();

但是当我执行这段代码时,系统需要大约10秒才能显示对话框(考虑到我的设备是OnePlus One,看起来很奇怪).

如果我尝试用简单(较短)的字符串替换LicenseInfo,则Dialog的打开速度非常快.所以我认为问题是从Google Play utils检索的法律声明信息的长度.

我怎么解决这个问题?

我遇到了同样的问题,但我在GitHub上发现了这个问题并根据我的解决方案.这确实有帮助,但是当警告对话框显示时,UI线程上仍然有一个小挂起但只持续几秒钟.

https://github.com/wf9a5m75/phonegap-googlemaps-plugin/blob/master/src/android/plugin/google/maps/AsyncLicenseInfo.java

private class AsyncLoadLicenseInfo extends AsyncTask<Void,Void,AlertDialog.Builder>
{

    @Override
    protected void onPreExecute()
    {
        progressDialog = new ProgressDialog(context);
        progressDialog.setIndeterminate(true);
        progressDialog.setMessage(context.getResources().getString(R.string.LegalNoticesLoading));
        progressDialog.setCancelable(false);
        progressDialog.show();

    }

    @Override
    protected AlertDialog.Builder doInBackground(Void... params)
    {
        String googleAttribution = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(context);
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder
                .setTitle(context.getResources().getString(R.string.AboutLegalNotices))
                .setCancelable(false)
                .setMessage(googleAttribution)
                .setPositiveButton(context.getResources().getString(R.string.Close),null);

        return builder;
    }

    @Override
    protected void onPostExecute(AlertDialog.Builder builder)
    {

        AlertDialog attributionDialog = builder.create();
        attributionDialog.setOnShowListener(new DialogInterface.OnShowListener()
        {
            @Override
            public void onShow(DialogInterface dialog)
            {
                progressDialog.dismiss();
                progressDialog = null;

            }
        });

        attributionDialog.show();
    }
}
相关文章
相关标签/搜索