I'm trying to add, in my android app, the legal notices for Google Maps v2 API, that can be obtained calling: GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo()
So, my code is the following:
String LicenseInfo = GooglePlayServicesUtil
      .getOpenSourceSoftwareLicenseInfo(getApplicationContext());
AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(MyActivity.this);
LicenseDialog.setTitle("Lagal Notices");
LicenseDialog.setMessage(LicenseInfo);
LicenseDialog.show();
But when I execute this code, the system required about 10 seconds before the dialog is shown (considering that my device is a OnePlus One, it seems pretty strange) .
If I try to replace the LicenseInfo with a simple (shorter) string, the Dialog is open pretty fast. So I think that the problem is the length of the legal notices information retrieved from the Google play utils.
How can I solve this problem?
I had the same problem, but I found this on GitHub and based my solution on it. This does help but when the alert dialog shows, there is still a small hang on the UI thread but only for a few seconds.
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();
    }
}
As tasomaniac suggested, using WebView instead of TextView works without problems - there is just a small delay.
Here is the complete code to show the dialog:
private void legalDialog(){
        String licenseInfo =  GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this);
        licenseInfo = licenseInfo.replace("\n", "<br/>");
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.legal_notice);
        WebView webView = new WebView(this);
        webView.loadData("<html><body>"+licenseInfo+"</body></html>", "text/html", "utf-8");
        WebSettings webSettings = webView.getSettings();
        webSettings.setDefaultFontSize(12);
        builder.setView(webView);
        builder.setPositiveButton(R.string.dialog_close, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        final AlertDialog createDialog = builder.create();
        createDialog.show();
    }
Make sure to check if GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this) doesn't return null, before calling legalDialog().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With