Related
I'm having an issue with my apps in-app billing. I thought it was working well for the last week, but I'm having an unexpected result.
I have about 10 items for sale. Each item sets a shared pref value to true when purchased/querying inventory if it is bought. One item, is a "Buy All" button, when bought, it's suppose to set the values for all the others to true. This was working well, the problem arises when I add new items to buy. The "buy all" should give access to those as well, but it seems it's not.
I'll try to make my code as simple as possible while still showing the needed info:
BaseActivity.java(where all in-app purchases set up):
//SKU FOR our products
static final String SKU_W31 = "workout_31";
static final String SKU_W32 = "workout_32";
static final String SKU_W37 = "workout_37";
static final String SKU_ALL = "all_workouts";
//is paid?
public boolean m31paid = false;
public boolean m32paid = false;
public boolean m37paid = false;
public boolean mAllPaid = false;
IabHelper mHelper;
IabBroadcastReceiver mBroadcastReceiver;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0);
mHelper = new IabHelper(this, base64EncodedPublicKey);
//SET FALSE FOR LIVE APP
mHelper.enableDebugLogging(false);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d(LOG, "Problem setting up in app billing: " + result);
} else Log.d(LOG, "set up correctly!");
if (mHelper == null) return;
mBroadcastReceiver = new IabBroadcastReceiver(BaseActivity.this);
IntentFilter broadcastFilter = new IntentFilter(IabBroadcastReceiver.ACTION);
registerReceiver(mBroadcastReceiver, broadcastFilter);
// IAB is fully set up. Now, let's get an inventory of stuff we own.
Log.d(LOG, "Setup successful. Querying inventory.");
try {
mHelper.queryInventoryAsync(mGotInventoryListener);
} catch (IabHelper.IabAsyncInProgressException e) {
complain("Error querying inventory. Another async operation in progress.");
}
}
});
}
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(LOG, "Query inventory finished.");
SharedPreferences.Editor editor = getSharedPreferences("my_pref", MODE_PRIVATE).edit();
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
Purchase w37Purchase = inventory.getPurchase(SKU_W37);
m37paid = (w37Purchase != null && verifyDeveloperPayload(w37Purchase));
Log.d(LOG, "User has workout 37" + (m37paid ? "BOUGHT" : "NOT BOUGHT"));
if (w37Purchase != null) {
editor.putBoolean("workout37", true);
editor.apply();
}
Purchase w32Purchase = inventory.getPurchase(SKU_W32);
m32paid = (w32Purchase != null && verifyDeveloperPayload(w32Purchase));
Log.d(LOG, "User has workout 32" + (m32paid ? "BOUGHT" : "NOT BOUGHT"));
if (w32Purchase != null) {
editor.putBoolean("workout32", true);
editor.apply();
}
Purchase w31Purchase = inventory.getPurchase(SKU_W31);
m31paid = (w31Purchase != null && verifyDeveloperPayload(w31Purchase));
Log.d(LOG, "User has workout 31" + (m31paid ? "BOUGHT" : "NOT BOUGHT"));
if (w31Purchase != null) {
editor.putBoolean("workout31", true);
editor.apply();
}
Purchase wAllPurchase = inventory.getPurchase(SKU_ALL);
mAllPaid = (wAllPurchase != null && verifyDeveloperPayload(wAllPurchase));
Log.d(LOG, "User has " + (mAllPaid ? "BOUGHT" : "NOT BOUGHT"));
if (wAllPurchase != null) {
editor.putBoolean("workout31", true);
editor.putBoolean("workout32", true);
editor.putBoolean("workout37", true);
editor.apply();
}
}};
I then have the methods for buying that I put in the onClick of the corresponding buttons:
public void onBuy31ButtonClicked (View arg0) {
Log.d(LOG, "Buy 31 button clicked.");
if (m31paid) {
Toast.makeText(getApplicationContext(), R.string.already_bought, Toast.LENGTH_LONG).show();
return;
}
Log.d(LOG, "launching purchase for 31");
String payload = "";
try {
mHelper.launchPurchaseFlow(this, SKU_W31, RC_REQUEST, mPurchaseFinishedListener, payload);
} catch (IabHelper.IabAsyncInProgressException e) {
Toast.makeText(getApplicationContext(), R.string.purchase_error, Toast.LENGTH_LONG).show();
}
}
public void onBuy32ButtonClicked (View arg0) {
Log.d(LOG, "Buy 32 button clicked.");
if (m32paid) {
Toast.makeText(getApplicationContext(), R.string.already_bought, Toast.LENGTH_LONG).show();
return;
}
Log.d(LOG, "launching purchase for 32");
String payload = "";
try {
mHelper.launchPurchaseFlow(this, SKU_W32, RC_REQUEST, mPurchaseFinishedListener, payload);
} catch (IabHelper.IabAsyncInProgressException e) {
Toast.makeText(getApplicationContext(), R.string.purchase_error, Toast.LENGTH_LONG).show();
}
}
public void onBuy37ButtonClicked (View arg0) {
Log.d(LOG, "Buy 37 button clicked.");
if (m37paid) {
Toast.makeText(getApplicationContext(), R.string.already_bought, Toast.LENGTH_LONG).show();
return;
}
Log.d(LOG, "launching purchase for 37");
String payload = "";
try {
mHelper.launchPurchaseFlow(this, SKU_W37, RC_REQUEST, mPurchaseFinishedListener, payload);
} catch (IabHelper.IabAsyncInProgressException e) {
Toast.makeText(getApplicationContext(), R.string.purchase_error, Toast.LENGTH_LONG).show();
}
}
public void onBuyAllButtonClicked (View arg0) {
Log.d(LOG, "Buy all button clicked.");
if (m32paid) {
Toast.makeText(getApplicationContext(), R.string.already_bought, Toast.LENGTH_LONG).show();
return;
}
Log.d(LOG, "launching purchase for all");
String payload = "";
try {
mHelper.launchPurchaseFlow(this, SKU_ALL, RC_REQUEST, mPurchaseFinishedListener, payload);
} catch (IabHelper.IabAsyncInProgressException e) {
Toast.makeText(getApplicationContext(), R.string.purchase_error, Toast.LENGTH_LONG).show();
}
}
My mPurchaseFinishedListener:
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(LOG, "Purchase finished: " + result + ", purchase: " + purchase);
SharedPreferences.Editor editor = getSharedPreferences("my_pref", MODE_PRIVATE).edit();
// if we were disposed of in the meantime, quit.
if (mHelper == null) return;
if (result.isFailure()) {
complain("Error purchasing: " + result);
return;
}
if (purchase.getSku().equals(SKU_W30)) {
editor.putBoolean("workout30", true);
editor.apply();
return;
}
if (purchase.getSku().equals(SKU_W31)) {
editor.putBoolean("workout31", true);
editor.apply();
return;
}
if (purchase.getSku().equals(SKU_W32)) {
editor.putBoolean("workout32", true);
editor.apply();
return;
}
if (purchase.getSku().equals(SKU_W37)) {
editor.putBoolean("workout37", true);
editor.apply();
return;
if(purchase.getSku().equals(SKU_ALL)) {
editor.putBoolean("workout31", true);
editor.putBoolean("workout32", true);
editor.putBoolean("workout37", true);
editor.apply();
return;
}
Then where the data is, I simply have an if statement to check the boolean value as such:
xpandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
SharedPreferences pref = getApplicationContext().getSharedPreferences("my_pref", MODE_PRIVATE);
boolean w31 = pref.getBoolean("workout31", false);
boolean w32 = pref.getBoolean("workout32", false);
boolean w37 = pref.getBoolean("workout37", false);
if (groupPosition == 2) {
if(w31 == true) {
if (childPosition == 0) {
Intent intent = new Intent(getApplicationContext(), WorkoutDaysActivity.class);
intent.putExtra("workout", "w31w1");
startActivity(intent);
}
if (childPosition == 1) {
Intent intent = new Intent(getApplicationContext(), WorkoutDaysActivity.class);
intent.putExtra("workout", "w31w2");
startActivity(intent);
}
}else Toast.makeText(getApplicationContext(), "Sorry, but you need to purchase these workouts from the menu.", Toast.LENGTH_LONG).show();
}
All child items have the same code as above, switching out the w31 with w32 and w37.
I have taken out most purchases to try to cut back on code and still get the point across, but basically what is happening is 31 and 32 were added before, and then I used the purchase all button, they work. But I added 37 in a later update, and my theory was that the boolean value would change for it when it queries for all workouts and see it was purchased. In reality though, when I click 37 in the expandable list view, I get the toast saying it needs to be purchased, and when I go to the purchase page and click "Purchase All", I get the toast saying it was already purchased.
Does anyone see anything wrong with my code? Thanks a lot, this is causing huge problems!
Cause of async operations you may have a race condition. Your activity with expandable list view should be registered to all changes in your SharedPreferences.
When updating current user unique fields, not getting proper exception message from parse.
If i update username with existing username and send update request (save) using parse it is showing correctly.If now i reset the username back and give the existing email and update , it is returning username exists exception message instead of returning email exists message.
public void updateUserData(UserModel userModel) throws ParseException {
ParseUser user = ParseUser.getCurrentUser();
if (user != null && userModel != null){
if(userModel.getFirstName() != null) {
user.put(Constants.FIRST_NAME, userModel.getFirstName());
}
if(userModel.getLastName() != null) {
user.put(Constants.LAST_NAME, userModel.getLastName());
}
if(userModel.getUsername() != null) {
user.setUsername(userModel.getUsername());
}
if(userModel.getEmail() != null) {
user.setEmail(userModel.getEmail());
}
if (userModel.getPassword() != null) {
user.setPassword(userModel.getPassword());
}
if (userModel.getAvatar() != null) {
ParseFile file = new ParseFile(System.currentTimeMillis() + ".jpg", userModel.getAvatar());
file.save();
user.put("imageFile", file);
}
user.save();
}
}
Thanks in advance,
Please post if any have faced such issues.
change this code.
if (userModel.getAvatar() != null) {
final ParseFile file = new ParseFile(System.currentTimeMillis() + ".jpg", userModel.getAvatar());
file.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
// TODO Auto-generated method stub
if (e == null) {
// success
user.put("imageFile", file);
// exit from one thered
UpdateDatabase(user);
} else {
// fail
e.getMessage();
}
}
});
}
then this code copy & paste.
protected void UpdateDatabase(ParseUser user) {
// TODO Auto-generated method stub
// before update parse table then set user permisson like read & write
user.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
// TODO Auto-generated method stub
if (e == null) {
// success
} else {
// fail
e.getMessage();
}
}
});
}
I did the following:
#Override
public void onResume() {
super.onResume();
// For scenarios where the main activity is launched and user
// session is not null, the session state change notification
// may not be triggered. Trigger it if it's open/closed.
Session session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
and
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
makeMeRequest(session);
} else if (state.isClosed()) {
}
}
and
private void makeMeRequest(final Session session) {
Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
if (session == Session.getActiveSession()) {
if (user != null) {
log.d("creating fragment"); //<<<<<<<<<<<<<<<
//creating a fragment when the request is complete
.....
}
}
if (response.getError() != null) {
}
}
});
request.executeAsync();
}
Please read the comment of the first code clause: as suggested by Facebook, that code works because without it, the fragment is not created in certain scenarios even though I'm logged in, but with this code, onCompleted is called twice and I get an exception. see my logging in the 3rd code clause: log.d("creating fragment") - I see it twice before the exception occurred.
Any idea what am I missing?
p.s.: I have a main activity that calls a fragment where the user can login to facebook
Session session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {
onSessionStateChange(session, session.getState(), null);
}
don't use above code in onresume(),
Activity normally called first oncreate() and then onresume().so that it's called twice.
please check it.
I am trying to upload a picture to facebook using the sdk for android. When i run the code my app crashes. Can someone help me. I am not too sure how to use the sdk. Is there another way to upload pictures?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
// start Facebook Login
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
#Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request.newUploadPhotoRequest(session, bm, new Request.Callback() {
#Override
public void onCompleted(Response response)
{
// TODO Auto-generated method stub
if (isFinishing()) {
return;
}
if (response.getError() != null) { // [IF Failed Posting]
Log.d("", "photo upload problem. Error="+response.getError() );
} // [ENDIF Failed Posting]
Object graphResponse = response.getGraphObject().getProperty("id");
if (graphResponse == null || !(graphResponse instanceof String) ||
TextUtils.isEmpty((String) graphResponse)) { // [IF Failed upload/no results]
Log.d("", "failed photo upload/no response");
} else { // [ELSEIF successful upload]
fbPhotoAddress = "https://www.facebook.com/photo.php?fbid=" +graphResponse;
}
}
} ).executeAsync();
}
}
});
}
}
I want to share the text/image programatically from my app on facebook.How should I proceed for that.After lots of googling I found lots of sample apps but as the latest FB SDK is deprecated those APIs it is hard to find the way using new SDK.Please help me out for this issue.
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x- howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(getApplicationContext(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getApplicationContext(),
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(getApplicationContext(),
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}
This is what i get for fb API 3.5 doc & which I have tried but it is crashing the app by saying session is null.
Here your session is null because you have not started it yet.
You have to start your session after login.
You can achieve this by using
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
});
For more information try going through the tutorials from http://developers.facebook.com/docs/android/scrumptious/authenticate/. These are really helpful.
Here is how I implemented --
This class is used to do initial stuffs to facebook
LoginFacebookClass
/**
* for integrating facebook in your app..
* Firstly import FacebookSDK lib project and add in your project as lib project.
* then
* create an instance of this class
* and, then call the facebook login method by passing reference of your activity and true, if you want to fetch data and, false if you want to share data on faceboko
* Please do whatever you want in the interface callback methods
* implemented by this class
*
*
* Note: Please write a line exactly in your activity's on activity result as
* -- Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
* here, 'Session' is Class of Facebook.
* 'this' is reference of your activity
*/
public class FacebookLoginClass implements FB_Callback
{
Context context;
FBImPlmentation fbImpl;
String mImageURLString = "", mPhotoTypeString = "";
// private FBBean userDataBean;
/**
* constructor for FacebookLoginClass
* #param con : context of activity
* #param string
* #param mImageURLString2
*/
public FacebookLoginClass(Context con)
{
this.context = con;
fbImpl = FBImPlmentation.getInstance(context, this);
}
public FacebookLoginClass(Context con, String imageURLString, String photoType)
{
this.context = con;
fbImpl = FBImPlmentation.getInstance(context, this);
mImageURLString = imageURLString;
mPhotoTypeString = photoType;
}
/**
* method for initiating facebook Login
* #param isDataFetch : true for fetching user data, false for sharing on wall
*/
public void facebookLogin(boolean isDataFetch)
{
fbImpl.CheckSession(isDataFetch);
}
/**
* method for facebookLogout
*/
public void facebookLogout()
{
fbImpl.fbLogout();
}
#Override
public void onLogin(Session s)
{
fbImpl.getDataFromFB(s);
}
#Override
public void onLoginForShareData()
{
Log.e("facebook.", "True in..........");
Bundle postParams = new Bundle();
postParams.putString("name", "");
postParams.putString("caption", "");
postParams.putString("description", " Android, share your pics and videos");
if (mPhotoTypeString.equalsIgnoreCase("photo"))
{
postParams.putString("picture", mImageURLString);
}
else
{
postParams.putString("link", "");
}
fbImpl.publishFeedDialog(postParams);
}
#Override
public void onAuthFailiure()
{
}
#Override
public void onUserData(FBBean fbUserDataBean)
{
try
{
if (BejoelUtility.isNetworkAvailable(context))
{
String imageURLString = "http://graph.facebook.com/" + fbUserDataBean.getUserID() + "/picture?type=large";
new FacebookTwitterLoginAsyncTask(context, fbUserDataBean.getFirstNAme(), fbUserDataBean.getLastName(),
fbUserDataBean.getMailId(), fbUserDataBean.getUserBday(), fbUserDataBean.getUserSex(), "", "", imageURLString,
fbUserDataBean.getAccessToken(), "facebook").execute();
}
else
{
BejoelUtility.showMsgDialog(context, context.getString(R.string.app_name), context.getString(R.string.no_internet));
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
#Override
public void onPost(boolean postStatus)
{
// TODO Auto-generated method stub
}
#Override
public void onFriendRequest(boolean shareAppStatus)
{
// TODO Auto-generated method stub
}
#Override
public void onLogout(boolean status)
{
// TODO Auto-generated method stub
}
}
This class interact with facebook
public class FBImPlmentation
{
public static List<String> READ_PERMISSIONS = Arrays.asList("email");
public List<String> WRITE_PERMISSIONS = Arrays.asList("publish_actions");
private static FBImPlmentation fbImpl;
private FB_Callback mInterface;
private static Activity activity;
boolean isDataFetch=false;
private String mAccessTokenString = "";
/**
* constructor for facebookImplementation
* #param con :context of activity via FacebookLogin Class
* #param mInterface : refrence of class implementing FB_Callback interface..as in our case,
* it is refrence of FacebookLogin Class
* #return : instance of FBImplementation
*/
public static FBImPlmentation getInstance(Context con, FB_Callback mInterface)
{
activity = (Activity) con;
if (fbImpl == null)
fbImpl = new FBImPlmentation();
fbImpl.mInterface = mInterface;
return fbImpl;
}
/**
* method to be called for facebook Logout
*/
public void fbLogout()
{
if (Session.getActiveSession() != null)
{
Session.getActiveSession().closeAndClearTokenInformation();
}
Session.setActiveSession(null);
mInterface.onLogout(true);
}
/**
* method for checking session.
* if session is not open, then open a new session.
* If session is already open then..just call the fbcallback onlogin method
* #param isDataFetch2
*/
public void CheckSession(boolean isDataFetch2)
{
fbImpl.isDataFetch= isDataFetch2;
Session s = Session.getActiveSession();
if (s != null && s.isOpened())
{
if(isDataFetch)
mInterface.onLogin(s);
else
mInterface.onLoginForShareData();
mAccessTokenString = s.getAccessToken();
}
else
{
Session.openActiveSession(activity, true, mFBCallback);
}
}
// Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(activity, permissions);
Session.StatusCallback mFBCallback = new Session.StatusCallback()
{
// call method is always called on session state change
#Override
public void call(Session session, SessionState state, Exception exception)
{
if (session.isOpened())
{
List<String> permissions = session.getPermissions();
if (!isSubsetOf(READ_PERMISSIONS, permissions))
{
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(activity, READ_PERMISSIONS);
session.requestNewReadPermissions(newPermissionsRequest);
return;
}
else if(isDataFetch)
{
mInterface.onLogin(session);
}
else
{
mInterface.onLoginForShareData();
}
}
}
};
/**
* method for fetching the user data
* #param session : it takes the refrence of active session
*/
public void getDataFromFB(Session session)
{
Request.executeMeRequestAsync(session, new Request.GraphUserCallback()
{
// callback after Graph API response with user object
#Override
public void onCompleted(GraphUser user, Response response)
{
if (user != null)
{
// code to retrieve user's data and pass to signup fragment
FBBean fbUserDataBean = new FBBean();
if (mAccessTokenString != null)
fbUserDataBean.setAccessToken(mAccessTokenString);
else
{
fbUserDataBean.setAccessToken("");
}
if (user.getUsername() != null && !(user.getUsername().equals(null)))
fbUserDataBean.setUserName(user.getUsername());
else
{
fbUserDataBean.setUserName("");
}
if (user.getFirstName() != null && !(user.getFirstName().equals(null)))
fbUserDataBean.setFirstNAme(user.getFirstName());
else
{
fbUserDataBean.setFirstNAme("");
}
if (user.getLastName() != null && !(user.getLastName().equals(null)))
fbUserDataBean.setLastName(user.getLastName());
else
{
fbUserDataBean.setLastName("");
}
if (user.getBirthday() != null && !(user.getBirthday().equals(null)))
fbUserDataBean.setUserBday(user.getBirthday());
else
{
fbUserDataBean.setUserBday("");
}
if (user.asMap().get("gender") != null)
{
fbUserDataBean.setUserSex(user.asMap().get("gender").toString());
}
else
{
fbUserDataBean.setUserSex("");
}
if (user.getProperty("email") != null && !(user.getProperty("email").equals(null)))
fbUserDataBean.setMailId(user.getProperty("email").toString());
else
{
fbUserDataBean.setMailId("");
}
if (user.getId() != null && !(user.getId().equals(null)))
fbUserDataBean.setUserID(user.getId());
else
{
fbUserDataBean.setUserID("");
}
// String[] sportsArray = FacebookUtils.getSportsArray(user.getInnerJSONObject());
// if (sportsArray != null && !(sportsArray.equals(null)))
// fbUserDataBean.setSportsname(sportsArray);
mInterface.onUserData(fbUserDataBean);
}
}
});
}
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset)
{
for (String string : subset)
{
if (!superset.contains(string))
{
return false;
}
}
return true;
}
/**
* method for publishing posts
*/
public void publishFeedDialog(Bundle postParams)
{
Session s = Session.getActiveSession();
List<String> permissions = s.getPermissions();
if (!isSubsetOf(WRITE_PERMISSIONS, permissions))
{
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(activity,
WRITE_PERMISSIONS);
s.requestNewPublishPermissions(newPermissionsRequest);
return;
}
// Bundle postParams = new Bundle();
// postParams.putString("name", "Facebook SDK for Android");
// postParams.putString("caption", "Build great social apps and get more installs.");
// postParams.putString("description", "Video by Lata manadjahgkfdjhaskjd akhgfkjashfkjash");
// postParams.putString("link", "");
// postParams.putString("picture", "");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(activity, Session.getActiveSession(), postParams))
.setOnCompleteListener(new OnCompleteListener()
{
#Override
public void onComplete(Bundle values, FacebookException error)
{
if (error == null)
{
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null)
{
mInterface.onPost(true);
}
else
{
// User clicked the Cancel button
mInterface.onPost(false);
}
}
else
if (error instanceof FacebookOperationCanceledException)
{
// User clicked the "x" button
// Toast.makeText(MainActivity.this.getApplicationContext(), "Publish cancelled",
// Toast.LENGTH_SHORT).show();
mInterface.onPost(false);
}
else
{
// Generic, ex: network error
// Toast.makeText(MainActivity.this.getApplicationContext(), "Error posting story",
// Toast.LENGTH_SHORT).show();
mInterface.onAuthFailiure();
}
}
}).build();
feedDialog.show();
}
}