views:

100

answers:

4

I want to know what kind of users are using my app.

I think I need the device id, the network type, the network provider name and its ip address. is there any framework to do this thing? And of course I will ask user to enable it before I can do it and leave an option to disable it when user want to toggle it off.

+1  A: 

You could do this relatively easy by reading this information in your app programatically and then send it to you per sms, email, or just upload it to a server.

However, I don't think that the users will be very lucky that you're doing this. At least you have to inform them about that.

For a ID you could use this:

http://developer.android.com/reference/android/telephony/TelephonyManager.html#getDeviceId%28%29

To get the IP you could use this code:

public String getLocalIpAddress() {
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                    return inetAddress.getHostAddress().toString();
                }
            }
        }
    } catch (SocketException ex) {
        Log.e(LOG_TAG, ex.toString());
    }
    return null;
}

To get the network type (I think your talking about wifi or mobile) you can use this code snippet:

ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

//mobile
State mobile = conMan.getNetworkInfo(0).getState();

//wifi
State wifi = conMan.getNetworkInfo(1).getState();

and then use it like that:

if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) {
    //mobile
} else if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {
    //wifi
}
Roflcoptr
+1  A: 

You can use a service like Flurry or Google Analytics to gather some of this data (not sure about device ID or IP address), but as others have said, you might want to make this "opt-in" via an application preference due to privacy concerns.

Erich Douglass
A: 

Google has a full SDK for this very purpose. Documentation and details are available at: http://code.google.com/mobile/analytics/docs/android/

From the page:

The Google Analytics for Mobile Apps SDKs provide an interface for tracking activity within mobile apps and reporting that activity via the standard Google Analytics dashboard.

Tracking mobile applications has some structural variations from tracking website pages. For that reason, you should be familiar with Analytics tracking in order to understand how this SDK works.

Use the SDK to track two basic types of user interaction:

Pageviews - This is the standard unit of measure for a traditional web site, and is used to calculate visits, session length, and bounce rate. We recommend that you trigger at least one pageview at application load to track unique visitors. Because mobile apps don't contain HTML pages, you must decide when (and how often) to trigger a pageview request, and choose descriptive names for reporting purposes. The names you choose will be populated in your Analytics reports as page paths in the Content reports, even though they are not actually HTML pages.

Events - You can define additional events to be reported in the Event Tracking section of Google Analytics. Events are grouped using categories and may also use per-event labels, which provides flexibility in reporting. For example, a multimedia app could could have play/stop/pause actions for its video category and assign a label for each video name. The Google Analytics reports would then aggregate events for all events tagged with the video category. For more information on Event Tracking, see the Event Tracking Guide

thewinchester
A: 

You don't need to roll your own solution, there are plenty of free, off-the-shelf solutions which work and will let you focus on your app. I also recommend staying away from web analytics solutions because the application model is different so shoe-horning a mobile app into it can be strange. You don't think of your app as page views and referrals, do you?

Localytics is one solution: the service is free, the SDK is open source, and the turnaround time is instant so integration can be done and verified in 10 minutes.

Brian