I want to add statistic in my android application.
Read article http://code.google.com/intl/ru/apis/analytics/docs/mobile/android.html#startingTheTracker and done below
1 added library libGoogleAnalytics.jar in my application
2 added in manifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
3 changed source code
private GoogleAnalyticsTracker tracker;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tracker = GoogleAnalyticsTracker.getInstance();
// Start the tracker in manual dispatch mode...
tracker.startNewSession(GOOGLE_ANALYTICS, this);
tracker.trackPageView("/MainListView");
...
protected void onDestroy() {
super.onDestroy();
tracker.stopSession();
}
4 I created "fake" site for application (https://sites.google.com/site/balancetransportcardkazan/ :) )
5 registered site in https://www.google.com/analytics/,
constant GOOGLE_ANALYTICS is for this site.
statistic is empty, What I forgot to do?
You have to dispatch the changes to the server. Here is an excerpt from my wrapper class around GoogleTracker to make it easier for me.
public void trackPageView(String page) {
tracker.trackPageView( packageName + "/" + getVersionCode() + "/" + page );
tracker.dispatch();
}
public void trackEvent(String action, String label, int count) {
tracker.trackEvent( packageName, action, label, count );
tracker.dispatch();
}
public void trackEvent(String action) {
tracker.trackEvent(packageName, action, null, 0 );
tracker.dispatch();
}
As mentioned by chubbard You need to dispatch the events to get it tracked. check your logs whether requests are sent to GA server. As i have seen it usually takes around 4-5 hours for statistics to get updated. While viewing the report ensure the report date is current date. By default the report will be shown for yesterday.
I think for getting statics of your android app, you should implement google analytics code into all your classes/functions of the your app.
I think below link can help you for How to implement Google Analytics for android app -
http://www.tatvic.com/blog/android-application-tracking-through-google-analytics/
Related
I am aware about the changes introduced in Android 6.0/SDKVersion 23 regarding the run-time permission. There is already discussion and talks on this topic in the below post which talks about the various aspects of new permission model.
"How to request permissions from a Service in Android Marshmallow"
Google I/O 2015 - Android M Permissions
"Mother, May I?" Asking for Permissions (Android Dev Summit 2015)
After going thorough these article,I believe below is suggested to "workaround" (as Service doesnot have UI support)this problem.
Check permission checkSelfPermission() in the context of
Service.
Notify it to status bar in case the permission is denied.
User would now click on status bar which would launch a new
DialogActivity to request for permission when users press on the
notification.
I am not able to make the workable version of the suggestions provided to achieve this task. When we launch DialogActivity to ask for permission, it would be assigned and available for that activity. It would not be applicable for background service who had put it on status bar and even after this service would not be granted this permission(instead the permission would be given to DialogActivity).
Could somebody provide the input(possibly workable logic/code) so that I can make it workable(.i.e. execute the code in the context of Service which would be dependent on whether permission is granted or not).
My Scenario
Develop application which would send the SMS at regular interval
regarding the my current location.
I have designed the UI for this application as mentioned below. It had some settings parameters and also buttons which would start the main logic which is:
Start monitoring the current location and
Send the SMS to configured contact numbers.
I believe user would minimize this application( as it does not have any interesting logic apart from sending the SMS) and it should continue to work in background(.i.e. monitoring the location and sending the SMS). Hence I thought to use move this logic in Service instead of keeping it the Activity itself. If I keep these logic in Activity itself, it works as expected however for that user is suppose to keep the application in foreground all the time.
So far I have been able to achieve the following:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Define START/STOP button handles.
mStartApp = (ImageButton)findViewById(R.id.startApp);
mStopApp = (ImageButton)findViewById(R.id.stopApp);
//Write event handlers for above grabbed buttons.
mStartApp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent startService = new Intent(getApplicationContext(),
CurrentLocationTrackerService.class);
startService(startService);
}
});
mStopApp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent stopService = new Intent(getApplicationContext(),
CurrentLocationTrackerService.class);
stopService(stopService);
}
});
// Support for the ActionBar widgets menu in current activity.
Toolbar mToolBar = (Toolbar)findViewById(R.id.myToolbar);
if(mToolBar != null) {
setSupportActionBar(mToolBar);
}
}
//Other methods.....
}
public class CurrentLocationTrackerService extends Service {
public CurrentLocationTrackerService() { }
#Override
public void onCreate() { }
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
int permissionLocationAccess = ContextCompat.checkSelfPermission(getApplicationContext(),
Manifest.permission.ACCESS_FINE_LOCATION);
// If permissionLocationAccess is true execute further
// If permissionLocationAccess false(which would always as we are in Service and it is dangerous
// permission) we need to put some information to status bar. Post that user would click on that
// which would launch some new activity where UI of asking permission would be shown. But still
// Service would not get the permission( only new activity would have that permission but it is
// of no use here as I am planning to put these logic iside the Service as my app may not be always
// be in foreground)
}
}
Hope I have provided all detail regarding the problem and also my application context regarding why I require to model in this way.The real point over here is how to achieve this.
I am really stuck at this point and any help would be highly appreciated. Kindly let me know in case anything else is required from my side.
I'm currently attempting to use AppSync to sync a piece of data between an android app and a pebble app. However, I seem to not be able to get the pebble to realize that any data is being transferred - that is, no logs are being produced where they should be. What is really bothering me is that this is essentially the code found in the pebble weather example. I've pasted the relevant bits of code below - could someone possibly look it over and suggest where any issues may be? I've made sure that the UUIDs in both programs (pebble app and android app) are the same, and that they are on the same network, and that the pebble is actually connected to the phone, and that the android function is actually being called and all.
Snippet of pebble app code:
static void sync_error_callback(DictionaryResult dict_error, AppMessageResult app_message_error, void *context) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "App Message Sync Error: %d", app_message_error);
}
static void sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) {
APP_LOG(APP_LOG_LEVEL_DEBUG, new_tuple->value->cstring);
}
void home_screen_load() {
// set up each one of the SimpleMenuItems
Tuplet initial_values[] = {
TupletCString(0x0, "Initial 1")
};
app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL);
}
Snippet of android app:
final UUID PEBBLE_APP_UUID = UUID.fromString("10549fd4-1fe4-4d30-8a18-6f2f8149f8fd");
public void sendDataToWatch(String toSend) {
// Build up a Pebble dictionary containing the weather icon and the current temperature in degrees celsius
PebbleDictionary data = new PebbleDictionary();
data.addString(0x0, toSend);
PebbleKit.sendDataToPebble(getApplicationContext(), PEBBLE_APP_UUID, data);
}
To debug this type of problem, you should set a inbox_dropped handler and see if you get anything there.
After initializing AppMessage and AppSync, call:
app_message_register_inbox_dropped(appmsg_in_dropped);
And add this function:
static void appmsg_in_dropped(AppMessageResult reason, void *context) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "In dropped: %s", translate_error(reason));
}
Take a look at this question for the source of the translate_error function.
I am writing a Spell Check client using the sample code in the SDK as an example. I have the following code (not actual implementation, but an accurate sample representation):
public class HelloSpellChecker implements SpellCheckerSessionListener {
private SpellCheckerSession mSpellCheckService;
private void bindService() {
final TextServicesManager tsm = (TextServicesManager) getSystemService(
Context.TEXT_SERVICES_MANAGER_SERVICE);
mSpellCheckService = tsm.newSpellCheckerSession(null, null, this, true);
}
public void getSuggestions(String word) {
mSpellCheckService.getSuggestions(new TextInfo("tgis"), 3);
}
#Override
public void onGetSentenceSuggestions(final SentenceSuggestionsInfo[] arg0) {
Log.d(TAG, "onGetSentenceSuggestions");
// Process suggestions
}
}
What I want to know is will onGetSentenceSuggestions only be fired when my application calls getSuggestions, or will it be fired any time the system service receives a request to getSuggestions?
If it is the latter, what is the best way to ensure my app only processes suggestions which it requested?
I would say Android system service listener is localized through the session in this case.
onGetSentenceSuggestions method is fired by any request to getSuggestions method. However, you don't have to worry about processing suggestions which your app requested since the spellchecker session takes care of it. Your app only gets the suggestions requested by the session your app created to interact with the spell checker service.
Hope this helps.
References:
http://developer.android.com/reference/android/view/textservice/SpellCheckerSession.html
http://developer.android.com/guide/topics/text/spell-checker-framework.html
I've been trying out Google Tag Manager for mobile devices, specifically Android but I keep getting a message saying "invalid macro" when trying getString(myKeyValue) on a Container.
Here's a part of my code in my MainActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtHello = (TextView)findViewById(R.id.txtHello);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
String hello = mContainer.getString("hello");
long l = mContainer.getLong("long");
txtHello.setText(hello + l);
}
});
tagManager = TagManager.getInstance(this);
ContainerOpener.openContainer(tagManager, CONTAINER_ID, OpenType.PREFER_NON_DEFAULT, null, new ContainerOpener.Notifier() {
#Override
public void containerAvailable(Container container) {
mContainer = container;
}
});
}
I've added these permissions in the manifest:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
I have the right Container_id because it shows the right version after refreshing it programmatically.
And this is my assets/tagmanager/CONTAINER_ID.json file (of course with the right filename):
{
'hello': 'hola',
'long' : '12345679'
}
So after my container is initialized, I press a button that runs the code above, trying to get the values. But I get the error: "Invalid macro: hello" and "Invalid macro: long", also
"Failed to convert '' to a number"
This is a new service for mobile devices but can anybody help me with this?
I've found a problem for my case. I just downloaded a version from the web browser manager.
The important thing is to add a rule that allows GTM to use this macro. Always comes in handy here.
Don't forget to publish the version of your container
For people not getting what dumazy referring to
you'll also need to enable it with Always or any other appropriate rules
In your json you are using '123456' quotas to define long, you should not:
{
'string': 'hola',
'long': 123456,
'double': 123.123
}
If you have further problems look on: Android TagManager not getting default values
Got a strange thing going on, I recently started counting visitors of my app, it was working fine. Ater a while I saw that on Google Analytics, you can point out if it is a website or mobile. I made a new profile with 'mobile' selected, replaced the code in my app, but since then, it isn't counting anymore.. I waited more then 24 hours.
I use
mGATracker = GoogleAnalyticsTracker.getInstance();
mGATracker.startNewSession("UA-xxxxxxxx-x", this);
mGATracker.trackPageView("/About");
And dispatch in the onDestroy method:
#Override
public void onDestroy() {
try {
super.onDestroy();
mGATracker.dispatch();
mGATracker.stopSession();
} catch (Exception error) {
Log.e("<YOUR_TAG>", "onDestroy: " + error.toString());
}
}
Anybody else experienced this?
GA ver 1 requires 'website' type of panel.