如何收集用户数据, 操作系统版本,手机型号等使用电子邮件内容中的EXTRA_TEXT?
答案 0 :(得分:0)
要获取操作系统版本,只需使用var theBigWeddingBook = angular.module('theBigWeddingBook');
theBigWeddingBook.controller('RegCtrl', function ($scope, $firebaseAuth, $firebaseObject) {
var ref = new Firebase("https://the-big-wedding-book.firebaseio.com");
var reg = $firebaseAuth(ref);
ref.onAuth(function(authData) {
if (authData) {
console.log("Authenticated with uid:", authData.uid);
} else {
console.log("Client unauthenticated.")
}
});
$scope.user = {};
$scope.addUser = function() {
var username = $scope.user.email;
var password = $scope.user.password;
var uid = $scope.user.uid;
reg.$createUser({
email: username,
password: password
}).then(function(user) {
console.log('User has been successfully created!');
return reg.$authWithPassword({ email: username, password: password });
}).catch(function(error) {
console.log(error);
})
};
ref.onAuth(function(authData) {
ref.child('user').child(authData.uid).set(authData).then(function(auth) {
console.log('Data Saved Successfully!');
}).catch(function(error) {
console.log(error);
})
})
})
对于设备型号,您可以使用
Build.VERSION.RELEASE
然后,当您想将其包含在emailIntent的文本中时,只需使用:
public static String getDeviceModel() {
return Build.MANUFACTURER + " " + Build.MODEL;
}
答案 1 :(得分:0)
您可以创建一个单独的类:
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
public class Utils {
public static String buildDeviceUserInformation(Context context) {
StringBuilder builder = new StringBuilder();
builder.append(String.format("Device: %s\n", getDeviceName()));
builder.append(String.format("OS: %s\n", Build.VERSION.RELEASE));
builder.append(String.format("App Version: %1$s/%2$s\n", getAppVersion(context), getAppVersionCode(context)));
String carrierName = getCarrier(context);
if(!TextUtils.isEmpty(carrierName))
builder.append(String.format("Carrier: %1$s\n", carrierName));
return builder.toString();
}
public static String getCarrier(Context context) {
try {
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
return manager.getNetworkOperatorName();
}
catch (Exception e) {
return "";
}
}
public static String getDeviceName() {
String device = Build.MANUFACTURER;
if(!TextUtils.isEmpty(Build.MODEL)) {
device = TextUtils.isEmpty(device) ? Build.MODEL : device + " " + Build.MODEL;
}
return device;
}
public static String getAppVersion(Context context) {
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
return "";
}
}
public static Integer getAppVersionCode(Context context) {
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
} catch (PackageManager.NameNotFoundException e) {
return null;
}
}
}
然后在你的意图中使用它就像这样:
emailIntent.putExtra(Intent.EXTRA_TEXT, Utils.buildDeviceUserInformation(AboutMeActivity.this));
输出看起来像这样:
Device: LGE Nexus 5
OS: 6.0.1
App Version: 10.70/1070