Groovy library in android - java

Please help me guys I'm stuck on this problem for over a week.
I'm working on an app which involves groovy. The app simply creates a pdf document with some information.
The part where the pdf is created is written in groovy. I wrote a small groovy library which takes some information and create a pdf document using pdfbox. This library was developed in IntelliJ IDEA and it works perfectly.
Now, the problem occurs when I try to integrate this groovy library with my android application. I managed to build an artifact of the groovy library and even import it to the android studio under libs folder, but when I try to run the main function of groovy library, the app crashes with a MissingPropertyException:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.silverfix.groovytestapp, PID: 8030
groovy.lang.MissingPropertyException: No such property: EMPTY_DOC for class: app.Constants$Paths
at groovy.lang.MetaClassImpl.invokeStaticMissingProperty(MetaClassImpl.java:1004)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1859)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1835)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3735)
at org.codehaus.groovy.runtime.callsite.ClassMetaClassGetPropertySite.getProperty(ClassMetaClassGetPropertySite.java:51)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)
at app.MainClass.initialize(MainClass.groovy:41)
at app.MainClass.main(MainClass.groovy:32)
at com.silverfix.groovytestapp.MainActivity$1.onClick(MainActivity.java:24)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Code for main class of the groovy library:
package app
import app.components.Evaluator
import app.components.FieldRenamer
import app.components.FormMetaHolder
import app.components.FieldPopulater
import app.components.entities.DGObject
import org.apache.pdfbox.cos.COSDictionary
import org.apache.pdfbox.cos.COSName
import org.apache.pdfbox.pdmodel.PDDocument
import org.apache.pdfbox.pdmodel.PDDocumentCatalog
import org.apache.pdfbox.pdmodel.PDPage
import org.apache.pdfbox.pdmodel.PDResources
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm
import org.apache.pdfbox.pdmodel.interactive.form.PDField
/**
* Created by David on 26/09/2016.
*/
class MainClass {
static PDDocument document = new PDDocument()
static void main(args) {
initialize()
initiateData()
initiatePdf()
populateData()
saveDocuemnt()
}
// Initialize the document's meta data
static void initialize() {
InputStream inputStream = MainClass.class.getClassLoader().getResourceAsStream("$Constants.Paths.EMPTY_DOC")
PDDocument tempDoc = new PDDocument().load(inputStream)
}
static void initiatePdf() {
...
}
static void initiateData() {
...
}
static void populateData() {
...
}
static void saveDocuemnt() {
...
}
}
Code for Constants class:
package app
/**
* Created by David on 09/10/2016.
*/
class Constants {
// Paths
public static class Paths {
public static final String RESULT_FILE = "intellijPDF.pdf"
public static final String EMPTY_DOC = "dgc_empty.pdf"
public static final String IATA_DOC = "dgc_iata.pdf"
public static final String SILVER_DOC = "dgc_silverfix.pdf"
}
}
And this is the MainActivity:
package com.silverfix.groovytestapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import app.MainClass;
public class MainActivity extends AppCompatActivity {
private Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.create_doc);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
MainClass.main(null);
}
});
}
}
Image of the Project hierarchy

add #CompileStatic try again.
#CompileStatic
public class MainClass {

To use Groovy library in Android project it is necessary to configure Groovy support for Android: https://github.com/groovy/groovy-android-gradle-plugin
After applying Groovy plugin to Android you can add your library as follows (assuming it is in libs directory):
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs') {
exclude group: 'org.codehaus.groovy'
}
compile 'org.codehaus.groovy:groovy:2.4.12:grooid'
...
}

Related

codename native Android application subclassing issues

