我怎样才能触发com.google.android.gms包.actions.SEARCH

主题 : 求助,找不到import com.google.android.gms.appstate.AppStateM
级别: 新手上路
可可豆: 34 CB
威望: 34 点
在线时间: 37(时)
发自: Web Page
来源于&&分类
求助,找不到import com.google.android.gms.appstate.AppStateM&&&
本人移植项目,缺少com.google.android.gms文件夹下面的N个文件,不知道从哪里找回这些文件,请教高手,谢谢指导!
图片:QQ截图23.png
级别: 新手上路
可可豆: 34 CB
威望: 34 点
在线时间: 37(时)
发自: Web Page
顶一下,不要沉底,希望有人能帮我一下,初学cocos2dx,以前做unity3d,差别太大,可能影响了我对cocos2dx的认知。坐等高手
级别: 新手上路
可可豆: 13 CB
威望: 13 点
在线时间: 4(时)
发自: Web Page
你是要加googleplayservice么
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版developerWorks 社区
软件工程师,IBM Mobile Cloud Services软件工程师,IBM Mobile Cloud Services软件工程师,IBM Mobile Cloud Services
中已经介绍过,BlueList 应用程序是一个简单的 Android 应用程序,允许您在云中创建一个列表(在本例中为一个杂货列表),您和指定的用户可以维护和更新该列表。在本教程中,我们将介绍如何向 BlueList 应用程序添加 Google+ 身份验证,允许您将列表上的商品限定到特定用户,以便只有添加了这些商品的用户才能在列表中看到它们。“BlueList 应用程序是一个使用 Bluemix 服务的简单应用程序,它使您能够立即开始编写自己的(更复杂的)应用程序!”在
中,我们添加了推送通知服务,只要该列表被修改,每个向 IBM Push Service 注册的移动设备都会收到一个通知。为此,我们在
上创建了一个项目,并相应地配置了该项目。在本教程中,我们将通过一些步骤,允许多个具有 Google+ 帐户(使用该设备注册)的用户添加到列表中,提供对列表中的特定商品的访问限制,只允许授权的用户进行访问。您的 Google+ 帐户可用于获取 Google+ API 中的服务的访问权。具体地讲,我们将使用 Google+ API 获取 Google ID 令牌和 Google 访问令牌。这些令牌可用于超越简单的 Google+ 登录,实现用户身份验证。完成您的应用程序的前提条件&熟悉 。熟悉 ,我们在前一篇教程中向 Android 应用程序添加了 Push 服务(您可选择此阿勇上一篇教程中的示例作为起点,因为该应用程序是本教程的起点)。一个 Android 开发环境。我们使用了 ,但您也可以使用自己喜欢的环境。熟悉 ,以便使用上述按钮下载所需的代码。对于本教程,所需的项目是: bluelist-auth-google-androidbluelist-auth-google-node一个 Google+ 帐户。如果没有,可以 。一个在 Google Developers Console 上创建的项目(已在上一篇教程中设置)。创建项目的操作说明可以在
获得。熟悉 。API JAR 文件可以在
下载。熟悉 ,用它来推送您的 Bluemix 应用程序的 node.js Mobile Cloud 代码。开始之前&要继续学习本教程中的步骤,必须在 IBM Bluemix 上创建并正确配置一个移动云应用程序后端。还必须在 Google Developers Cloud Console 上创建并配置一个 Google 云项目。如果完成了本系列中的前一篇教程,则表明您已经完成了这项操作,不需要再执行其他准备步骤。 如果跳过了本系列中的前一篇教程,那么您可以执行前一篇教程中的
步骤或 bluelist-auth-google-android 项目中的 Readme 步骤(推荐)来完成这些准备步骤。具体地讲,您可能需要执行 Readme 中的以下节中的步骤(依赖于您已执行哪些步骤): 创建 Mobile Cloud 应用程序将 Google Play Services Library 项目导入您的工作区中创建一个 Google 帐户使用 Google Services 创建并配置一个云应用程序(仅第 1-5 步,本教程中介绍了其他步骤)配置您的 Node.js 应用程序并将它部署到 IBM Bluemix在任何一种情况下,都推荐单击上面的按钮来获取最新的代码Google 身份验证流简介& 继续执行必要的步骤来向应用程序添加 Google+ 身份验证之前,我们需要花费一点时间来看看总体身份验证流。我们将使用 Google+ Sign-in 来实现个性化的 BlueList 应用程序体验。此外,我们将使用 Google+ API 超越个性化并公开一种利用验证层安全性的方式。身份验证流包括 3 个部分:获取身份验证令牌针对 Google+ API Service 检验身份验证令牌的真实性(客户端)针对 Google+ API Service 检验身份验证令牌的真实性(服务器端)我们将会详细查看:获取身份验证令牌假设您在一家杂货店中,并且想要在 Android 设备上的 BlueList 移动应用程序中查看杂货列表。您单击 BlueList 图标,并看到一个登录屏幕,其中有一个按钮允许您以在 Android 设备上注册的 Google 用户身份登录 BlueList。选择该用户并单击 OK。此刻,BlueList 应用程序将联系 Google 身份验证服务,并请求一个 ID 令牌,该令牌将为对您的用户详细信息的访问提供一种身份验证方法。Google 服务现在显示了一个表单,并会请求获得将您的用户详细信息发送到 BlueList 的权限,您单击 OK 就可以授予该权限。BlueList 应用程序现在拥有访问用户信息、验证用户真实性和访问 Google 服务所需的令牌。 作为一种补充性安全措施,同时为了确保您的 Google 帐户未损坏,BlueList 应用程序现在将会返回到 Google API 服务,向它传递 Google ID 令牌,并要求 Google 验证该令牌的真实性。如果该令牌经验证是真实的,那么您将转到 MainActivity 页面来查看其他列表。备注:尽管客户端身份验证有时很有用,但始终应在服务器端执行真正的企业级身份验证,用户不太可能在这里篡改应用程序安全性逻辑。
在访问 MainActivity 后,将会调用 Bluemix Mobile Cloud 应用程序服务。对于绑定到 Mobile Application Security (MAS) 的服务,还涉及到另一个身份验证确认步骤。因为在一个服务绑定到 MAS 时,MAS 在该服务前面抛出了一面 “墙”,强制要求验证存在 Bluemix Mobile Cloud 服务应用程序 ID,而且 该 ID 或访问令牌存在于对该服务的所有请求的标头中。但是,从标头中获取该令牌还不够。MAS 还会和 Google 一起执行检查,以确认该令牌是真实的 Google 令牌。如果该令牌是真实的,那么您现在将能够访问这个自定义的云代码服务。如果发现该令牌不是真实的,那么您将无法修改 BlueList 中的商品。将 Google+ 身份验证添加到您应用程序中&第 1 步:打开 Google+ API 支持&登录到 。 在左侧的导航面板中,单击之前创建的 PROJECT NAME(之前在设置 Push 过程中创建)。单击 APIs & auth,然后单击 APIs。在服务列表中找到 Google+ API 并打开它。它现在显示在为您项目启用的服务的列表中靠近顶部的地方。第 2 步:确保您的虚拟设备支持 Google Play Services&打开 Android Virtual Device Manager。确保您的至少一个虚拟设备的目标是 Google APIs,并与您的 AndroidManifest.xml 文件中指定的 API 级别相匹配。需要这么做是因为 Google 身份验证代码将使用 Google 服务。 备注:如果未正确配置您的虚拟设备,那么在启动应用程序时,可能在 LogCat 控制台中收到 “Google Play services are missing” 警告。对于此示例,我们选择了 Galaxy Nexus – 4.65" 设备。您也可以使用一个实际的 Android 设备。 第 3 步. 提取 Android 调试密钥库证书&确保您在系统上将 PATH 设置为指向某个 Oracle 7 JDK。打开一个命令终端并导航到用户主目录下的 .android 目录。例如,在 Windows® 7 上,该目录为 C:\Users\myuser\.android。运行 Java™ 可执行程序 keytool.exe,以便列出该密钥库的 SHA-1 证书。如果提示输入密码,请输入 android。
keytool.exe -list -keystore debug.keystore重要事项:记下 SHA-1 值,在后面的一个步骤中将要输入它。一种替代方法:在 Eclipse 中,选择 Window & Preferences & Android & Build。复制默认的调试密钥库的 SHA-1 指纹值。第 4 步. 配置 Google+ API 服务&在 Google Developers Console 中,转到 &project_name& & APIs and auth & Credentials。单击 Create new Client ID。在下一个面板上,选择 Web application 并单击 Create Client ID。 为一个已安装的应用程序创建一个客户端 ID。选择 Android 作为 Installed Application Type,并输入 com.ibm.bluelist 作为 Package Name,然后在 SIGNING CERTIFICATE FINGERPRINT (SHA-1) 字段中输入您的 SHA-1 值(已在第 3 步中保存)。
创建客户端 ID 后,向下滚动,找到 Public API access 节并按下 Create new Key。选择 Server key 并按下 Create。记下刚创建的服务器应用程序密钥 的 API 密钥。备注:此步骤和上一步可能已在上一篇教程中执行过。如果是这样,那么您可以跳过这些步骤。记下 Client ID for Android application 和 Client ID for Web application。在后面的一步中,您需要在源代码中指定这些信息。
使用来自您在 Google Developers Cloud Console 上的项目的 2 个新值更新 assets/bluelist.properties 文件(这两个值分别在第 4.2 和 4.3 步中生成):webAppClientID 和 androidAppClientID第 5 步. 添加需要的库&备注:如果使用 Android Studio,可跳过此步骤。假设您已完成
中的步骤或执行了本教程的
一节中的一个 “补充任务” 场景,我们将开始更改此项目代码,将它提升到 Google+ 身份验证级别。 并
Google+ API Client Library,对该文件进行解压缩。在 Google+ API Client Library for Java 中,在 Client Library ZIP 归档文件的 plus\libs 目录下,您会找到需要添加到项目中的 JAR 文件,添加这些文件后才能使用 OAuth 2.0 向 Google+ 身份验证服务执行身份验证。添加下图中列出的所有 JAR 文件(在 libs 目录下)后,您的目录将类似于下图(版本号是截至编写本文时的最新版本,但在您阅读本文时,最新版本可能有所不同): 备注:不是上述所有 JAR 归档文件都已在 Client Library ZIP 归档文件中提供,具体地讲,jackson-core-asl-1.8.10.jar、google-http-client-jackson-1.18.0-rc.jar 和 android-support-v4.jar 归档文件就没有提供。第一和第二个文件可从各种 Maven 存储库中获取,您可以使用您最喜爱的搜索引擎搜索这些存储库。截至编写本教程时,jackson-core-asl-1.8.10.jar 可在
获得。google-http-client-jackson JAR 文件可在
获得。android-support-v4 JAR 文件可在您的 Android SDK 安装位置找到。&在本教程中的前面,我们推荐您下载已完成的项目。这样,您就无需执行第 6 步。不过第 6 步概述了将 Google+ 身份验证功能添加到 BlueList 应用程序或您选择创建的其他任何应用程序所需的代码更改。要在 Eclipse 中为此项目创建一个登录活动,首先请选择 bluelist-push-android 项目。然后转到 File & New & Other & Android 并双击 Android Activity。从活动列表中选择 Login Activity。将该活动命名为 LoginActivity,继续单击后续屏幕上的 Next,然后单击 Finish。创建该活动后,修改 AndroidManifest.xml 文件,以便将 LoginActivity 设置为要在应用程序启动时加载的初始活动。为此,从 MainActivity 元素中剪切 &intent-filter&...&/intent-filter& 语句,并将它粘贴到新的 LoginActivity 元素中。 在 Eclipse 上打开 res/layout/activity_login.xml 文件。如果从头创建登录页面,那么可以选择 Relative Layout,然后添加 Google+ Sign in 按钮 (com.google.mon.SignInButton) 和两个 Android TextViews。您现在应该有一个类似下图的布局。如果需要进一步指导来设计此页面,请参阅 bluelist-auth-google-android 项目中相应的 Java 源代码。 LoginActivity.java 类包含的代码需要使用 Google 身份验证令牌,检验它,如果客户端检验成功,则前进到 MainActivity.java。尽管推荐您将 LoginActivity.java 的内容复制到项目中,但我们想重点强调一下与 Google 身份验证流相关的一些明显的编码步骤。这些步骤已在上面的
一节中介绍,在检查以下代码段之前,应回顾一下相关的内容。重要代码包括:定义 Client ID for Android 和 Web Application 变量,它们将从一个文件读入到 LoginActivity.java 中: /*
This is the "Android Application Client ID" field for a given Android Client,
/* whose value is
found in the Google Developers Console.
private String androidAppClientIdValue =
/* This is the "Web Application Client ID" field for a given Web Application Client,
/* whose value is
found in the Google Developers Console
private String webAppClientIdValue =
Context context = getApplicationContext();
AssetManager assetManager = context.getAssets();
props.load(assetManager.open(PROPS_FILE));
Log.i(CLASS_NAME, "Found configuration file: " + PROPS_FILE);
androidAppClientIdValue = props.getProperty(GOOGLE_ANDROID_APP_CLIENT_ID_KEY);
webAppClientIdValue = props.getProperty(GOOGLE_WEB_APP_CLIENT_ID_KEY);
}为用户提供在其当前设备上注册的 Google+ 用户列表:
selectedAccountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);指定获取 Google 令牌的范围:
// Use this scope to get the Google ID Token
String clientIdScope = "audience:server:client_id:" + webAppClientIdV;
// Use this scope to get the GOOGLE Access Token
String oAuthScopes = "oauth2:";
oAuthScopes += " /auth/userinfo.profile";
oAuthScopes += " /auth/userinfo.email";
oAuthScopes += " /auth/plus.login";获取 Google 令牌:
/* Obtain Google ID and Access Tokens */
idToken = GoogleAuthUtil.getToken(getApplicationContext(),
selectedAccountName, clientIdScope);
System.out.println("Google ID Token: "+idToken);
googleAccessToken = GoogleAuthUtil.getToken(getApplicationContext(),
selectedAccountName, oAuthScopes);
System.out.println("Google Access Token: "+googleAccessToken);在客户端上检验 Google ID 令牌:
GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier(
/* Http Transport is needed to fetch Google's latest public key */
new ApacheHttpTransport(), factory);
/* Verify valid token, signed , intended for a third party. */
if (!verifier.verify(idToken) ||
!idToken.verifyAudience(Collections.singletonList(webAppClientIdValue))||
!idToken.getPayload().getAuthorizedParty().equals(androidAppClientIdValue)) {
System.out.println("Invalid token");
googleTokenFailedVerification =
}使用 GOogle 访问令牌获取对用户内容的访问权:
/* use this url to get details from
access_token */
URL url = new URL
("/oauth2/v1/tokeninfo?alt=json&id_token="+token);
HttpClient httpClient = new DefaultHttpClient();
HttpGet pageGet = new HttpGet(url.toURI());
org.apache.http.HttpResponse hResponse = httpClient.execute(pageGet);在 LoginActivity::startMainActivity() 中检验令牌后,前进到 BlueList MainActivity.java 类中:
if( googleIdToken != null && !googleIdToken.isEmpty() )
* The token has been found and validated so let's pass user onto the
* Bluelist main activity.
* If user has not been signed in, then don't go onto MainActivity.
if( googleEmail == null || googleEmail.isEmpty() )
mStatus.setText("Error: User Not Signed in");
final Context context = thisA
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra("GOOGLE_ID_TOKEN", googleIdToken);
intent.putExtra("GOOGLE_OAUTH_TOKEN", googleAccessToken);
intent.putExtra("GOOGLE_NAME", googleFirstName + " " + googleLastName);
intent.putExtra("GOOGLE_EMAIL", googleEmail);
intent.putExtra("GOOGLE_PICTURE", googlePicture);
statusMessage = "";
mStatus.setText("");
System.out.println("Opening Main Activity and passing Google ID Token: " + googleIdToken);
startActivity(intent);
selectedAccountName =
...在 UserAccount.java 中,创建一个新 bean 来代表该用户,使用从以下字段生成的 getter/setter 方法:
privatestatic
String idToken = null;
privatestatic
String userName = null;
privatestatic
String userEmail = null;
privatestatic String userPicture
privatestatic String accessToken
= null;在 Item.java 中,添加新的 getUserId() 和 setUserId() 方法:
* Gets the userId associated with the Item.
* @return String userId
public String getUserId() {
return (String) getObject(USERID);
* Sets the email address of the user who is maintaining list items
* @param String userId
publicvoid setUserId(String userId) {
setObject(USERID, (userId != null) ? userId : "");
}在 MainActivity.java 中,添加代码来从 intent 拉入身份验证令牌,并在 IBMBluemix 安全性上下文中设置它。此刻,MAS 将在云端检验该令牌。成功检验后将返回一个 Bolts 任务和一个惟一用户 ID,客户端 SDK 初始化将继续进行。
/* Set ID TOKEN so that all subsequent Service calls
will contain the ID TOKEN in the header. */
Log.d(CLASS_NAME, "Setting
the GOOGLE ID TOKEN for all future IBM Bluemix Mobile Cloud Service calls");
/* ID is overridden by applicationID set
in assets/configuration.json. */
IBMBluemixsetSecurityToken
(IBMSecurityProvider.GOOGLE, UserAccount.
getAccessToken()).continueWithTask(
new Continuation&IBMCurrentUser, Task&String&&() {
public Task&String&
then(Task&IBMCurrentUser& user) throws Exception {
if (user.isFaulted()) {
Log.e(CLASS_NAME,
"There was an error setting security token. Stack trace: ");
user.getError().printStackTrace();
returnnull;
Log.i(CLASS_NAME,
"Set security token successfully. Initializing services.");
Log.i(CLASS_NAME, "
The successfully returned IBMCurrentUser: " + user.getResult().getUuid());
IBMCurrentUser cUser = user.getResult();
uUserID = cUser.getUuid();
// Initialize the IBM Data Service
IBMData.initializeService();
// Register Item Specialization
Item.registerSpecialization(Item.class);
// Initialize the IBM Cloud Code Service
IBMCloudCode.initializeService();
// Instantiate the cloud code service instance
myCloudCodeService = IBMCloudCode.getService();
// Initialize IBM Push service
IBMPush.initializeService();
// Retrieve instance of the IBM Push service
push = IBMPush.getService();
/* Refresh the list. */
listItems();
// Register the device with the IBM Push service.
return push.register(deviceAlias, consumerID);
}).continueWith(new Continuation&String, Void&() {
public Void then(Task&String& task)
throws Exception {
if (task.isCancelled()) {
Log.e(CLASS_NAME, "Exception : Task "
+ task.toString() + " was cancelled.");
} else if (task.isFaulted()) {
Log.e(CLASS_NAME,
"Exception : " + task.getError().getMessage());
Log.e(CLASS_NAME,
"There was an error initializing Push service. Stack trace: ");
task.getError().printStackTrace();
Log.i(CLASS_NAME,
"Device Successfully Registered with the Push service with deivceID: "
+ task.getResult());
returnnull;
...在 MainActivity.java 中,将以下行添加到 updateItem() 中来支持返回的 uUserID:
editIntent.putExtra("userId", uUserID);在 MainActivity.java 中,在 listItems() 中添加代码来按惟一用户 ID 过滤数据项:
// Clear local itemList, as we'll be reordering &
repopulating from DataService.
itemList.clear();
Log.i(CLASS_NAME,
"Clearing the locally-kept list. List is now: " + itemList);
for (Item item : objects) {
if (item.getUserId() != null &&
item.getUserId().equals(uUserID)) {
itemList.add(item);
...在 MainActivity.java 中,将以下行添加到 createItem() 来将一个数据项与一个惟一用户 ID 相关联:
item.setUserId(uUserID);第 7 步. 在您的 IBM Mobile Cloud 服务上启用 Google+ 登录检验&登录到您的
帐户。单击您的 Mobile Cloud 后端应用程序。单击 Mobile Application Security。勾选 Enable Google Sign-In 复选框。这需要任何访问与您的应用程序有关联的 Mobile Cloud 服务的应用程序,在每个请求中提供一个 Google 身份验证令牌。单击 Save。 第 8 步. 运行应用程序&请注意,您已完成了代码更改,您的代码应等效于 Google+ 身份验证版本。我们来测试一下!在 Android 模拟器中运行最新的代码。您会看到以下屏幕: 创建一个帐户(如果在设备上注册了多个 Google+ 帐户)应用程序权限登录以一个已注册用户的身份进行登录。向列表中添加商品。退出应用程序。转到 Settings & Apps & BlueList 并单击 Force Stop,然后单击应用程序上的 Clear Data。再次运行该应用程序,以不同的注册用户的身份进行登录。请注意,此用户还没有商品。向列表中添加更多商品。重复第 4 和 5 步,这一次以第 2 步中的第一个用户的身份登录。请注意,第二个用户添加的商品未在第一个用户可访问的列表中。您的 Google+ 身份验证代码已起作用! 结束语&在本教程中,我们演示了如何在 Android 应用程序中联合使用 IBM Bluemix Mobile Cloud Services 客户端 SDK 和 Google+ API Client Library for Java。我们使用身份验证和授权功能扩展了一个 Bluemix Mobile Cloud 应用程序后端服务,该服务利用了 Push、Mobile Data 和 IBM Cloud 托管的 Node.js 应用程序。示例应用程序展示了如何使用 GZoogle+ 身份验证服务生成的 OAuth 2.0 身份验证令牌,验证对与现有移动应用程序后端绑定的 Mobile Cloud 服务的访问权,并使用 Mobile Application Security 作为网关。文中还展示了不同的 Google+ 帐户持有人如何访问自己的惟一列表,且无法访问其他用户的数据。
注意:评论中不支持 HTML 语法
剩余 1000 字符
developerWorks: 登录
标有星(*)号的字段是必填字段。
保持登录。
单击提交则表示您同意developerWorks 的条款和条件。 查看条款和条件。
在您首次登录 developerWorks 时,会为您创建一份个人概要。您的个人概要中的信息(您的姓名、国家/地区,以及公司名称)是公开显示的,而且会随着您发布的任何内容一起显示,除非您选择隐藏您的公司名称。您可以随时更新您的 IBM 帐户。
所有提交的信息确保安全。
选择您的昵称
当您初次登录到 developerWorks 时,将会为您创建一份概要信息,您需要指定一个昵称。您的昵称将和您在 developerWorks 发布的内容显示在一起。昵称长度在 3 至 31 个字符之间。
您的昵称在 developerWorks 社区中必须是唯一的,并且出于隐私保护的原因,不能是您的电子邮件地址。
标有星(*)号的字段是必填字段。
(昵称长度在 3 至 31 个字符之间)
单击提交则表示您同意developerWorks 的条款和条件。 .
所有提交的信息确保安全。
static.content.url=/developerworks/js/artrating/SITE_ID=10Zone=移动开发, Cloud computingArticleID=991644ArticleTitle=使用 Google+ 身份验证增强 Android 应用程序publish-date=拒绝访问 |
| 百度云加速
请打开cookies.
此网站 () 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(387f1b6aa0614382-ua98).
重新安装浏览器,或使用别的浏览器获取Google Advertising ID作为唯一识别码 - Widsom的博客 - CSDN博客
获取Google Advertising ID作为唯一识别码
android提升
获取Google Advertising ID作为唯一识别码
在Android程序中,有时候我们APP需要获取唯一识别码,来区别用户。在Android系统中提供了了AndroidId,但AndroidId有时候会为null,同时root手机用户,androidid可以改变。所以AndroidId并不能作为唯一识别码。
对于Google推荐使用Google Advertising ID,通过Google Service可以获取Google Advertising ID(如果没有Google Service就回去不到Google Advertising ID)。下面看看代码吧
AdvertisingIdClient类
public class AdvertisingIdClient {
* 这个方法是耗时的,不能在主线程调用
public static String getGoogleAdId(Context context) throws Exception {
if (Looper.getMainLooper() == Looper.myLooper()) {
return "Cannot call in the main thread, You must call in the other thread";
PackageManager pm = context.getPackageManager();
pm.getPackageInfo("com.android.vending", 0);
AdvertisingConnection connection = new AdvertisingConnection();
Intent intent = new Intent(
"com.google.android.gms.ads.identifier.service.START");
intent.setPackage("com.google.android.gms");
if (context.bindService(intent, connection, Context.BIND_AUTO_CREATE)) {
AdvertisingInterface adInterface = new AdvertisingInterface(
connection.getBinder());
return adInterface.getId();
} finally {
context.unbindService(connection);
return "";
private static final class AdvertisingConnection implements ServiceConnection {
boolean retrieved = false;
private final LinkedBlockingQueue&IBinder& queue = new LinkedBlockingQueue&&(1);
public void onServiceConnected(ComponentName name, IBinder service) {
this.queue.put(service);
} catch (InterruptedException localInterruptedException) {
public void onServiceDisconnected(ComponentName name) {
public IBinder getBinder() throws InterruptedException {
if (this.retrieved)
throw new IllegalStateException();
this.retrieved = true;
return this.queue.take();
private static final class AdvertisingInterface implements IInterface {
private IB
public AdvertisingInterface(IBinder pBinder) {
binder = pB
public IBinder asBinder() {
public String getId() throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
binder.transact(1, data, reply, 0);
reply.readException();
id = reply.readString();
} finally {
reply.recycle();
data.recycle();
public boolean isLimitAdTrackingEnabled(boolean paramBoolean)
throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
boolean limitAdT
data.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
data.writeInt(paramBoolean ? 1 : 0);
binder.transact(2, data, reply, 0);
reply.readException();
limitAdTracking = 0 != reply.readInt();
} finally {
reply.recycle();
data.recycle();
return limitAdT
MainActivity类调用
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Executors.newSingleThreadExecutor().execute(new Runnable() {
public void run() {
String adid = AdvertisingIdClient.getGoogleAdId(getApplicationContext());
Log.e("MainActivity", "adid:
" + adid);
} catch (Exception e) {
e.printStackTrace();
我的热门文章
即使是一小步也想与你分享

我要回帖

更多关于 google gms认证 的文章

 

随机推荐