How to dismiss initial account manager dialog in google plus android? - android

Hi I am using google plus. when I click button, it need to display email and other information. But problem is if user has multiple account, without clicking button, dialog is opening. After dismissing dialog and click button, once again dialog is opening and working fine. I couldn't find this strange issue.
When i launch screen, without clicking button, choose an account dialog is opening. How to solve this?
Here is my code: I am using fragments.
public class LoginFragment extends SherlockFragment implements OnClickListener,
ConnectionCallbacks, OnConnectionFailedListener {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Common.mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
Common.mGoogleApiClient.connect();
return view;
}
public void onStop() {
super.onStop();
if (Common.mGoogleApiClient.isConnected()) {
Common.mGoogleApiClient.disconnect();
}
}
}
Common:
public class Common {
static int RC_SIGN_IN = 0;
static String TAG = "MainActivity";
static int PROFILE_PIC_SIZE = 400;
static GoogleApiClient mGoogleApiClient;
static boolean mIntentInProgress;
static boolean mSignInClicked;
static ConnectionResult mConnectionResult;
static Activity con;
public Common(Activity c) {
con = c;
}
LoginActivity:
public class LoginActivity extends SherlockFragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
public void resolveSignInError() {
if (Common.mConnectionResult != null) {
if (Common.mConnectionResult.hasResolution()) {
try {
Common.mIntentInProgress = true;
Common.mConnectionResult.startResolutionForResult(
Common.con, Common.RC_SIGN_IN);
} catch (SendIntentException e) {
Common.mIntentInProgress = false;
Common.mGoogleApiClient.connect();
}
}
}
}
#Override
protected void onActivityResult(int requestCode, int responseCode,
Intent data) {
super.onActivityResult(requestCode, responseCode, data);
if (requestCode == Common.RC_SIGN_IN) {
if (responseCode != Common.con.RESULT_OK) {
Common.mSignInClicked = false;
}
Common.mIntentInProgress = false;
if (!Common.mGoogleApiClient.isConnecting()) {
Common.mGoogleApiClient.connect();
}
}
}
}
Here is screenshot where without clicking google plus button, dialog pop up.

Related

why tts isn't changing the languge in Android Fragment but works fine in Activity?

So I have been trying to change the TTS language inside a fragment but it isn't working but same code works fine inside MainActivity. I don't understand why. I have checked other solutions but none worked for me. I have tried different solution , solution but even this isn't working.
public class HomeFragment extends Fragment implements TextToSpeech.OnInitListener{
private static final int TTS_DATA_CHECK = 1;
private TextToSpeech engine;
private SettingsViewModel settingsViewModel;
private EditText textMsg;
private Button button;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
engine = new TextToSpeech(getContext(),this);
settingsViewModel = new ViewModelProvider(getActivity()).get(SettingsViewModel.class);
return inflater.inflate(R.layout.fragment_home, container, false);
}
#RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
textMsg = view.findViewById(R.id.textMsg);
button = view.findViewById(R.id.playButton);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
engine.speak(textMsg.getText().toString(), TextToSpeech.QUEUE_FLUSH, null,null);
}
});
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
settingsViewModel.getLanguage().observe(getViewLifecycleOwner(), new Observer<String>() {
#Override
public void onChanged(String s) {
Log.d("LANGUAGE_SELECTED",s);
switch (s){
case "ENGLISH":
engine.setLanguage(Locale.ENGLISH);
break;
case "FRENCH":
engine.setLanguage(Locale.FRENCH);
break;
}
}
});
}
#Override
public void onInit(int status) {
if(status==TextToSpeech.SUCCESS){
int result = engine.setLanguage(Locale.ENGLISH);
if(result == TextToSpeech.LANG_MISSING_DATA
|| result== TextToSpeech.LANG_NOT_SUPPORTED){
Toast.makeText(getContext(),"Not supported",Toast.LENGTH_LONG).show();
}
}else{
Toast.makeText(getContext(),"TTS is missing",Toast.LENGTH_LONG).show();
}
}
}
First you need to initialize TTS in main activity like this -
public class MainActivity extends AppCompatActivity implements TextToSpeech.OnInitListener {
private static final int TTS_DATA_CHECK = 101;
static TextToSpeech engine;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
engine = new TextToSpeech(this,this);
}
#Override
public final void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 101)
{
if (resultCode != TextToSpeech.Engine.CHECK_VOICE_DATA_PASS)
{
final Intent tnt = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(tnt);
}
}
}
#Override
public void onInit(int status) {
if(status==TextToSpeech.SUCCESS){
if(TTS_DATA_CHECK == TextToSpeech.LANG_MISSING_DATA
|| TTS_DATA_CHECK== TextToSpeech.LANG_NOT_SUPPORTED){
Toast.makeText(this,"Not supported",Toast.LENGTH_LONG).show();
}
}
}
static public TextToSpeech getInstance() {
return engine;
}
}
Then you have to call the TTS instance inside Fragment like this. Note that, MainActivity is the parent activity of the given Fragment.
Now replace the following code in your Fragment with this code -
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log.d("VMA","OnActivityCreated");
settingsViewModel.getLanguage().observe(getViewLifecycleOwner(), new Observer<String>() {
#Override
public void onChanged(String s) {
Log.d("VMA","LANGUAGE_SELECTED " + s);
switch (s){
case "FRENCH":
MainActivity.getInstance().setLanguage(Locale.FRENCH);
break;
case "ENGLISH":
MainActivity.getInstance().setLanguage(Locale.ENGLISH);
break;
}
}
});
}
Also, you can remove the rest of the TTS code from Fragment. You don't that anymore.