My codenameone application crashes anything I use this native code
package com.mycompany.interfaces;
import android.app.Application;
import android.content.Context;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.messaging.FirebaseMessaging;
public class InitialiseApp extends Application{
private static Context context;
public static Context getContext() {
return context;
}
#Override
public void onCreate()
{
super.onCreate();
context = getApplicationContext();
try
{
FirebaseApp.initializeApp(this, new FirebaseOptions.Builder().
setApiKey("XXXXXXXXXXXXXX").
setApplicationId("XXXXXXXX").
setGcmSenderId("XXXXXXXXXX")
.build());
FirebaseInstanceId.getInstance().deleteInstanceId();
FirebaseInstanceId.getInstance().getToken("XXXXXXXXXX",FirebaseMessaging.INSTANCE_ID_SCOPE);
FirebaseMessaging.getInstance().subscribeToTopic("test");
}
catch(Exception c)
{
c.printStackTrace();
}
}
}
I declare the class in the android.xapplication_attr android:name="com.mycompany.interfaces.InitialiseApp"
Need a assistance
Are you putting this in the native interface stub or in the CN1 part of the code?
Also, I don’t think that’s how you get a context in CN1. Look in the developer guide and video tutorials for Native Interfaces. I also recall a series of blog posts about native interfaces that dive into writing the Android code. You’ll need to use something from the AndroidNativeUtil class like: AndroidNativeUtil.getActivity().

AsyncLoader - wont accept 'this'

This is a follow up to a question I asked here.
I have copied and pasted this code from this tutorial. When I paste it into Android Studio, the 'this' parameter of of content.getLoadManager.initLoader() is highlighted in red and shows the following error:
Wrong 3rd Argument Type. Found 'com.example.carl.loaderDemo.FooLoaderClient', requried: 'android.app.LoaderManager.LoaderCallBacks
I've ran into this previously (see first link). I was hoping this tutorial would help but I just seem to be going in endless circles!
Can anyone point me in the right direction?!
package com.example.carl.loaderdemo;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
public class FooLoader extends AsyncTaskLoader {
public FooLoader(Context context, Bundle args) {
super(context);
// do some initializations here
}
public String loadInBackground() {
String result = "";
// ...
// do long running tasks here
// ...
return result;
}
}
class FooLoaderClient implements LoaderManager.LoaderCallbacks {
Activity context;
// to be used for support library:
// FragmentActivity context2;
public Loader onCreateLoader(int id, Bundle args) {
// init loader depending on id
return new FooLoader(context, args);
}
#Override
public void onLoadFinished(Loader loader, Object data) {
}
public void onLoaderReset(Loader loader) {
// ...
}
public void useLoader() {
Bundle args = new Bundle();
// ...
// fill in args
// ...
Loader loader =
context.getLoaderManager().initLoader(0, args, this);
// with support library:
// Loader loader =
// context2.getSupportLoaderManager().initLoader(0, args, this);
// call forceLoad() to start processing
loader.forceLoad();
}
}
Screenshot of error message:
There is a mismatch in your imports:
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
But you need
import android.app.LoaderManager;
import android.content.AsyncTaskLoader;
import android.content.Loader;
You cannot mix the support library with the android framework. Alternatively you can subclass FragmentActivity and call getSupportLoaderManager() instead.
You're implementing android.support.v4.app.LoaderManager.LoaderCallbacks but the client is expecting android.app.LoaderManager.LoaderCallbacks. You need to be consistent in which loader API you're using.

NFC on Android using JavaFX Ports

