I've added Google Analytics to my mobile application by using the google-services.json file.
Now I've enabled auto activity tracking and I want to provide a screen name for each activity.
Google documents say, I should add
<screenName name=".MyActivity">My activity</screenName>
to my XML configuration file. Where's this coming from? I don't have a xml config file, I have a google-services.json file.
Do I need to create a XML file inside res/xml/ ?
What values are necessary as I am currently using the android default R.xml.global_tracker ?
Or do I need to add these screen-name information to the json file and if yes, whats the structure then?
Thanks in advance.
You could create your own XML. Here is mine, remember to replace your tracking ID:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="ga_trackingId" translatable="false">UA-99999999-1</string>
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<!-- The screen names that will appear in reports -->
<screenName name="com.codylab.squats.MainActivity">MainActivity</screenName>
<screenName name="com.codylab.squats.SettingsActivity">SettingsActivity</screenName>
<screenName name="com.codylab.squats.BreakActivity">BreakActivity</screenName>
<screenName name="com.codylab.squats.FinishedActivity">FinishedActivity</screenName>
<screenName name="com.codylab.squats.InitialActivity">InitialActivity</screenName>
<screenName name="com.codylab.squats.WorkoutActivity">WorkoutActivity</screenName>
</resources>
Create an Application class:
public class YourNameApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
// To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
analytics.newTracker(R.xml.squats_tracker);
}
}
Add a name attribute of application tag in your AndroidMenifest.xml
...
<application
android:name=".YourNameApplication"
...>
...
</application>
Related
I created a separate layout for tablets in android studio, but I'm unable to run that particular layout, whenever I try to run it, it default runs the normal layout, which is for mobile
I have to agree with the user Ricardo but having said that, I need some more information. First of all how you load the layout, what is the layout name and where did you place these layouts.
Check this before https://developer.android.com/training/multiscreen/screensizes.html and you have to do something like this.
In your manifest
<resources>
<bool name="isTablet">true</bool>
</resources>
<resources>
<bool name="isTablet">false</bool>
</resources>
In your Mainactivity
boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
// do something
} else {
// do something else
}
I'm working with android studio to develop Android app. I'm working on the creation of a template to use in my applications. I have read the Android IDE Template Format specification and so i start my personal template starting from Dummy template.
I have a .ftl file with the following line of code:
<applicationGestureListenerClazz>${projectPackageName}.listeners.${projectShortName}GestureListener</applicationGestureListenerClazz>
When i execute the template i obtain the following line:
<applicationGestureListenerClazz>org.abubu.dummy.listeners.DummyGestureListener
</applicationGestureListenerClazz>
The variables are correctly defined (in other file they work fine). I don't known why.. it add a CRLF after this line.
Anybody has analogue problem?
UPDATE
I discover that the problem is linked to extension of output file. For example. I have a file **license_key_strings.txt.ftl* that contains:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- public key di ${projectPackageName}.key-->
<string name="publicKey">${licenseKey}</string>
</resources>
<!-- fine -->
If i use it to create a xml file
<instantiate from="root/key/src/main/res/values/license_key_strings.txt.ftl" to="${keyBaseDir}/src/main/res/values/license_key_strings.xml"/>
I obtain this file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- public key di org.dummy.key-->
<string name="publicKey">
MIIBIjANBgkqhkiG9w0BAQ
</string>
</resources>
But the output filename ends with .txt
<instantiate from="root/key/src/main/res/values/license_key_strings.txt.ftl" to="${keyBaseDir}/src/main/res/values/license_key_strings.txt"/>
The final output become:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- public key di org.dummy.key-->
<string name="publicKey">MIIBIjANBgkqhkiG9w0BAQ</string>
</resources>
<!-- fine -->
I'm working with Android Studio 1.4
Is it possible to specify multiple keys for Google Maps Android API in the same code base?
It looks like I have to change the key in manifest file each time I change keystore. It's not very convenient, imho, if you need to test the app signed with keys form debug and release keystores.
I added both keys in the manifest at once. Like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
..
android:versionCode="1"
android:versionName="1.0" >
<!-- RELEASE key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my-release-keu" />
<!-- DEBUG key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my-debug-key" />
</application>
</manifest>
Apparently, this works. Looks like Google code is smart enough to use relevant key automatically.
I don't think this is what you want to do. You should add both debug and release SHA1 key to API key on Google Developer API Console. Take a look at this answer
AFAIK, there is no programmatical form on doing this. For comodity, you can define API keys in strings.xml, and retrieve it from the manifest
String debugMapKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String releaseMapKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String mapKey = BuildConfig.DEBUG ? debugMapKey : releaseMapKey;
MapView mv = new MapView(this, mapKey);
Here's one that's driving me crazy:
I have recently started looking into Appcelerator Titanium. I have built a few small apps both with a normal project and using Alloy so I understand the basics at least.
One thing I just cannot get working is the i18n folder/files.
Here is what ive done:
- Create a "Default Project"
- add folder to root directory "i18n"
- add "en" and "es" folder to "i18n"
- add "strings.xml" to both those new folders.
- added:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Welcome TEST</string>
</resources>
to both the strings.xml, except in the es strings I put "ES Welcome TEST".
- In Resources -> app.js I changed "I am Window 1" to L('welcome_message')
- Ran the application
Both the normal and alloy versions just show a blank screen. I would like to get my alloy app working the most but from what I understand the localization code should work the same in both apps. In alloy I may just have to put it in the style.
Any pointers would be great! I have looked at other post claiming its not working but all of them were either syntax errors or just set it up wrong. I have copied their code and have the exact same issue with it not working so I have a feeling im missing a newbie step.
-- Here are some screenshots, I just created a brand new regular(not alloy) project, added the code above and try to use L('welcome_message') to no luck. I tried installing everything on a new PC to make sure I wasn't messing anything up on my main computer.
Heres the answer:
https://wiki.appcelerator.org/display/guides/Internationalization
Ends up by default your manifest file is not setup by default to allow localization UNLESS you choose a tabbed project.
Kinda silly if you ask me.
For the topic poster:
My new string.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Don't Help Austin</string>
<string name="user_agent_message">user agent set to</string>
<string name="format_test">Your name is %s</string>
<string name="base_ui_title">Base UI</string>
<string name="controls_win_title">Controls</string>
<string name="phone_win_title">Phone</string>
<string name="platform_win_title">Platform</string>
<string name="mashups_win_title">Mashups</string>
<string name="ordered">Hi %1$s, my name is %2$s</string>
</resources>
Screenshot of my non-Alloy experiment:
For those looking to answer the question in the topic, this is a possible answer below.
My i18n folder is on the same hierarchy level as app and plugins, so mine isn't inside the app folder like the rest of the Alloy resources.
index.xml
<Alloy>
<Window class="container">
<Label id="label" onClick="doClick"></Label>
</Window>
</Alloy>
index.tss
".container": {
backgroundColor:"white"
},
"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000",
text: L("welcome_message")
}
strings.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Welcome to Kitchen Sink for Titanium</string>
<string name="user_agent_message">user agent set to</string>
<string name="format_test">Your name is %s</string>
<string name="base_ui_title">Base UI</string>
<string name="controls_win_title">Controls</string>
<string name="phone_win_title">Phone</string>
<string name="platform_win_title">Platform</string>
<string name="mashups_win_title">Mashups</string>
<string name="ordered">Hi %1$s, my name is %2$s</string>
</resources>
When I placed the L("welcome_message") inside the index.xml, it didn't work.
I'm using beta 4 of google analytics V2 within my android app. For convenience I'm wrapping it in a separate class (singleton) like this:
private AnalyticsTracker(Context context) {
GAServiceManager.getInstance().setDispatchPeriod(5);
GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(context);
googleAnalytics.setDebug(true);
tracker = googleAnalytics.getTracker(context.getString(R.string.ga_trackingId));
}
For further usage I use the EasyTracker for activity tracking and the tracker member variable for event tracking.
public void onActivityStart(Activity activity) {
EasyTracker.getInstance().activityStart(activity);
}
public void onActivityStop(Activity activity) {
EasyTracker.getInstance().activityStop(activity);
}
public void trackEvent(AnalyticsEvent event) {
tracker.sendEvent(event.category, event.action, event.label, 0L);
GAServiceManager.getInstance().dispatch();
}
The problem is that setDebug(true) in the constructor seems to be ignored as there is no output on LogCat and my interaction appears in the reports. I'm not setting the debug flag in the analytics.xml.
If I do so and set the flag to true in the xml file it works as expected and analytics logs the events to LogCat.
Any idea why it ignores the call from the code?
Thanks
Use <bool name="ga_debug">false</bool> in analytics.xml in values folder for enableing disabling debug.
analytics.xml:
<!-- Replace placeholder ID with your tracking ID -->
<string name="ga_trackingId">UA-123456-2</string>
<!-- Enable automatic activity tracking -->
<bool name="ga_autoActivityTracking">true</bool>
<!-- Enable automatic exception tracking -->
<bool name="ga_reportUncaughtExceptions">true</bool>
<!-- Enable debug -->
<bool name="ga_debug">false</bool>
<!-- The screen names that will appear in your reporting -->
<string name="com.example.myapp.MainActivity">any name</string>
<!--The inverval of time after all the collected data should be sent to the server, in seconds.-->
<integer name="ga_dispatchPeriod">30</integer>
Ref: link