GoogleApiClient not connected if used from fragment

I discovered a strange behaviour today.
I have my activity which connects to the GoogleApiClient in onStart() and disconnects in the onStop()
The activity uses a GridViewPager to show my fragments. To send messages through the Data Layer i use a callback interface between activity and fragment.
If i call sendMessage() from a button within the Activity layout it works fine. If sendMessage() is executed by the fragment using the callback interface sendMessage() shows the "not connected" Toast.
In both ways the same method in the Activity is called so how is it possible that it behaves different ?
I should mention that the problem only occours after the application is restarted for the first time.
Activity
public class WearPlex extends WearableActivity implements
NavigationRemoteCallbacks,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private List<Node> nodeList = new ArrayList<Node>();
private List<Fragment> fragmentList = new ArrayList<Fragment>();
private GoogleApiClient googleApiClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wear_plex);
setAmbientEnabled();
fragmentList.add(NavigationRemoteFragment.getInstance(this));
GridViewPager mGridPager = (GridViewPager)findViewById(R.id.gridViewPager);
mGridPager.setAdapter(new MainGridPageAdapter(getFragmentManager(), fragmentList));
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
#Override
protected void onStart() {
super.onStart();
googleApiClient.connect();
}
#Override
protected void onStop() {
googleApiClient.disconnect();
super.onStop();
}
#Override
public void onConnected(Bundle bundle) {
Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
nodeList.clear();
Wearable.NodeApi.getConnectedNodes(googleApiClient).setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
#Override
public void onResult(NodeApi.GetConnectedNodesResult nodes) {
for (Node node : nodes.getNodes()) nodeList.add(node);
}
});
}
#Override
public void navigationRemoteSendCommand(String commandPath) {
sendMessage(commandPath, null);
}
public void debugOnClick(View view) {
sendMessage("/debug", null);
}
public void sendMessage(String path, byte[] data) {
if (googleApiClient.isConnected()) {
for (int i = 0; i < nodeList.size(); i++) {
if (nodeList.get(i).isNearby()) {
Toast.makeText(this, "Send message", Toast.LENGTH_SHORT).show();
Wearable.MessageApi.sendMessage(googleApiClient, nodeList.get(i).getId(), path, data);
}
}
} else {
Toast.makeText(this, "Not connected", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Toast.makeText(this, "Connection failed", Toast.LENGTH_SHORT).show();
}
Fragment
public class NavigationRemoteFragment extends Fragment {
private static NavigationRemoteFragment navigationRemoteFragment = null;
private NavigationRemoteCallbacks callbackHandler = null;
private ImageButton navBtnCenter;
public static NavigationRemoteFragment getInstance(NavigationRemoteCallbacks handler) {
if (navigationRemoteFragment == null) {
navigationRemoteFragment = new NavigationRemoteFragment();
navigationRemoteFragment.callbackHandler = handler;
}
return navigationRemoteFragment;
}
public NavigationRemoteFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_navigation_remote, container, false);
navBtnCenter = (ImageButton)v.findViewById(R.id.navBtnCenter);
navBtnCenter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
callbackHandler.navigationRemoteSendCommand("/debug");
}
});
return v;
}
}
Callback interface
public interface NavigationRemoteCallbacks {
public void navigationRemoteSendCommand(String commandPath);
}
EDIT 1 code for MainGridPageAdapter
public class MainGridPageAdapter extends FragmentGridPagerAdapter {
private List<Fragment> fragmentList = null;
public MainGridPageAdapter(FragmentManager fm, List<Fragment> fragmentList) {
super(fm);
this.fragmentList = fragmentList;
}
#Override
public Fragment getFragment(int i, int i1) {
if (i1 < fragmentList.size()) return fragmentList.get(i1);
return null;
}
#Override
public int getRowCount() {
return 1;
}
#Override
public int getColumnCount(int i) {
return fragmentList.size();
}
You don't show the code for MainGridPageAdapter so I don't know how it is managing fragments. You mention that the problem occurs after a restart. Looking at the code in WearPlex.onCreate(), I suspect that the problem is caused fragments that are holding a reference to an old, destroyed instance of the activity.
A poorly documented behavior of FragmentManager is that it saves its state across restarts. This is often overlooked, resulting in duplicate fragment instances after a restart. The correct pattern for managing fragment creation in the onCreate() method of the host activity is:
if (savedInstanceState == null) {
// Not a restart
// Create a new instance of the fragment
// Add it to the fragment manager
} else {
// Restart
// The fragment manager has saved and restored the fragment instances
// Use findFragmentById() to get the fragment if you need it
}
You are not using savedInstanceState in onCreate() to test for restart. Are you seeing more fragments than you expect after restart? If so, the original fragments are holding a reference to the old activity, which was stopped, and has a disconnected GoogleApiClient. If the NavBtn of one of those fragments is clicked, you will see the "not connected" toast.
Update
The problem is caused by the way you are creating new instances of NavigationRemoteFragment, specifically the use of static member navigationRemoteFragment. After a restart, when the activity is recreated, the code calls NavigationRemoteFragment.getInstance(this). getInstance() finds navigationRemoteFragment not null because it is static, and does not create a new fragment. The fragment returned is the old one, which holds a reference to the old activity, which has been stopped and has a disconnected GoogleApiClient.
This could be confirmed by using the isDestroyed method and adding a some debug logging:
#Override
public void navigationRemoteSendCommand(String commandPath) {
if (isDestroyed()) {
Log.w("TEST", "This is an old instance of the activity");
}
sendMessage(commandPath, null);
}

Why my button is shown and than quickly hidden onResume

It's probably just a silly mistake but I cannot fix it. I have a Google+ sign in a button, which is shown when the user is not logged in. I also have a sign out button, which is GONE when the user is logged in.Everything works except that when I go back to the activity (onResume) I can see the red Google+ button for about a second and than it gets hidden and the sign out button appears. How can I remove this one second during which I can still see the Google+ button ?
This is my layout:
XML code:
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/startGameView"
android:src="#drawable/play"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/startGameView"
android:layout_centerHorizontal="true"
android:layout_marginBottom="46dp">
<!-- show achievements -->
<Button
android:id="#+id/show_achievements"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Achievements"/>
<!-- show leaderboards -->
<Button
android:id="#+id/show_leaderboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Leaderboard"/>
</LinearLayout>
Code in the activity:
public class StartActivity extends BaseGameActivity implements View.OnClickListener{
private ImageView mPlay;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
mPlay = (ImageView)findViewById(R.id.startGameView);
mPlay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//play animations
YoYo.with(Techniques.Pulse)
.duration(200)
.playOn(findViewById(R.id.startGameView));
Intent intent = new Intent(StartActivity.this, MainActivity.class);
startActivity(intent);
}
});
findViewById(R.id.sign_in_button).setOnClickListener(this);
findViewById(R.id.sign_out_button).setOnClickListener(this);
findViewById(R.id.show_achievements).setOnClickListener(this);
findViewById(R.id.show_leaderboard).setOnClickListener(this);
//mSignOutButton = (Button)findViewById(R.id.sign_out_button);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_start, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onSignInFailed() {
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}
#Override
public void onSignInSucceeded() {
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
findViewById(R.id.sign_out_button).setVisibility(View.VISIBLE);
}
#Override
public void onClick(View view) {
if (view.getId() == R.id.sign_in_button) {
beginUserInitiatedSignIn();
}else if (view.getId() == R.id.sign_out_button) {
signOut();
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}else if (view.getId() == R.id.show_achievements){
Toast.makeText(StartActivity.this,"achivements",Toast.LENGTH_SHORT).show();
startActivityForResult(Games.Achievements.getAchievementsIntent(getApiClient()), 1);
}else if(view.getId() == R.id.show_leaderboard){
Toast.makeText(StartActivity.this,"leaderboard",Toast.LENGTH_SHORT).show();
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(
getApiClient(), getString(R.string.number_of_solved_math_problems_leaderboard)), 2);
}
}
BaseActivity code:
public abstract class BaseGameActivity extends FragmentActivity implements
GameHelper.GameHelperListener {
// The game helper object. This class is mainly a wrapper around this object.
protected GameHelper mHelper;
// We expose these constants here because we don't want users of this class
// to have to know about GameHelper at all.
public static final int CLIENT_GAMES = GameHelper.CLIENT_GAMES;
public static final int CLIENT_APPSTATE = GameHelper.CLIENT_APPSTATE;
public static final int CLIENT_PLUS = GameHelper.CLIENT_PLUS;
public static final int CLIENT_ALL = GameHelper.CLIENT_ALL;
// Requested clients. By default, that's just the games client.
protected int mRequestedClients = CLIENT_GAMES;
private final static String TAG = "BaseGameActivity";
protected boolean mDebugLog = false;
/** Constructs a BaseGameActivity with default client (GamesClient). */
protected BaseGameActivity() {
super();
}
/**
* Constructs a BaseGameActivity with the requested clients.
* #param requestedClients The requested clients (a combination of CLIENT_GAMES,
* CLIENT_PLUS and CLIENT_APPSTATE).
*/
protected BaseGameActivity(int requestedClients) {
super();
setRequestedClients(requestedClients);
}
/**
* Sets the requested clients. The preferred way to set the requested clients is
* via the constructor, but this method is available if for some reason your code
* cannot do this in the constructor. This must be called before onCreate or getGameHelper()
* in order to have any effect. If called after onCreate()/getGameHelper(), this method
* is a no-op.
*
* #param requestedClients A combination of the flags CLIENT_GAMES, CLIENT_PLUS
* and CLIENT_APPSTATE, or CLIENT_ALL to request all available clients.
*/
protected void setRequestedClients(int requestedClients) {
mRequestedClients = requestedClients;
}
public GameHelper getGameHelper() {
if (mHelper == null) {
mHelper = new GameHelper(this, mRequestedClients);
mHelper.enableDebugLog(mDebugLog);
}
return mHelper;
}
#Override
protected void onCreate(Bundle b) {
super.onCreate(b);
if (mHelper == null) {
getGameHelper();
}
mHelper.setup(this);
}
#Override
protected void onStart() {
super.onStart();
mHelper.onStart(this);
}
#Override
protected void onStop() {
super.onStop();
mHelper.onStop();
}
#Override
protected void onActivityResult(int request, int response, Intent data) {
super.onActivityResult(request, response, data);
mHelper.onActivityResult(request, response, data);
}
protected GoogleApiClient getApiClient() {
return mHelper.getApiClient();
}
protected boolean isSignedIn() {
return mHelper.isSignedIn();
}
protected void beginUserInitiatedSignIn() {
mHelper.beginUserInitiatedSignIn();
}
protected void signOut() {
mHelper.signOut();
}
protected void showAlert(String message) {
mHelper.makeSimpleDialog(message).show();
}
protected void showAlert(String title, String message) {
mHelper.makeSimpleDialog(title, message).show();
}
protected void enableDebugLog(boolean enabled) {
mDebugLog = true;
if (mHelper != null) {
mHelper.enableDebugLog(enabled);
}
}
#Deprecated
protected void enableDebugLog(boolean enabled, String tag) {
Log.w(TAG, "BaseGameActivity.enabledDebugLog(bool,String) is " +
"deprecated. Use enableDebugLog(boolean)");
enableDebugLog(enabled);
}
protected String getInvitationId() {
return mHelper.getInvitationId();
}
protected void reconnectClient() {
mHelper.reconnectClient();
}
protected boolean hasSignInError() {
return mHelper.hasSignInError();
}
protected GameHelper.SignInFailureReason getSignInError() {
return mHelper.getSignInError();
}
If you cloned (or refreshed) the samples recently, you'll notice that GameHelper and BaseGameActivity are not longer used. There is an informative video about this change: Game On! - The death of BaseGameActivity. If you just implement the interfaces to get the callbacks for the state: GoogleApiClient.ConnectionCallbacks and GoogleApiClient.OnConnectionFailedListener your problem should go away.
More specific details on how to use these interfaces is at https://developers.google.com/games/services/training/signin
As I see in GameHelper class, it disconnects from googleApiClient on onStop() and connect on onStart(). This is causing of blinking buttons.
If you don't want to change GameHelper implementation, make some UI improvement to make it less annoying.

How do I make a google plus button with a custom layout in android?

I want to create a custom layout for my google plus button, any ideas? I've tried calling the OnClickEvent of the google plus button (that doesn't work) and I've tried changing the background image. Source code:
<com.google.android.gms.plus.PlusOneButton
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="#+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
plus:size="standard"
plus:annotation="inline"/>
holder.mPlusOneButton = (PlusOneButton) holder.content.findViewById(R.id.plus_one_button);
holder.mPlusOneButton.initialize("http://www.xxx.xx/", 0);
Add a custom button to your layout
Set OnClickListener to your custom button
Use the PlusClient as described here to handle the login procedure
As example I can provide my controller class for handling Google Plus login:
public class GooglePlusLoginController implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener {
public static final int REQUEST_CODE_SIGN_IN = 100;
private PlusClient googlePlusClient;
private ConnectionResult connectionResult;
private Activity activity;
public GooglePlusLoginController(Activity activity) {
this.activity = activity;
googlePlusClient = new PlusClient.Builder(activity, this, this)
.setActions("http://schemas.google.com/AddActivity")
.setScopes(Scopes.PLUS_LOGIN) // Space separated list of scopes
.build();
googlePlusClient.connect();
}
// call this method in your click handler
public void login() {
try {
connectionResult.startResolutionForResult(activity, REQUEST_CODE_SIGN_IN);
} catch (IntentSender.SendIntentException e) {
googlePlusClient.connect();
}
}
// call this method in your activity's onActivityResult
public void onActivityResult() {
if(!googlePlusClient.isConnected() && !googlePlusClient.isConnecting()) {
googlePlusClient.connect();
}
}
#Override
public void onConnected(Bundle bundle) {
// connected, you can now get user's data from
// googlePlusClient.getCurrentPerson()
}
#Override
public void onDisconnected() {
}
#Override
public void onConnectionFailed(ConnectionResult result) {
connectionResult = result;
}
private void logout() {
if(googlePlusClient.isConnected()) {
googlePlusClient.clearDefaultAccount();
googlePlusClient.disconnect();
googlePlusClient.connect();
}
}
}

