Like Blog Post Facebook Button - android

I have a blog which shows a Facebook like button under every post.
I want to add that button, which upon click, just like that blog post, to an android app. Is that possible? If yes, then how?
Do I have to use Facebook SDK?
This is how the button is displayed in the blog.
<iframe allowTransparency='true' expr:src='"http://www.facebook.com/plugins/like.php?href=" + data:post.canonicalUrl+"&send=false&layout=button_count&show_faces=false&width=90&action=like&font=arial&colorscheme=light&height=21"' frameborder='0' scrolling='no' style='border:none; overflow:hidden; width:90px; height:21px;'/>

Try this : It's working for me
<com.facebook.widget.LikeView
android:id="#+id/like"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Like"
/>
And add following code in your android class file:
LikeView likeView = (LikeView) findViewById(R.id.like);
likeView.setObjectId("Your URL);

Related

How to set standard Facebook login button apperancce on Android?

Does anyone know how to restore the standard facebook button appearance ?
My code:
<com.facebook.login.widget.LoginButton
android:id="#+id/lpFacebookLoginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="14dp"
android:paddingBottom="14dp"
android:layout_marginTop="#dimen/small_vertical_margin"
android:layout_marginBottom="#dimen/small_vertical_margin"/>
and how it looks now :
it should look like this :
how Facebook SDK is added in gradle:
implementation 'com.facebook.android:facebook-login:latest.release'

Facebook Android SDK 4.5 LikeView not working

I am trying to integrate latest facebook android sdk(v 4.5) Like button. This is what I have put in my facebook_layout.xml
<com.facebook.share.widget.LikeView
android:layout_marginTop="30dp"
android:id="#+id/like_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
</com.facebook.share.widget.LikeView>
And I have a fragment where I am putting this like view onCreate method to
initialize the view
LikeView likeView = (LikeView)facebookview.findViewById(R.id.like_view);
likeView.setEnabled(true);
likeView.setLikeViewStyle(LikeView.Style.BOX_COUNT);
likeView.setObjectIdAndType(
"https://www.facebook.com/FacebookDevelopers",
LikeView.ObjectType.PAGE);
Apart from this I have also put my app id in AndroidManifest.xml as mentioned here
But I am still not able to get the like to work. When I Click on the like button it just opens up a black facebook activity and for few seconds and closes it, and there are no likes happening on this page or the same page i have created for testing.
I have resolved this issue by adding my facebook user as a Tester/Developer to my facebook android App.
Reference: https://developers.facebook.com/docs/apps/security
Note: you can set the error listener to the object of LikeView for the better understanding of what error you are getting.
likeView.setOnErrorListener(new LikeView.OnErrorListener() {
#Override
public void onError(FacebookException e) {
Log.e(TAG, e.getMessage(), e);
}
});

Google Play Games achievement unlocked popup not showing

I'm unlocking achievement using this simple method from developers docs:
Games.Achievements.unlock(getApiClient(), "my_achievement_id");
Achievement unlocks, but no popup shows up. There is also no popup when logged in to Google Play Games - which is connected.
Just add a view to the layouts you want to display achievements on like this:
<FrameLayout
android:id="#+id/gps_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
When you have your layout ready you neet to execute this inside your Activity or Fragment:
Games.setViewForPopups(getApiClient(), findViewById(R.id.gps_popup));
You have to be sure, that your GoogleApiClient is connected though, otherwise your app will crash.
<FrameLayout
android:id="#+id/gps_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
This is the same in Jacek KwiecieĊ„ answer
GamesClient gamesClient = Games.getGamesClient(MainActivity.this, GoogleSignIn.getLastSignedInAccount(context));
gamesClient.setViewForPopups(findViewById(R.id.gps_popup));
This changed because setViewForPopups with 2 parameters is deprecated.
Jacek and user3782779 answers didn't work for me, I had to do the following:
GamesClient gamesClient = Games.getGamesClient(this, GoogleSignIn.getLastSignedInAccount(this));
gamesClient.setViewForPopups(findViewById(android.R.id.content));
gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
Had the same problem. I have solved it by adding icon to the achievement. I am not kidding, it is really strange but it started to work after that. Please note that I am talking about not published project, I was just testing my app and wondering what is going on.
The ONLY view that worked for my case of having multiple activities was:
activity.window.decorView.findViewById(android.R.id.content)
I had the same problem with the achievement popup. The "Welcome Back" popup was showing correctly by just using my own View, but once I started opening other screens where I wanted to show the achievement unlocked popup, it was not working. The only thing that ended up working was using the content view from the decorView
val gamesClient = Games.getGamesClient(activity, googleSignInAccount)
gamesClient.setGravityForPopups(Gravity.TOP or Gravity.CENTER_HORIZONTAL)
gamesClient.setViewForPopups(activity.window.decorView.findViewById(android.R.id.content))
You can call this code from any new activity you open and the pop-up will show up there as soon as you unlock your achievements.

Android Google plus Sign out button looks different from sign in button in Google tutorial docs

I am following the steps mentioned in Google developers site to implement sign in and sign out in my app.
The code to add the sign-in and sign-out button as mentioned there is:
<!-- sign-in button -->
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- sign-out button -->
<Button
android:id="#+id/sign_out_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign Out"
android:visibility="gone" />
In the sample mentioned over there, the sign out button looks very different(and odd) from the sign out button.
Is this because the sign out button is not taken from com.google.android.gms?
Is there a proper sign-out button available in com.google.android.gms?
There is no sign-out button provided by google.
If you would like extra buttons in the same style as google's, you will need to create them yourself.
But it's a lot easier than it sounds, there are many resources provided by Google to show you how to create a button that looks just like a Google button. Take a look over here:
https://developers.google.com/+/branding-guidelines
Here is a little example I made in microsoft paint to show you the kind of stuff you can make!
You can make your button look the same as <com.google.android.gms.common.SignInButton>, adding a predefined style to your button with the xml tag style:
style="#style/FirebaseUI.Button.AccountChooser.GoogleButton"
Note that its a FirebaseUI style and you can put the Button text that you want.
How about : change text Sign in to Sign out.
layout.xml
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_out_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
kotlin.kt
val signOutButton: SignInButton = findViewById(R.id.sign_out_button)
signOutButton.setSize(SignInButton.SIZE_STANDARD)
signOutButton.setOnClickListener { signOut() }
val txtLogout = signOutButton.getChildAt(0) as TextView
try {
txtLogout.setText("Sign out")
} catch (e: Exception) {
//e.printStackTrace()
}

I need exact simple instructions for placing a simple hyperlink to a web site in a java android application

I am a PHP programmer who is having to do some work in the android development environment. I have 2 books on this and have tried 30 search engine topics and still have not found just a simple example of everything that you need to do to place a working hyperlink in a Java android application.
I just need a very simple but complete ingredient for doing so. I have the 2.2 android development environment with Eclipse and an emulator. I have tried the WebView control which just simply loads a web site into the window when I run the application. I need a basic hyperlink to a web site example.
I don't want anything else thrown in with it (just an application with a working hyperlink and nothing else), because I am trying to learn the different controls bit by bit along with the Java and XML code that controls them.
This is so different from PHP, ASP, etc. that it has me totally fishing for answers. Thanks;
Cullan
Android is a GUI, not a Web browser. Hence, "place a working hyperlink in a Java android application" is akin to "place a snowplow blade on a dishwasher" or "implement a Web app in COBOL". It is technically possible but probably is the incorrect solution to whatever problem it is that you really trying to solve.
So, as MatrixFrog indicates, one possibility is to use a TextView and some HTML:
TextView tv=(TextView)findViewById(R.id.whatever_you_called_it_in_your_layout);
tv.setText(Html.fromHtml("Who knows?"));
But, doing that would be unusual in a GUI environment. Most developers would use a button, or a menu choice, or something along those lines, to trigger viewing some URL.
CommonsWare, That is not what I call a detailed explanation or example of how to place a hyperlink inside an android application. It is just a small snippet of code with no further explanation. I found what works on my own and here is the Java code for it:
package com.practice.weblink;
import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.widget.TextView;
public class WebLink extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textview = (TextView) findViewById(R.id.hyperlink);
Linkify.addLinks(textview, Linkify.WEB_URLS);
}
}
The TextView has the following qualities in the main.xml file:
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/hyperlink"
android:id="#+id/hyperlink"
android:autoLink="web"
>
</TextView>
The strings.xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">WebLink</string>
<string name="hyperlink">http://google.com</string>
</resources>
That is how you give a working example of something. Next time don't assume that people can just piece together what you are mentioning in your answer.
How about using onClick in the XML layout file?
layout.xml
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:clickable="true"
android:text="#string/market_url"
android:textColor="#00f"
android:onClick="openURL"
/>
MyActivity.java
public void openURL(View v) {
String url = ((TextView) v).getText().toString();
final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url));
startActivity(intent);
}

Categories

Resources