我正在使用Eclipse为android开发应用程序,我想集成Admob来赚钱。教程说我应该观看LogCat来查找ID,但是它在哪里呢?
当我在测试模式或真实模式下运行时,有时eclipse会通知广告返回,但它不会在emu中显示。有谁能解释一下吗?
发布于 2010-12-24 16:00:26
如果你是在模拟器上运行admob广告,那么就没有If。只需使用AdManager方法并将其设置为TEST_EMULATOR,就像logcat所说的那样。如果你在一个实际的usb调试设备上运行,并观察logcat,ID就会出现在那里。
发布于 2013-08-08 06:06:10
如果您仅在Emulator或少数设备上进行测试,则接受的答案将起作用,但如果您在大量设备上进行测试,则可能需要按比例添加正在运行的设备的设备ID。
以下代码将以编程方式将当前运行的设备转换为adview测试设备
...
if(YourApplication.debugEnabled(this)) //debug flag from somewhere that you set
{
String android_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
String deviceId = md5(android_id).toUpperCase();
mAdRequest.addTestDevice(deviceId);
boolean isTestDevice = mAdRequest.isTestDevice(this);
Log.v(TAG, "is Admob Test Device ? "+deviceId+" "+isTestDevice); //to confirm it worked
}
您需要使用Android ID的md5,且必须为大写。下面是我使用的md5代码
public static final String md5(final String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest
.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {
String h = Integer.toHexString(0xFF & messageDigest[i]);
while (h.length() < 2)
h = "0" + h;
hexString.append(h);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
Logger.logStackTrace(TAG,e);
}
return "";
}
编辑:显然,MD5的方法并不完美,有人建议尝试https://stackoverflow.com/a/21333739/2662474我不再需要这个功能了,所以我没有测试。祝好运!
发布于 2014-07-09 19:35:22
获取散列设备ID
在oncreate中
String android_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
String deviceId = md5(android_id).toUpperCase();
Log.i("device id=",deviceId);
然后为md5 ()添加这个类
public String md5(String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i=0; i<messageDigest.length; i++)
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
https://stackoverflow.com/questions/4524752
复制相似问题