my Google+1 button is grayed out and not working?

i was trying to integrate G+ button in ma app.The G+ buttons grayed out.and its not counting.how to turns red ?
public class HomeActivity extends SherlockActivity implements ConnectionCallbacks, OnConnectionFailedListener{
private static final String URL = "https://play.google.com/store/apps/details?id=com.phoneix.allu";
private static final int PLUS_ONE_REQUEST_CODE = 0;
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
private ProgressDialog mConnectionProgressDialog;
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;
private PlusOneButton mPlusOneStandardButton;
#Override
public void onCreate(Bundle pBundle) {
super.onCreate(pBundle);
setContentView(R.layout.dashboard);
mPlusOneStandardButton = (PlusOneButton) findViewById(R.id.plus_one_standard_button);
mPlusClient = new PlusClient.Builder(this, this, this)
.build();
}
#Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
#Override
protected void onResume() {
super.onResume();
// Refresh the state of the +1 button each time we receive focus.
mPlusOneStandardButton.initialize(URL, PLUS_ONE_REQUEST_CODE);
}
#Override
public void onDisconnected() {
// Nothing to do.
}
#Override
public void onConnectionFailed(ConnectionResult result) {
if (mConnectionProgressDialog.isShowing()) {
// The user clicked the sign-in button already. Start to resolve
// connection errors. Wait until onConnected() to dismiss the
// connection dialog.
if (result.hasResolution()) {
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
}
// Save the intent so that we can start an activity when the user clicks
// the sign-in button.
mConnectionResult = result;
}
public void onConnected(Bundle connectionHint) {
mPlusOneStandardButton.initialize(URL, PLUS_ONE_REQUEST_CODE);
}
#Override
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
mConnectionResult = null;
mPlusClient.connect();
}
}
}
Try out this:
In xml file:
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="92dp" >
</com.google.android.gms.common.SignInButton>
</RelativeLayout>
In your activity get that button:
#Override
public void onCreate(Bundle pBundle) {
super.onCreate(pBundle);
setContentView(R.layout.dashboard);
findViewById(R.id.sign_in_button).setOnClickListener(new OnClickListener() {
#Override
public void onClick
(View v) {
Intent i = new Intent(getApplicationContext(),YourActivity.class);
startActivity(i);
}
});
}
The problem is with the latest update of google play services.
Once I uninstalled all updates of google play services from app's settings,all +1 buttons are showing up fine.
Let's hope google will fix their update.
The new Google Play update changed the interface of the plusOne button, hence breaking all plusOne button based on the "old" Google play service SDK.
If you checkout their samples, you'll discover they have changed the interface for the plusOnButton.initialize, which no longer takes a "plusOneClient", but a URL.
To fix, download the latest (v13) Google Play Services using your "Android SDK Manager", and import it back to your project.

Categories

Resources