Use the Alert Dialogs example as a starting point.....
Add this icon to your src\main\android\res\drawable directory
I grabbed that icon from the Tango project, but had to change the filename to be compatable with Android.
Then from the Google Analytics example, create an analytics profile, update your pom.xml and AndroidManifest.xml
Instead of putting the tracker code directly into the onCreate method, let's move that into the "I Accept!" button. Note the change to onDestroy as well!
public class DisclaimerTestActivity extends Activity {private static String TAG = "DisclaimerTest";private GoogleAnalyticsTracker tracker = null;
public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
AlertDialog dialog = new AlertDialog.Builder(this).create();dialog.setTitle("Disclaimer");dialog.setMessage("In order to provide support for this application, we reserve the right to anonymously track and report usage information in this application. We will track which parts of the application are popular but will not track who you are or what you type / look at.");dialog.setIcon(R.drawable.network);dialog.setButton("I Accept!", new DialogInterface.OnClickListener(){public void onClick(DialogInterface dialogInterface, int i) {tracker = GoogleAnalyticsTracker.getInstance();tracker.start("UA-YOUR-ACCOUNT-HERE", DisclaimerTestActivity.this);setContentView(R.layout.main);track("/");dispatch();return;}});dialog.setButton2("No Way!", new DialogInterface.OnClickListener(){public void onClick(DialogInterface dialogInterface, int i) {finish();return;}});dialog.show();}
@Overrideprotected void onDestroy(){super.onDestroy();if(tracker != null) tracker.stop();}
// track("Clicks", "Button", "clicked", 77private void track(String category, String action, String label, int value){tracker.trackEvent(category, action, label, value);}
// track("/testApplicationHomeScreen");// track("/download");private void track(String page){tracker.trackPageView(page);}
// Allows sending in bulk by queuing up multiple tracks before calling dispatch// timestamps based on when dispatch is calledprivate void dispatch(){tracker.dispatch();}}
Redeploy (mvn clean install). Now, if you accept the disclaimer it will do analytic notifications (which can take up to 24 hours to show up). If you cancel, it will just close the app.
No comments:
Post a Comment