I have been recently experimenting with JavaFXPorts and I have been trying to use it to build a native Android app. For the application I'm building I am trying to bake in NFC support but there doesn't seem to be much information out there about this. The only useful guide I found so far was some sample code written by johanvos on his BitBucket Repo here.
The problem I am facing now is using this code snippet, Netbeans keeps on reporting that the android libraries I'm trying to reference don't exist.
This is a some of my code:
package com.afropolymath.waitress;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
import android.content.Context;
import android.nfc.NfcAdapter;
import android.nfc.NfcAdapter.ReaderCallback;
import android.nfc.Tag;
import android.os.Bundle;
import javafxports.android.FXActivity;
public class Waitress extends Application implements ReaderCallback {
private Stage stage;
private StackPane rootLayout;
#Override
public void start(Stage stage) {
this.stage = stage;
this.initLayout();
Context ctx = FXActivity.getInstance();
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(ctx);
nfcAdapter.enableReaderMode(FXActivity.getInstance(), this, NfcAdapter.FLAG_READER_NFC_A, Bundle.EMPTY);
}
public void initLayout() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/RootLayout.fxml"));
rootLayout = (StackPane) loader.load();
Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
Scene scene = new Scene(rootLayout, visualBounds.getWidth(), visualBounds.getHeight());
stage.getIcons().add(new Image(Waitress.class.getResourceAsStream("/assets/icon.png")));
stage.setScene(scene);
stage.show();
} catch (IOException e) {
}
}
#Override
public void onTagDiscovered(Tag tag) {
}
}
And these are the errors I'm getting:
/Users/chidieberennadi/NetBeansProjects/Waitress/src/main/java/com/afropolymath/waitress/Waitress.java:12: error: package android.content does not exist
import android.content.Context;
^
/Users/chidieberennadi/NetBeansProjects/Waitress/src/main/java/com/afropolymath/waitress/Waitress.java:13: error: package android.nfc does not exist
import android.nfc.NfcAdapter;
^
/Users/chidieberennadi/NetBeansProjects/Waitress/src/main/java/com/afropolymath/waitress/Waitress.java:14: error: package android.nfc.NfcAdapter does not exist
import android.nfc.NfcAdapter.ReaderCallback;
^
/Users/chidieberennadi/NetBeansProjects/Waitress/src/main/java/com/afropolymath/waitress/Waitress.java:15: error: package android.nfc does not exist
import android.nfc.Tag;
^
/Users/chidieberennadi/NetBeansProjects/Waitress/src/main/java/com/afropolymath/waitress/Waitress.java:16: error: package android.os does not exist
import android.os.Bundle;
^
Any ideas on what might have been the problem?
While Johan Vos' NFC project works, it is based on the use of android and dalvik dependencies on the main package:
dependencies {
compile files("${ANDROID_HOME}/platforms/android-21/android.jar")
compile "org.javafxports:jfxdvk:8u60-b3"
}
But JavaFXPorts it's intended to create projects that can be deployed on different platforms, so now if you create a project using the Gluon's Plugin for NetBeans, you'll find four different folders to place the code:
Source Packages [Java], for all the common code, shared with all the platforms
Desktop/Java Packages, for Java code, only available running on Desktop
Android/Java Packages, for Java or Android code, only available running on Android
Ios/Java Packages, for Java code, only available running on iOS.
Also, if you check the project dependencies, you'll notice that the android.jar is available only for Android.
This means that you should create your regular project on the main package, and add the android part only in the Android package. In order to call the android class, you'll need to provide some mechanism on the main package to create an instance of it.
If you check the HelloPlatform sample, you'll notice that a PlatformService is used to load the classes depending on the platform, while PlatformProvider is an interface with the method/s that can be called from the main package, but will have the implementation given to each platform.
With this idea, but using Class.forName() instead of the service, Gluon Charm-Down library implements different native services.
You can have a look also at the GoNative sample and post that explains it in detail.
In case you want to implement a new service, like the NFC for Android,
these are the possible classes required.
Main package
NFCPlatform
public abstract class NFCPlatform {
public abstract NFCService getNFCService();
}
NFCService
public interface NFCService {
boolean isAvailable();
boolean isEnabled();
StringProperty tagIdProperty();
// other methods
}
Android Package
AndroidNFCPlatform
public class AndroidNFCPlatform extends NFCPlatform {
private AndroidNFCService nfcService;
#Override
public NFCService getNFCService() {
if (nfcService == null) {
nfcService = new AndroidNFCService();
}
return nfcService;
}
}
AndroidNFCService
Your implementation of the NFC service. Here we can use Android API. NetBeans won't complain.
This is a minimal implementation:
public class AndroidNFCService implements NFCService, ReaderCallback {
private final NfcAdapter nfcAdapter;
private StringProperty tagId;
public AndroidNFCService() {
NfcManager manager = (NfcManager) FXActivity.getInstance().getSystemService(FXActivity.NFC_SERVICE);
nfcAdapter = manager.getDefaultAdapter();
}
#Override
public boolean isAvailable() {
return nfcAdapter != null;
}
#Override
public boolean isEnabled() {
return isAvailable() && nfcAdapter.isEnabled();
}
#Override
public StringProperty tagIdProperty() {
if (tagId == null) {
tagId = new SimpleStringProperty();
}
return tagId;
}
#Override
public void onTagDiscovered(Tag tag) {
Platform.runLater(() ->
tagIdProperty().set(new String(tag.getId())));
}
}
Finally, you can use this service on your main class, once you get an instance of the NFCPlatform.
public static NFCPlatform getNFCPlatform() {
try {
if ("android".equals(System.getProperty("javafx.platform", "desktop"))) {
return (NFCPlatform) Class.forName("<your package>.AndroidNFCPlatform").newInstance();
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
System.out.println("Error " + ex);
}
return null;
}
#Override
public void start(Stage stage) {
NFCService nfcService = getNFCPlatform().getNFCService();
if (nfcService != null) {
System.out.println("Available: " + nfcService.isAvailable());
...
}
}

JBehave-Junit-Runner throwing NullPointerException

I am new to JBehave and am attempting to use the JBehave-JUnit-Runner to display test results nicely in JUnit in Eclipse Luna (on Ubuntu 12.04). I am using JBehave-JUnit-Runner 1.1.2, JUnit 4.12-beta-1 and JBehave-core 4.0-beta-9. When I right-click on my story file and 'Run as JUnit Test' all is well. However, when I put the #RunWith(JUnitReportingRunner.class) at the top of my story class as required for JBehave-JUnit-Runner, I get the following error:
java.lang.RuntimeException: java.lang.NullPointerException
at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.run(JUnitReportingRunner.java:80)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.NullPointerException
at de.codecentric.jbehave.junit.monitoring.JUnitScenarioReporter.afterStory(JUnitScenarioReporter.java:114)
at org.jbehave.core.reporters.DelegatingStoryReporter.afterStory(DelegatingStoryReporter.java:49)
at org.jbehave.core.reporters.ConcurrentStoryReporter.afterStory(ConcurrentStoryReporter.java:120)
at org.jbehave.core.embedder.PerformableTree.performBeforeOrAfterStories(PerformableTree.java:399)
at org.jbehave.core.embedder.StoryManager.performStories(StoryManager.java:102)
at org.jbehave.core.embedder.StoryManager.runStories(StoryManager.java:93)
at org.jbehave.core.embedder.StoryManager.runStoriesAsPaths(StoryManager.java:74)
at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:204)
at de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner.run(JUnitReportingRunner.java:78)
... 6 more
Here is my utility class for testing. One method, very basic:
package org.felimar;
public abstract class StringManipulation
{
public static boolean stringBlank(final String src)
{
return src.matches("^\\s*$"); //$NON-NLS-1$
}
}
The story file for JBehave:
Utilities for managing character strings
Narrative:
In order to easily manipulate and investigate character strings
As a development team
I want to use a group of string-related utilities
Scenario: A string contains zero or more characters
Given a source string with value <value>
Then the method should return <return>
Examples:
|value|return|
|""|true|
|" "|true|
|"Normal Non-Blank"|false|
The steps class:
package org.felimar.steps;
import static org.felimar.StringManipulation.stringBlank;
import org.felimar.StringManipulation;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Named;
import org.jbehave.core.annotations.Then;
public class StringManipulationSteps
{
private String m_srcString;
public String getSrcString()
{
return m_srcString;
}
#Given("a source string with value $value")
public void givenValue(#Named("value") final String srcString)
{
setSrcString(srcString);
}
public void setSrcString(final String srcString)
{
m_srcString = srcString;
}
#Then("the method should return $value")
public void stringBlankRtrns(#Named("value") final boolean isBlank)
{
if (stringBlank(getSrcString()) != isBlank)
throw new RuntimeException("stringBlank did not determine *" +
getSrcString() + "* was " + isBlank);
}
}
And finally, the story class:
package org.felimar.stories;
import static java.util.Arrays.asList;
import static org.jbehave.core.reporters.Format.CONSOLE;
import static org.jbehave.core.reporters.Format.TXT;
import java.util.List;
import org.felimar.StringManipulation;
import org.felimar.steps.StringManipulationSteps;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;
import org.junit.runner.RunWith;
import de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner;
#RunWith(JUnitReportingRunner.class)
public class StringManipulationStories extends JUnitStories
{
public StringManipulationStories()
{
super();
super.useConfiguration(
new MostUsefulConfiguration().useStoryReporterBuilder(
new StoryReporterBuilder().withDefaultFormats().withFormats(
CONSOLE, TXT)));
}
#Override
public InjectableStepsFactory stepsFactory()
{
return new InstanceStepsFactory(configuration(),
new StringManipulationSteps());
}
#Override
protected List<String> storyPaths()
{
return asList("org/felimar/stories/StringManipulationStories.story");
}
}
Are there any obvious errors in any of the code, or should I step back from using the beta libraries?
I found the problem was with the JUnit-4.12-beta-1. I had my Gradle build script set to 4.+, so I changed it to specify 4.11 and the problem disappeared. The JBehave-core 4.0-beta-9 seems to work just fine, so I left that in place.
I also experimented with using JUnitReportingRunner.recommandedControls(configuredEmbedder()); as the last line of the constructor, but it actually threw up an extra error.
My thanks to Andreas for his helpful suggestions - they were very much appreciated and ultimately helped me solve my problem.
Kind regards,
Flic

New Google Analytics SDK 4

Im having some trouble setting up Google Analytics on my Android app. Could any one help me out and point me to some sample code or tutorial. Im trying to follow this one
Heres my code:
package com.examp2.testq;
import java.util.HashMap;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
:
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
Im not sure what to do with the PROPERTY ID or how to call it?
Thanks!
Put the following line inside MainActivity:
private static final String PROPERTY_ID = "UA-xxxxx-x";
private Tracker tracker;
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
replacing UA-xxxxx-x with the tracking id for your app.
I'm using Google Analytics in an app that is only one screen, so my MainActivity onCreate method looks like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GoogleAnalytics.getInstance(this).newTracker(PROPERTY_ID);
GoogleAnalytics.getInstance(this).getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
tracker = getTracker(TrackerName.APP_TRACKER);
tracker.setScreenName("MainActivity");
tracker.send(new HitBuilders.AppViewBuilder().build());
setContentView(R.layout.main);
//...etc.
This is enough for a ton of useful data in Analytics.
You'll have to add the following includes:
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Logger;
import com.google.android.gms.analytics.Tracker;
import com.google.android.gms.analytics.GoogleAnalytics;
Don't forget to add the following permissions before the <application> tag inside the <manifest> tag of AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Google also says to add the following tag inside the <application> tag.
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Lastly, if you're using Android Studio, Google says to add the following lines to proguard-rules.txt:
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames #com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
#com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
...and also this dependency to your project's build.gradle file:
apply plugin: 'android'
...
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.3.23'
}
Property id is simply a string of the format UA-XXXXXX-Y. It is also called the tracking id, webproperty id etc. You can get this from the admin settings of Google Analytics account. Most likely you already have it.
There are basically two ways of getting a tracker. You can create it from an xml file. If you are doing that, you need to use public Tracker newTracker (int configResId)
The second method is to use public Tracker newTracker (String trackingId). In your code snippet, you are using the second method.
Try this tutorial https://developers.google.com/analytics/devguides/collection/android/v4/
and this https://developers.google.com/analytics/devguides/collection/android/v4/events
hope this helps.
Property id i the "UA-XXXXXX-Y" In admob i think, you can create this trackig ID.

Categories