I want to make a test app which uses android facebook sdk.
I have followed all the steps mentioned at http://developers.facebook.com/docs/mobile/android/build/
I am using following snippet given at this link
public class AndroidFacebookActivity extends Activity {
Facebook facebook = new Facebook("282009485165563");
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
facebook.authorize(this, new DialogListener() {
#Override
public void onComplete(Bundle values) {}
#Override
public void onFacebookError(FacebookError error) {}
#Override
public void onError(DialogError e) {}
#Override
public void onCancel() {}
});
}
However when i run this app on emulator, I get following error
The Appliaction has stopped unexpectedly.
from Logcat i see following
java.lang.NoClassDefFoundError: com.facebook.android.Facebook
I have built the facebook application and installed it successfully before running my app.
Please help.
Thanks in Advance
I was able to do it.
Right click on facebook project->Android->check IsLibrary option.
now go to your app, and when you go to add library, it would list facebook library.
just select it and you are good to go...
Related
I am new to in app subscription. I have looked at Google's official documentation but that wasn't helpful. In my app I want to integrate monthly in app subscription. There are no proper tutorials for subscription on YouTube either, there are only for one time in app products. All I know is that I need a product Id and license key for in app purchases and I have them both with me. Can anyone help me with subscription? Here is my code
public class MainActivity extends Activity implements BillingProcessor.IBillingHandler{
BillingProcessor bp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
bp = new BillingProcessor(this, Constants.base64EncodedPublicKey, this);
bp.purchase(MainSellerActivity.this,"subscription_product_id");
}
#Override
public void onProductPurchased(String productId, TransactionDetails details) {
Toast.makeText(this, "Subscribed Successfully", Toast.LENGTH_SHORT).show();
}
#Override
public void onPurchaseHistoryRestored() {
}
#Override
public void onBillingError(int errorCode, Throwable error) {
}
#Override
public void onBillingInitialized() {
}
The provided code above is a little bit modified, but this is basically where I am stuck at. Everything is working fine with when I use android.test.purchased in place of product Id, but I am getting an error when I use an actual product Id. Please help. If possible please provide a complete code for subscription.
Try this library.it is easy to integrate
android-inapp-billing-v3
I'm developing a game for Android that has Facebook login and I faced the following weird behaviour when trying to logout:
if user press Facebook logout button, closes the app and then reopens again, the user is still logged in (= access token still valid).
As a test, I checked the access token after logout and it is null as it should be, but if I close and reopen the app then the access token is again not null.
It seems that Facebook caches the access token and takes it from cache even after logout.
I tried using native Facebook button and also LoginManager.getInstance.logout(); I have initialized Facebook sdk on the top of the onCreate, before setContent() and I followed the procedure on Facebook docs, but same result.
I'm using Facebook sdk 4.6.0 and I faced this problem on Android 4.2.2 and 4.4.2.
EDIT
Here's the code:
- Facebook button:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_settings);
btnFacebookLogout.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException e) {
}
});
}
- normal button:
btnNormalLogout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LoginManager.getInstance().logOut();
}
});
Any suggestion?
Thanks in advance
Well, i`ve been fighting that damn sdk for about an hour and discovered a simple workaround for that logout issue.
Just try to do the following:
LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_ONLY)
Pros: LoginManager.getInstance().logOut() works fine in this case.
Cons: the authentication will always appear in a webview dialog.
In one of the activities in my Android app I want the user to be able to post something to there wall on facebook. So far I have successfully allowed the user to log in using facebook..authorize(this, new DialogListener() { ... and this seems to work fine.
Now I am trying to use the following code in a Button onClickListener to allow the user to post something to there own wall.
facebook.dialog(this, "feed", new DialogListener() {
#Override
public void onComplete(Bundle values) {
}
#Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
Log.v("error", e.toString());
}
#Override
public void onError(DialogError e) {
Log.v("error", e.toString());
}
#Override
public void onCancel() {
}});
It appears to work as it shows the dialog but it disappears after about 2 or 3 seconds and also seems to close the activity from where it was called.
Logcat isn't very helpful... the last log just prints the url and doesn't show an error or anything. What am I doing wrong?
Looks like its the same issue as this:
http://developers.facebook.com/bugs/282710765082535
Except that I was using Android 2.1. Changed to 2.2 and it now works fine
I am implementing face book api in my application,I have one login
button for Facebook.
Whenever I press this button for Facebook login, it is working fine. Now I want to redirect another activity while I was successfully login with Facebook.
How to implement to do this, how can I implement call back method for that? Please help me.
I have used the Facebook SDK, as can be seen in my example:
mFacebook.authorize(this, new String[] { "friends_birthday", "friends_about_me", "read_friendlists" }, new DialogListener() {
#Override
public void onFacebookError(FacebookError arg0) {
}
#Override
public void onError(DialogError arg0) {
}
#Override
public void onComplete(Bundle arg0) {
//start activity here.
}
#Override
public void onCancel() {
}
});
To start an activity in general (put this in onComplete()):
Intent intent = new Intent(context, TargetActivity.class);
startActivity(intent);
Also, make sure that you add the Target Activity into your AndroidManifest.xml. You must do this in <activity/> tags. Without this, your application will crash.
I have a simple problem (maybe) with my code... I have a facebook button that will open the login dialog for the user, which works fine. but if there is no internet it'll take forever and I don't know how to timeout it... I've put it in a 'try' block, but it still takes way too long
this is the code for it
try{
facebook.authorize(this,new String[] {"publish_stream", "read_stream", "offline_access"}, new DialogListener() {
#Override
public void onComplete(Bundle values) {}
#Override
public void onFacebookError(FacebookError error) {}
#Override
public void onError(DialogError e) {}
#Override
public void onCancel() {}
});
} catch(Exception e) {
e.printStackTrace();
}
any help will be highly appreciated
P.S. this applies for the post into facebook as well
Why not put in some logic to detect whether there is a network connection and if not, do something nice for your users like tell them you require one. Check out this answer for more info.
I just faced same issue, and you have 2 way to do:
Edit Util.java in facebook SDK, add 1 line like conn.setTimeout(xxx);
Upgrade to newest facebook SDK, now it have timeout mechanism.