您可以使用 Flurry 或 Google Analytics 来收集其中一些数据(不确定设备 ID 或 IP 地址),但正如其他人所说,您可能出于隐私考虑,希望通过应用程序首选项进行此“选择加入”。
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.
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;
}
获取网络类型(我认为您谈论的是 wifi 或移动)您可以使用此代码片段:
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
//mobile
State mobile = conMan.getNetworkInfo(0).getState();
//wifi
State wifi = conMan.getNetworkInfo(1).getState();
然后像这样使用它:
if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) {
//mobile
} else if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {
//wifi
}
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.
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
}
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.
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
发布评论
评论(4)
您可以使用 Flurry 或 Google Analytics 来收集其中一些数据(不确定设备 ID 或 IP 地址),但正如其他人所说,您可能出于隐私考虑,希望通过应用程序首选项进行此“选择加入”。
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.
您可以通过以编程方式在应用程序中读取此信息,然后通过短信、电子邮件将其发送给您,或者只是将其上传到服务器来相对轻松地完成此操作。
然而,我不认为用户会因为你这样做而感到非常幸运。至少你必须告知他们这一点。
对于 ID,您可以使用以下内容:
http:// developer.android.com/reference/android/telephony/TelephonyManager.html#getDeviceId%28%29
要获取 IP,您可以使用以下代码:
获取网络类型(我认为您谈论的是 wifi 或移动)您可以使用此代码片段:
然后像这样使用它:
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:
To get the network type (I think your talking about wifi or mobile) you can use this code snippet:
and then use it like that:
您不需要推出自己的解决方案,有很多免费的现成解决方案可以工作,让您专注于您的应用程序。我还建议远离网络分析解决方案,因为应用程序模型不同,因此将移动应用程序硬塞进去可能会很奇怪。您不认为您的应用程序是页面浏览量和推荐,是吗?
Localytics 是一种解决方案:该服务是免费的,SDK 是开源的,并且周转时间是即时的,因此可以在 10 分钟内完成集成和验证。
[免责声明:这是我的网站]
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.
[Disclaimer: this is my site]
Google 为此提供了完整的 SDK。文档和详细信息可在以下位置获取:
http://code.google.com/mobile/analytics/docs/android/< /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: