- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在制作应用程序,我想将它与 G+ 集成,让用户使用 Google 帐户登录。我使用 Android Studio 创建应用。
我在 Stack Overflow 上阅读了很多问题和答案,但我无法修复我的应用!
以下是我执行的步骤:
1. 添加google-play-services.jar到我项目的libs文件夹
2. 在Android-Studio project explorer中点击jar文件的“Add As Library”
3. 将web example中的脚本添加到java文件
4. 将 google-play-services.jar 库添加到 Build.Gradle 文件
5. 启动应用程序使其崩溃
问题是:如何将 Google+ 集成添加到使用 Android Studio 制作的应用程序中,我做错了什么吗?谢谢您的帮助。
这是我的源代码:
Java 类:
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
import com.google.android.gms.plus.PlusClient;
public class StartActivity extends Activity implements View.OnClickListener, ConnectionCallbacks, OnConnectionFailedListener {
private static final String TAG = "ExampleActivity";
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
private ProgressDialog mConnectionProgressDialog;
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loading_screen);
mPlusClient = new PlusClient.Builder(this, this, this)
.setVisibleActivities("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity")
.build();
mConnectionProgressDialog = new ProgressDialog(this);
mConnectionProgressDialog.setMessage("Signing in...");
initializeSplashElements();
}
/// *** /// PLUS INTEGRATION /// *** ////
@Override
protected void onStart() {
super.onStart();
mPlusClient.connect();
}
@Override
protected void onStop() {
super.onStop();
mPlusClient.disconnect();
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (result.hasResolution()) {
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (IntentSender.SendIntentException e) {
mPlusClient.connect();
}
}
// Save the result and resolve the connection failure upon a user click.
mConnectionResult = result;
}
@Override
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
mConnectionResult = null;
mPlusClient.connect();
}
}
@Override
public void onConnected(Bundle bundle) {
String accountName = mPlusClient.getAccountName();
Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG).show();
}
@Override
public void onDisconnected() {
Log.d(TAG, "disconnected");
}
/// *** /// PLUS INTEGRATION /// *** ///
(...)
}
布局 XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".StartActivity"
android:clickable="false"
android:background="@drawable/ziel_pomar_tlo">
<ImageView
android:layout_width="fill_parent"
android:layout_height="150dp"
android:id="@+id/splashLogo"
android:src="@drawable/catch_up_logo_flatten"
android:contentDescription="@string/catchup_logo_describe"
android:layout_marginTop="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:focusable="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/loading_3dot"
android:id="@+id/loadingText"
android:enabled="true"
android:gravity="center"
android:textSize="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:layout_marginBottom="35dp"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:layout_above="@+id/loadingText"
android:layout_below="@+id/splashLogo"
android:layout_margin="10dp"
android:layout_alignParentEnd="false"
android:layout_centerHorizontal="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:clickable="false"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:id="@+id/gps_row">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/loading_screen_no_gps"
android:id="@+id/gps_desc"
android:textSize="20dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3"
android:layout_marginTop="10dp">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/loading_screen_no_gps_settings"
android:id="@+id/gps_settings"
android:layout_weight="2"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/loading_screen_no_gps_ok"
android:id="@+id/gps_fixed"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/web_row"
android:layout_gravity="bottom|top"
android:layout_marginTop="20dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/loading_screen_no_web"
android:id="@+id/web_desc"
android:textSize="20dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3"
android:layout_marginTop="10dp">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/loading_screen_no_web_settings"
android:id="@+id/web_wifi_settings"
android:layout_weight="1"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/loading_screen_no_web_settings2"
android:id="@+id/web_3g_settings"
android:layout_weight="1"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/loading_screen_no_web_ok"
android:id="@+id/web_fixed"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Build.Gradle:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar', 'libs/google-play-services.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 17
compileSdkVersion 17
}
}
最佳答案
您可以使用 Google Repository,而无需在代码中导入任何库 (.jar)
更新:如果您正在寻找 Google(或第三方)库,您可以查看:http://gradleplease.appspot.com/ (作者:Google 开发人员 Chris Broadfoot)
dependencies {
compile 'com.google.android.gms:play-services:4.4.52'
compile 'com.android.support:support-v4:19.1.0'
// compile files('libs/android-support-v4.jar') // OLD: can remove
// Other useful library
// compile 'com.android.support:appcompat-v7:19.1.0'
// compile 'com.android.support:gridlayout-v7:19.1.0'
// compile 'com.android.support:mediarouter-v7:19.1.0'
// compile 'com.android.support:support-v13:19.1.0'
// Note: these libraries require the "Google Repository" and "Android Repository"
// to be installed via the SDK manager.
}
引用:https://plus.google.com/+AndroidDevelopers/posts/4Yhpn6p9icf
关于android - 如何在 Android Studio 中使用 Google Plus 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17135158/
我很确定我错过了一些东西,但我找不到(即谷歌)为 Google Plus 创建测试帐户的可能性。 但是,肯定不允许创建虚假用户帐户进行测试,那么,如何使用多个(我的)帐户测试我的 G+ 应用程序? 最
有没有办法查看与 Google Plus 共享您的网站的人的列表(即点击特定 URL 加一按钮的人)? 最佳答案 点击 +1 按钮与分享并不完全相同(例如作为事件的一部分),但您确实可以使用 Goog
所以我试图用我的 sqlite 数据库中的行填充一个对象,如下所示: - (id) initWithSQLite:(sqlite3_stmt *)row andDatabase:(Database*)
R有没有+=的概念? (加等号)或 ++ (plus plus) 像 c++/c#/others 一样吗? 最佳答案 不,它没有,请参阅:R Language Definition: Operator
R有没有+=的概念? (加等号)或 ++ (plus plus) 像 c++/c#/others 一样吗? 最佳答案 不,它没有,请参阅:R Language Definition: Operator
假设我有一个在线购物系统,并且有许多用户注册了它。我想要一个功能,当我添加新产品或对特定产品进行促销时,我的 Google+ 页面会更新,因为产品的详细信息会自动发布在那里。它只会用于后台办公目的。
我经营一个博客并使用 Google Plus 作为推广工具,在 G+ 上发布每次更新。由于我有数百名关注者,我的 G+ 帖子经常有几条评论:我想在我的博客上展示它们! 我知道有一些工具可以根据 G+
链接:https://sites.google.com/site/oauthgoog/Home/emaildisplayscope 在上面的链接中,我添加了电子邮件范围 https://www.goo
在这个简单的脚本中我需要你的一点帮助。我正在尝试创建一个通过阅读 Windows 标题来运行“taskkill”的脚本,但我不知道如何让它在 C++ 中运行。据我所知,批量处理将非常容易 system
map mp; 我能看懂下面的代码: mp[1] = 1; mp[2] = 2; 但这有什么意义呢? mp[3]++; 不设置 mp[3] = n;(n 可以是整数)。 最佳答案 当 map 的 op
每当我需要从缓存中检索数据时,我都会使用 FromCache() 方法。 我没有设置任何默认缓存策略,而是使用默认情况下使用的任何 EF plus。 默认的缓存持续时间是多少?等一下?还是无限? 最佳
我正在我的应用程序中实现 google plus。我想在用户共享消息后实现回调函数。请让我知道在点击 google plus 中的共享按钮后是否可以实现回调。 提前致谢 普拉塔普 最佳答案 通过设置共
我有一个使用 Google+ API 列出您圈子中的用户的应用程序。这很好用,除了一件事:API 没有说明用户是否有图片,或者图片是否只是占位符(蓝色剪影)。 https://developers.g
是否可以将 Google 社区嵌入网站页面? 这样,我们的客户既可以从我们网站的内容和所有其他功能中受益,又可以使用 Google 社区进行协作。 理想情况下,我想抓取一个 Javascript 代码
我在 Google Plus 上有大量相册。我正在寻找一种有效的方式来下载它们。如果我将它们放在 Google Drive 上,我可以使用 skicka ,它有一些烦恼,但总体效果很好。 我正在寻找一
我正在建立一个网站,我想允许谷歌登录。我不希望我的客户再次将他们的个人资料图片上传到我的网站。我有一些关于如何使用 facebook 进行操作的线索,但是一旦用户通过 Google 帐户进行身份验证,
我想在我的网站上显示我的 facebook、twitter、linkedIn、google+ 页面的事件提要。对于 facebook 和 twitter,我通过引用他们的开发者网站(附图片)来获取提要
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 8年前关闭。 Improve this questi
网上有许多关于如何从 Notepad Plus Plus (NPP) 运行文件的示例。但是它们都没有考虑到当前工作目录是 NPP 可执行文件的位置,而不是文件的位置这一事实。 通常他们是这样的: cm
使用 VIM 编辑文件我可以轻松地复制和粘贴文件的名称(或完整路径) 我正在努力(要了解我对 VIM 的意思,您可以看到: this question 或 wiki ); 是否有使用 Notepad+
我是一名优秀的程序员,十分优秀!