Thursday, December 27, 2012

Include open source software license information/Legal Notices in your app using Google Maps Android API v2

If you use the Google Maps Android API in your application, you must include the Google Play Services attribution text as part of a "Legal Notices" section in your application. Including legal notices as an independent menu item, or as part of an "About" menu item, is recommended.

The attribution text is available by making a call to GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo.

source: Google Maps Android API v2 - Attribution Requirements.

open source software license information/Legal Notices for Google Maps Android API v2


To include menu option "Legal Notices" to display open source software license information in a dialog.:

Modify /res/values/strings.xml to include string resource of "menu_legalnotices".
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">AndroidMapsV2</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_legalnotices">Legal Notices</string>

</resources>


Modify /res/menu/activity_main.xml to add menu resource of "menu_legalnotices".
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/menu_legalnotices"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/menu_legalnotices"/>

</menu>


Modify the java code to override onOptionsItemSelected() to display "open source software license information" in dialog.
package com.example.androidmapsv2;

import com.google.android.gms.common.GooglePlayServicesUtil;

import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends FragmentActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 }
 
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
     case R.id.menu_legalnotices:
      String LicenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(
        getApplicationContext());
      AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(MainActivity.this);
      LicenseDialog.setTitle("Legal Notices");
      LicenseDialog.setMessage(LicenseInfo);
      LicenseDialog.show();
         return true;
     }
  return super.onOptionsItemSelected(item);
 }

}


download filesDownload the files.


The series:
A simple example using Google Maps Android API v2, step by step.

No comments:

Post a Comment