我的教程会在这里一起和我越来越有误差的方法getIntentSender()是未定义的类型ConnectionResult
在 onConnectionFailed
类。
全部code
包com.alfalfa.thisthat;
进口android.app.Activity;
进口android.content.Intent;
进口android.content.IntentSender.SendIntentException;
进口android.os.Bundle;
进口android.view.Menu;
进口com.google.android.gms.common.ConnectionResult;
进口com.google.android.gms.common.api.GoogleApiClient;
进口com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
进口com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
进口com.google.android.gms.plus.Plus;
公共类LoginActivity扩展活动器具
ConnectionCallbacks,OnConnectionFailedListener {
/ *请求code用来在用户交互调用的迹象。 * /
私有静态最终诠释RC_SIGN_IN = 0;
/ *客户端用来与谷歌API的交互。 * /
私人GoogleApiClient mGoogleApiClient;
/ *一个标志,指示一个PendingIntent正在进行和prevents
*我们启动进一步的意图。
* /
私人布尔mIntentInProgress;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
mGoogleApiClient =新GoogleApiClient.Builder(本)
.addConnectionCallbacks(本)
.addOnConnectionFailedListener(本)
.addApi(Plus.API,空)
.addScope(Plus.SCOPE_PLUS_LOGIN)
。建立();
}
保护无效的OnStart(){
super.onStart();
mGoogleApiClient.connect();
}
保护无效的onStop(){
super.onStop();
如果(mGoogleApiClient.isConnected()){
mGoogleApiClient.disconnect();
}
}
@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
//充气菜单;这增加了项目操作栏,如果它是present。
。getMenuInflater()膨胀(R.menu.main,菜单);
返回true;
}
@覆盖
公共无效onConnectionFailed(ConnectionResult结果){
如果(mIntentInProgress&安培;!&安培; result.hasResolution()){
尝试 {
mIntentInProgress =真;
startIntentSenderForResult(result.getIntentSender(),
RC_SIGN_IN,NULL,0,0,0);
}赶上(SendIntentException E){
//它被发送之前做的目的被取消。返回到默认
//状态,并尝试连接到获得更新ConnectionResult。
mIntentInProgress = FALSE;
mGoogleApiClient.connect();
}
}
}
@覆盖
公共无效onConnected(包connectionHint){
//我们已经解决了所有连接错误。 mGoogleApiClient可用于
//代表用户访问谷歌的API。
}
@覆盖
公共无效onConnectionSuspended(INT原因){
mGoogleApiClient.connect();
}
保护无效onActivityResult(INT申请code,INT响应code,意图意图){
如果(要求code == RC_SIGN_IN){
mIntentInProgress = FALSE;
如果(!mGoogleApiClient.isConnecting()){
mGoogleApiClient.connect();
}
}
}
}
编辑: LogCat中
02-13 19:12:31.763:E / AndroidRuntime(21257):致命异常:主要
02-13 19:12:31.763:E / AndroidRuntime(21257):工艺:com.alfalfa.thisthat,PID:21257
02-13 19:12:31.763:E / AndroidRuntime(21257):java.lang.RuntimeException的:无法启动的活动ComponentInfo {com.alfalfa.thisthat / com.alfalfa.thisthat.MainActivity}:android.content.ActivityNotFoundException:无法找到明确的活动类{com.alfalfa.thisthat / com.alfalfa.thisthat.LoginActivity};有你宣布你的AndroidManifest.xml这个活动?
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.ActivityThread.access $ 800(ActivityThread.java:135)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1196)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.os.Handler.dispatchMessage(Handler.java:102)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.os.Looper.loop(Looper.java:136)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.ActivityThread.main(ActivityThread.java:5017)
02-13 19:12:31.763:E / AndroidRuntime(21257):在java.lang.reflect.Method.invokeNative(本机方法)
02-13 19:12:31.763:E / AndroidRuntime(21257):在java.lang.reflect.Method.invoke(Method.java:515)
02-13 19:12:31.763:E / AndroidRuntime(21257):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779)
02-13 19:12:31.763:E / AndroidRuntime(21257):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-13 19:12:31.763:E / AndroidRuntime(21257):在dalvik.system.NativeStart.main(本机方法)
02-13 19:12:31.763:E / AndroidRuntime(21257):android.content.ActivityNotFoundException:产生的原因无法找到明确的活动类{com.alfalfa.thisthat / com.alfalfa.thisthat.LoginActivity};有你宣布你的AndroidManifest.xml这个活动?
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.Activity.startActivityForResult(Activity.java:3424)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.Activity.startActivityForResult(Activity.java:3385)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.Activity.startActivity(Activity.java:3627)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.Activity.startActivity(Activity.java:3595)
02-13 19:12:31.763:E / AndroidRuntime(21257):在com.alfalfa.thisthat.MainActivity.onCreate(MainActivity.java:16)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.Activity.performCreate(Activity.java:5231)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-13 19:12:31.763:E / AndroidRuntime(21257):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-13 19:12:31.763:E / AndroidRuntime(21257):11 ...更多
解决方案
由于今天和谷歌播放SDK版本15,这已被替换为
result.startResolutionForResult(这//你的活动
RC_SIGN_IN);
根据更新的documentation.
I am going along with the tutorial here, and am getting there error The method getIntentSender() is undefined for the type ConnectionResult
in the onConnectionFailed
class.
Full Code
package com.alfalfa.thisthat;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.plus.Plus;
public class LoginActivity extends Activity implements
ConnectionCallbacks, OnConnectionFailedListener {
/* Request code used to invoke sign in user interactions. */
private static final int RC_SIGN_IN = 0;
/* Client used to interact with Google APIs. */
private GoogleApiClient mGoogleApiClient;
/* A flag indicating that a PendingIntent is in progress and prevents
* us from starting further intents.
*/
private boolean mIntentInProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
}
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (!mIntentInProgress && result.hasResolution()) {
try {
mIntentInProgress = true;
startIntentSenderForResult(result.getIntentSender(),
RC_SIGN_IN, null, 0, 0, 0);
} catch (SendIntentException e) {
// The intent was canceled before it was sent. Return to the default
// state and attempt to connect to get an updated ConnectionResult.
mIntentInProgress = false;
mGoogleApiClient.connect();
}
}
}
@Override
public void onConnected(Bundle connectionHint) {
// We've resolved any connection errors. mGoogleApiClient can be used to
// access Google APIs on behalf of the user.
}
@Override
public void onConnectionSuspended(int cause) {
mGoogleApiClient.connect();
}
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == RC_SIGN_IN) {
mIntentInProgress = false;
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
}
}
EDIT: LogCat
02-13 19:12:31.763: E/AndroidRuntime(21257): FATAL EXCEPTION: main
02-13 19:12:31.763: E/AndroidRuntime(21257): Process: com.alfalfa.thisthat, PID: 21257
02-13 19:12:31.763: E/AndroidRuntime(21257): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alfalfa.thisthat/com.alfalfa.thisthat.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.alfalfa.thisthat/com.alfalfa.thisthat.LoginActivity}; have you declared this activity in your AndroidManifest.xml?
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.os.Handler.dispatchMessage(Handler.java:102)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.os.Looper.loop(Looper.java:136)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-13 19:12:31.763: E/AndroidRuntime(21257): at java.lang.reflect.Method.invokeNative(Native Method)
02-13 19:12:31.763: E/AndroidRuntime(21257): at java.lang.reflect.Method.invoke(Method.java:515)
02-13 19:12:31.763: E/AndroidRuntime(21257): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-13 19:12:31.763: E/AndroidRuntime(21257): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-13 19:12:31.763: E/AndroidRuntime(21257): at dalvik.system.NativeStart.main(Native Method)
02-13 19:12:31.763: E/AndroidRuntime(21257): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.alfalfa.thisthat/com.alfalfa.thisthat.LoginActivity}; have you declared this activity in your AndroidManifest.xml?
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.Activity.startActivityForResult(Activity.java:3424)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.Activity.startActivityForResult(Activity.java:3385)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.Activity.startActivity(Activity.java:3627)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.Activity.startActivity(Activity.java:3595)
02-13 19:12:31.763: E/AndroidRuntime(21257): at com.alfalfa.thisthat.MainActivity.onCreate(MainActivity.java:16)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.Activity.performCreate(Activity.java:5231)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-13 19:12:31.763: E/AndroidRuntime(21257): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-13 19:12:31.763: E/AndroidRuntime(21257): ... 11 more
解决方案
As of today and Google Play SDK version 15, this has been replaced with
result.startResolutionForResult(this, // your activity
RC_SIGN_IN);
as per the updated documentation.