guys i am want to post on facebook, for that using facebook sdk, but some line of code not executed. is pops-up a dialog for login, when i do login, then SessionEvents.AuthListener listener should listen for login success. but its not listening. and every time when i start app it ask for login.
below is my code.
public class FacebookConnector {
private Facebook mFacebook;
private AuthListener mSessionListener;
private Context context;
private String[] permissions;
private Activity activity;
public FacebookConnector(String appId, Activity activity, Context context, String[] permissions) {
this.mFacebook = new Facebook(appId);
SessionStore.restore(mFacebook, context);
SessionEvents.addAuthListener(mSessionListener);
SessionEvents.addLogoutListener((LogoutListener) mSessionListener);
this.context = context;
this.permissions = permissions;
this.activity = activity;
}
public void postMessageOnWall(String msg) {
if (mFacebook.isSessionValid()) {
Bundle parameters = new Bundle();
parameters.putString("message", msg);
try {
String response = mFacebook.request("me/feed", parameters, "POST");
System.out.println(response);
} catch (IOException e) {
e.printStackTrace();
}
} else {
login();
}
}
public void login() {
if (!mFacebook.isSessionValid()) {
mFacebook.authorize(this.activity, this.permissions, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
}
}
public Facebook getFacebook() {
return mFacebook;
}
}
and in my activity Class....
private void onFacebookBtnClicked() {
if (facebookConnector.getFacebook().isSessionValid()) {
postMessageInThread();
} else {
SessionEvents.AuthListener listener = new SessionEvents.AuthListener() {
#Override
public void onAuthSucceed() {
postMessageInThread();
}
#Override
public void onAuthFail(String error) {
}
};
SessionEvents.addAuthListener(listener);
facebookConnector.login();
}
}
private void postMessageInThread() {
Thread t = new Thread() {
public void run() {
try {
facebookConnector.postMessageOnWall(mQuote.getQuoteText() + "\n" + mQuote.getAuthorName());
mFacebookHandler.post(mUpdateFacebookNotification);
} catch (Exception ex) {
Log.e("Facebook", "Error sending msg", ex);
}
}
};
t.start();
}
final Runnable mUpdateFacebookNotification = new Runnable() {
public void run() {
Toast.makeText(getBaseContext(), "Facebook updated !", Toast.LENGTH_LONG).show();
}
};
in that postMessageInThread method not executing, don't know why
set this permission as public
private String[] PERMISSIONS = new String[]
{ "publish_stream", "read_stream", "offline_access" };
This will check is session exist if yes then it will direct update if not then ask user permission to update on wall.
Hi friends i got the solution, for my problem, so now posting the answer. i just had to overrideonActivityResult
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mFacebook.authorizeCallback(requestCode, resultCode, data);
}
i just added it and got my app working correctly.
Related
I hope anybody can help me ! I want to change my code for the new facebook sdk 4.0 but there is only a little description and i´m getting crazy and don´t know how to make the new code with facebook login button and accesstoken
target of this code is that the user logs in with his facebook account and checks if the user already exits. if not then insert new user with email and facebook id and name
I have marked the codes with //needs to be changed and //needs to be changed END
Thanx in advance for any help !!!
import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
// import com.facebook.Request;
//import com.facebook.Request.GraphUserCallback;
// import com.facebook.Response;
// import com.facebook.Session;
// import com.facebook.SessionState;
//import com.facebook.UiLifecycleHelper;
// import com.facebook.model.GraphUser;
// import com.facebook.widget.LoginButton;
#SuppressLint("NewApi")
public class AuthenticationFragment extends Fragment {
LoginButton facebookLoginButton;
// private UiLifecycleHelper uiHelper;
String TAG = "Fragment";
Button btnLogin, btnCreateAccount;
ProgressDialog dialogPrg;
String userName = null;
// New Facebook Added
CallbackManager callbackManager;
public static final AuthenticationFragment newInstance() {
// TODO Auto-generated constructor stub
AuthenticationFragment fragment = new AuthenticationFragment();
return fragment;
}
#Override
public void onAttach(Activity activity) {
// TODO Auto-generated method stub
super.onAttach(activity);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.authentication_layout, container,
false);
facebookLoginButton = (LoginButton) view
.findViewById(R.id.btnFacebookLogin);
facebookLoginButton.setFragment(this);
facebookLoginButton.setReadPermissions(Arrays.asList("email"));
// New added for Facebook
// Callback registration
facebookLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
// App code
//login ok get access token
AccessToken.getCurrentAccessToken();
}
#Override
public void onCancel() {
// App code
Log.i(TAG, "facebook login canceled");
}
#Override
public void onError(FacebookException exception) {
// App code
Log.i(TAG, "facebook login failed error");
}
});
//New added for Facebook END
btnLogin = (Button) view.findViewById(R.id.btn_login);
btnCreateAccount = (Button) view.findViewById(R.id.btn_create_account);
btnLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), LoginActivity.class);
startActivity(intent);
}
});
btnCreateAccount.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(getActivity(),
CreateAccountActivity.class);
startActivity(intent);
}
});
dialogPrg = new ProgressDialog(getActivity());
dialogPrg.setCanceledOnTouchOutside(false);
return view;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// uiHelper = new UiLifecycleHelper(getActivity(), callback);
// uiHelper.onCreate(savedInstanceState);
}
// Needs to be changed
private Session.StatusCallback callback = new Session.StatusCallback() {
#Override
public void call(final Session session, final SessionState state,
final Exception exception) {
onSessionStateChange(session, state, exception);
}
};
// Needs to be changed END
private void onSessionStateChange(Session session, SessionState state,
Exception exception) {
if (state.isOpened()) {
Log.i("FB AUT FRAGMENT", "Logged in...");
} else if (state.isClosed()) {
Log.i("FB AUT FRAGMENT", "Logged out...");
}
}
// Needs to be changed
private void insertUser(Session session) {
Request.newMeRequest(session, new GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
// TODO Auto-generated method stub
new facebookUserCheck(user).start();
}
}).executeAsync();
}
// Needs to be changed END
// Needs to be changed
private class facebookUserCheck extends Thread {
GraphUser user;
public facebookUserCheck(GraphUser user) {
// TODO Auto-generated constructor stub
this.user = user;
}
// Needs to be changed
#Override
public void run() {
// TODO Auto-generated method stub
super.run();
// TODO Auto-generated method stub
String handleInsertUser = getActivity().getResources().getString(
R.string.users_json_url)
+ "facebook_user_check";
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(handleInsertUser);
MultipartEntity reqEntity = new MultipartEntity();
// Needs to be changed user.getId
reqEntity.addPart("fb_id", new StringBody(user.getId()));
// Needs to be changed END
post.setEntity(reqEntity);
HttpResponse res = client.execute(post);
HttpEntity resEntity = res.getEntity();
final String response_str = EntityUtils.toString(resEntity);
if (resEntity != null) {
Log.i(TAG, response_str);
getActivity().runOnUiThread(new Runnable() {
public void run() {
try {
dialogPrg.dismiss();
JSONArray jsonArray = new JSONArray(
response_str);
if (jsonArray.length() == 1) {
JSONObject obj = jsonArray.getJSONObject(0);
User user = Ultils.parseUser(obj);
UserSessionManager userSession = new UserSessionManager(
getActivity());
userSession.storeUserSession(user);
Intent intent = new Intent(getActivity(),
HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
| Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
} catch (Exception e) {
LayoutInflater inflater = LayoutInflater
.from(getActivity());
View promptsView = inflater.inflate(
R.layout.username_promtps_layout, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
getActivity());
// set prompts.xml to alertdialog builder
alertDialogBuilder.setView(promptsView);
final EditText message = (EditText) promptsView
.findViewById(R.id.editTextDialogUserInput);
alertDialogBuilder
.setMessage(getResources().getString(
R.string.choose_your_user_name));
// set dialog message
alertDialogBuilder
.setCancelable(false)
.setPositiveButton(
getResources().getString(
R.string.ok_label),
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int id) {
if (!Validator
.validUserName(message
.getText()
.toString())) {
showDialog(getResources()
.getString(
R.string.invalid_user_name));
return;
}
userName = message
.getText()
.toString();
new facebookUserRegister(
user).start();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder
.create();
// show it
alertDialog.show();
}
}
});
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
// Needs to be changed
private class facebookUserRegister extends Thread {
GraphUser user;
public facebookUserRegister(GraphUser user) {
// TODO Auto-generated constructor stub
this.user = user;
}
// Needs to be changed END
#Override
public void run() {
super.run();
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
dialogPrg.show();
}
});
String handleInsertUser = getActivity().getResources().getString(
R.string.users_json_url)
+ "facebook_user_register";
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(handleInsertUser);
MultipartEntity reqEntity = new MultipartEntity();
// Needs to be changed user.getId, user.getName, user.asMap
reqEntity.addPart("fb_id", new StringBody(user.getId()));
reqEntity.addPart("fullname", new StringBody(user.getName()));
reqEntity.addPart("email", new StringBody(user.asMap().get("email").toString()));
// Needs to be changed END
reqEntity.addPart("username", new StringBody(userName));
post.setEntity(reqEntity);
HttpResponse res = client.execute(post);
HttpEntity resEntity = res.getEntity();
final String response_str = EntityUtils.toString(resEntity);
if (resEntity != null) {
Log.i(TAG, response_str);
getActivity().runOnUiThread(new Runnable() {
public void run() {
try {
dialogPrg.dismiss();
JSONObject jsonObj = new JSONObject(
response_str);
if (jsonObj.getString("ok").equals("0")) {
// show error email;
showDialog(getActivity().getResources()
.getString(R.string.email_exist));
return;
}
if (jsonObj.getString("ok").equals("1")) {
// show error username
showDialog(getActivity()
.getResources()
.getString(R.string.user_name_exist));
return;
}
if (jsonObj.getString("ok").equals("2")) {
// show unknow username
showDialog(getActivity().getResources()
.getString(R.string.login_failed));
return;
}
} catch (Exception e) {
JSONArray jsonArray;
try {
jsonArray = new JSONArray(response_str);
if (jsonArray.length() == 1) {
JSONObject obj = jsonArray
.getJSONObject(0);
User user = Ultils.parseUser(obj);
UserSessionManager userSession = new UserSessionManager(
getActivity());
userSession.storeUserSession(user);
Intent intent = new Intent(
getActivity(),
HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
| Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
showDialog(getActivity().getResources()
.getString(R.string.login_failed));
}
}
}
});
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
// Needs to be changed
#Override
public void onResume() {
super.onResume();
Session session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {
onSessionStateChange(session, session.getState(), null);
}
// uiHelper.onResume();
}
// Needs to be changed END
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// New Facebook added
callbackManager.onActivityResult(requestCode, resultCode, data);
//New Facebook added END
// uiHelper.onActivityResult(requestCode, resultCode, data);
// Needs to be changed
if (Session.getActiveSession() != null
&& Session.getActiveSession().isOpened()) {
dialogPrg.setMessage(getActivity().getResources().getString(
R.string.loging));
dialogPrg.show();
facebookLoginButton.setEnabled(false);
insertUser(Session.getActiveSession());
}
}
// Needs to be changed END
#Override
public void onPause() {
super.onPause();
// uiHelper.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
// uiHelper.onDestroy();
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// uiHelper.onSaveInstanceState(outState);
}
public void showDialog(String message) {
Ultils.logout(getActivity());
AlertDialog.Builder buidler = new AlertDialog.Builder(getActivity());
buidler.setMessage(message);
buidler.setPositiveButton(
getActivity().getResources().getString(R.string.ok_label),
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method
// stub
facebookLoginButton.setEnabled(true);
}
});
AlertDialog dialog = buidler.create();
dialog.show();
}
}
Use this Snippet for facebook login. Works like a charm in my app.
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.facebook.AppEventsLogger;
import com.facebook.FacebookAuthorizationException;
import com.facebook.FacebookOperationCanceledException;
import com.facebook.FacebookRequestError;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.model.GraphObject;
import com.facebook.model.GraphPlace;
import com.facebook.model.GraphUser;
import com.facebook.widget.FacebookDialog;
import com.facebook.widget.LoginButton;
import com.facebook.widget.ProfilePictureView;
import com.ids.service.R;
import android.support.v4.app.FragmentActivity;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends FragmentActivity {
private final String PENDING_ACTION_BUNDLE_KEY = "com.facebook.samples.hellofacebook:PendingAction";
private LoginButton loginButton;
private ProfilePictureView profilePictureView;
private PendingAction pendingAction = PendingAction.NONE;
private GraphUser user;
private GraphPlace place;
private List<GraphUser> tags;
private boolean canPresentShareDialog;
private boolean canPresentShareDialogWithPhotos;
private enum PendingAction {
NONE,
POST_PHOTO,
POST_STATUS_UPDATE
}
private UiLifecycleHelper uiHelper;
private Session.StatusCallback callback = new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state,
Exception exception) {
onSessionStateChange(session, state, exception);
}
};
private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() {
#Override
public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
Log.d("Facebook", String.format("Error: %s", error.toString()));
}
#Override
public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
Log.d("Facebook", "Success!");
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
if (savedInstanceState != null) {
String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
pendingAction = PendingAction.valueOf(name);
}
setContentView(R.layout.activity_main);
profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
#Override
public void onUserInfoFetched(GraphUser user) {
MainActivity.this.user = user;
updateUI();
// It's possible that we were waiting for this.user to be populated in order to post a
// status update.
handlePendingAction();
}
});
}
#Override
protected void onResume() {
super.onResume();
uiHelper.onResume();
// Call the 'activateApp' method to log an app event for use in analytics and advertising reporting. Do so in
// the onResume methods of the primary Activities that an app may be launched into.
AppEventsLogger.activateApp(this);
updateUI();
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
outState.putString(PENDING_ACTION_BUNDLE_KEY, pendingAction.name());
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback);
}
#Override
public void onPause() {
super.onPause();
uiHelper.onPause();
// Call the 'deactivateApp' method to log an app event for use in analytics and advertising
// reporting. Do so in the onPause methods of the primary Activities that an app may be launched into.
AppEventsLogger.deactivateApp(this);
}
#Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (pendingAction != PendingAction.NONE &&
(exception instanceof FacebookOperationCanceledException ||
exception instanceof FacebookAuthorizationException)) {
new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.cancelled)
.setMessage(R.string.permission_not_granted)
.setPositiveButton(R.string.ok, null)
.show();
pendingAction = PendingAction.NONE;
} else if (state == SessionState.OPENED_TOKEN_UPDATED) {
handlePendingAction();
}
updateUI();
}
#SuppressWarnings("unused")
private void updateUI() {
Session session = Session.getActiveSession();
if (user != null) {
profilePictureView.setProfileId(user.getId());
Log.e("Name", user.getName());
}
}
#SuppressWarnings("incomplete-switch")
private void handlePendingAction() {
PendingAction previouslyPendingAction = pendingAction;
// These actions may re-set pendingAction if they are still pending, but we assume they
// will succeed.
pendingAction = PendingAction.NONE;
switch (previouslyPendingAction) {
case POST_PHOTO:
postPhoto();
break;
case POST_STATUS_UPDATE:
postStatusUpdate();
break;
}
}
private interface GraphObjectWithId extends GraphObject {
String getId();
}
private void showPublishResult(String message, GraphObject result, FacebookRequestError error) {
String title = null;
String alertMessage = null;
if (error == null) {
title = getString(R.string.success);
String id = result.cast(GraphObjectWithId.class).getId();
alertMessage = getString(R.string.successfully_posted_post, message, id);
} else {
title = getString(R.string.error);
alertMessage = error.getErrorMessage();
}
new AlertDialog.Builder(this)
.setTitle(title)
.setMessage(alertMessage)
.setPositiveButton(R.string.ok, null)
.show();
}
private FacebookDialog.ShareDialogBuilder createShareDialogBuilderForLink() {
return new FacebookDialog.ShareDialogBuilder(this)
.setName("Hello Facebook")
.setDescription("The 'Hello Facebook' sample application showcases simple Facebook integration")
.setLink("http://developers.facebook.com/android");
}
private void postStatusUpdate() {
if (canPresentShareDialog) {
FacebookDialog shareDialog = createShareDialogBuilderForLink().build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else if (user != null && hasPublishPermission()) {
final String message = getString(R.string.status_update, user.getFirstName(), (new Date().toString()));
Request request = Request
.newStatusUpdateRequest(Session.getActiveSession(), message, place, tags, new Request.Callback() {
#Override
public void onCompleted(Response response) {
showPublishResult(message, response.getGraphObject(), response.getError());
}
});
request.executeAsync();
} else {
pendingAction = PendingAction.POST_STATUS_UPDATE;
}
}
private FacebookDialog.PhotoShareDialogBuilder createShareDialogBuilderForPhoto(Bitmap... photos) {
return new FacebookDialog.PhotoShareDialogBuilder(this)
.addPhotos(Arrays.asList(photos));
}
private void postPhoto() {
Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher);
if (canPresentShareDialogWithPhotos) {
FacebookDialog shareDialog = createShareDialogBuilderForPhoto(image).build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else if (hasPublishPermission()) {
Request request = Request.newUploadPhotoRequest(Session.getActiveSession(), image, new Request.Callback() {
#Override
public void onCompleted(Response response) {
showPublishResult(getString(R.string.photo_post), response.getGraphObject(), response.getError());
}
});
request.executeAsync();
} else {
pendingAction = PendingAction.POST_PHOTO;
}
}
private boolean hasPublishPermission() {
Session session = Session.getActiveSession();
return session != null && session.getPermissions().contains("publish_actions");
}
}
As you can read in the Facebook SDK for Android changelog in section 4.0 - March 25, 2015 the UiLifecycleHelper was removed and its functionality transferred to the CallbackManager.
Here is a tutorial which explains how to implement the login with facebook SDK 4.0.
Can someone explain to me how can i integrate Chartboost post install?
Already tried this post-install integration guide with my testing app (uploaded as alpha test) and with this reserved in-app purchases:
android.test.purchased
android.test.canceled
android.test.refunded
android.test.item_unavailable
When i try to run this code:
public void ChartboostPI(View view) {
trackInAppGooglePlayPurchaseEvent("Sample Title", "Sample description for product: android.test.canceled.", "0.99", "USD", "android.test.purchased", "inapp:"+this.getPackageName()+":android.test.canceled", "j");
}
i'm getting:
iap failure responce!!
P.S.:
Maybe there is some ways to test my own inapps, but i dont know how to specify this in in-app purchase code (I will be glad if someone will explain me how).
Finally i found the answer, cb developers posted example with release of 5.0.3
Here is example code:
public class GoogleIAPTracking extends Activity{
private static final String TAG = "com.chartboost.sdk.sample.cbtest.inappbilling";
private static final int INAPP_REQUEST_CODE = 10001;
//private static final String RELEASE_ITEM_SKU = "com.example.buttonclick";
private static final String TEST_ITEM_SKU = "android.test.purchased";
private Button clickButton;
private Button buyButton;
private String ITEM_SKU;
IabHelper mHelper;
Inventory inventory;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pit);
Chartboost.onCreate(this);
Chartboost.setDelegate(delegate);
buyButton = (Button)findViewById(R.id.buyButton);
clickButton = (Button)findViewById(R.id.clickButton);
clickButton.setEnabled(false);
ITEM_SKU = TEST_ITEM_SKU;
String base64EncodedPublicKey = getResources().getString(R.string.base64EncodedPublicKey);
/*Setting up Inapp billing purchase*/
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.enableDebugLogging(true);
mHelper.startSetup(new
IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result)
{
if (!result.isSuccess()) {
Log.d(TAG, "In-app Billing setup failed: " +
result);
} else {
Log.d(TAG, "############# In-app Billing is set up ###############");
Log.d(TAG, "In-app Billing is set up OK");
}
}
});
}
public void buyClick(View view) {
mHelper.launchPurchaseFlow(this, ITEM_SKU, INAPP_REQUEST_CODE, mPurchaseFinishedListener, "mypurchasetoken");
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
#Override
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG,"###### onIabPurchaseFinished"+purchase +"#####"+ ITEM_SKU);
if (result.isFailure()) {
Runnable r = new Runnable() {
#Override
public void run() {
mHelper.myconsume(GoogleIAPTracking.this.getPackageName(), "inapp:"+getPackageName()+":android.test.purchased");
}
};
r.run();
Log.d(TAG,"###### onIabPurchaseFinished Error ");
return;
}
else if (purchase.getSku().equals(ITEM_SKU)) {
mHelper.queryInventoryAsync(mReceivedInventoryListener);
buyButton.setEnabled(false);
}
}
};
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
#Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
Log.d(TAG,"###### onQueryInventoryFinished : " + inv);
if (result.isFailure()) {
// Handle failure
}
else {
Log.d(TAG," ####### Its in the inventory consuming the item !!!!");
try{
// MIGHT THROW AN EXCEPTION IF Chartboost.onStart() is not called.
Log.d(TAG,"########## Send it to Chartboost PIT ###########");
SkuDetails item = inv.getSkuDetails(ITEM_SKU);
Purchase purchase = inv.getPurchase(ITEM_SKU);
if(item !=null && purchase != null) {
String data =purchase.getOriginalJson();
String signature = TextUtils.isEmpty(purchase.getSignature()) ?"test":purchase.getSignature();
signature = TextUtils.isEmpty(signature) ?"test":signature;
if(item != null){
CBAnalytics.trackInAppGooglePlayPurchaseEvent(item.getTitle(),
item.getDescription(),
item.getPrice(),
item.getCurrencyCode(),
purchase.getSku(),
data,
signature);
}
}
} catch(Exception e){
Log.d(TAG, e.getMessage());
}
mHelper.consumeAsync(inv.getPurchase(ITEM_SKU), mConsumeFinishedListener);
}
}
};
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase,
IabResult result) {
Log.d(TAG,"###### onConsumeFinished");
if (result.isSuccess()) {
Log.d(TAG,"###### onConsumeFinished sucess");
}
buyButton.setEnabled(true);
}
};
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
// not handled, so handle it ourselves (here's where you'd
// perform any handling of activity results not related to in-app
// billing...
super.onActivityResult(requestCode, resultCode, data);
}
else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
};
/* The following methods reflect the buttons in our UI. */
public void onLoadButtonClick(View view) {
String toastStr = "Loading Interstitial";
Toast.makeText(this, toastStr, Toast.LENGTH_SHORT).show();
Chartboost.showInterstitial(CBLocation.LOCATION_STARTUP);
}
public void onMoreButtonClick(View view) {
String toastStr = "Loading More Apps";
Toast.makeText(this, toastStr, Toast.LENGTH_SHORT).show();
Chartboost.showMoreApps(CBLocation.LOCATION_GAME_SCREEN);
}
public void trackMiscRevenueGeneratingEventOfType(View view) {
String toastStr = "Sending trackMiscRevenueGeneratingEventOfType to SDK ..";
Toast.makeText(this, toastStr, Toast.LENGTH_SHORT).show();
//pit.trackMiscRevenueGeneratingEvent(CBMiscRevenueGeneratingEventType.CBMiscRevenueGeneratingEventType1, 100, "USD", "HayDay");
}
public void trackCustomEventOfType(View view) {
String toastStr = "Sending trackCustomEventOfType to SDK ..";
Toast.makeText(this, toastStr, Toast.LENGTH_SHORT).show();
//pit.trackCustomEventofType(CBCustomEventType.CBCustomEventType1, 2);
}
public void trackInGameScore(View view) {
String toastStr = "Sending trackInGameScore to SDK ..";
Toast.makeText(this, toastStr, Toast.LENGTH_SHORT).show();
//pit.trackInGameScore(10);
}
public void trackPlayerCurrencyBalance(View view) {
String toastStr = "Sending trackPlayerCurrencyBalance to SDK ..";
Toast.makeText(this, toastStr, Toast.LENGTH_SHORT).show();
//pit.trackPlayerCurrencyBalance(5, "USD");
}
/*Activity callback methods*/
#Override
protected void onStart() {
super.onStart();
Chartboost.onStart(this);
}
#Override
protected void onResume() {
super.onResume();
Log.d(TAG,"### onResume");
}
#Override
protected void onPause() {
super.onPause();
}
#Override
protected void onStop() {
super.onStop();
Chartboost.onStop(this);
}
#Override
public void onBackPressed() {
if (Chartboost.onBackPressed())
return;
else
super.onBackPressed();
}
#Override
public void onDestroy() {
super.onDestroy();
Chartboost.onDestroy(this);
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
/**
* Chartboost Delegate callbacks
*/
private ChartboostDelegate delegate = new ChartboostDelegate() {
};
}
I make an application in which I make an EditText and a button. I want to be post that message which is written on EditText on the Facebook friends wall after clicked on the button. Please give me some idea how we can perform this task using Facebook sdk.
The code is below:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.post_wall);
share = (Button) findViewById(R.id.share);
friend_name = (TextView) findViewById(R.id.wall_to);
wall = (EditText) findViewById(R.id.wall);
savedInstanceState = new Bundle();
savedInstanceState.getString("to");
onComplete(savedInstanceState);
}
#Override public void onComplete(Bundle values)
{
Utility.currentPermissions.clear();
if (values.isEmpty())
{
//"skip" clicked ?
return;
}
// if facebookClient.authorize(...) was successful, this runs
// this also runs after successful post
// after posting, "to"(which is the id of friend) is added to the values bundle
// I use that to differentiate between a call from
// faceBook.authorize(...) and a call from a successful post
// is there a better way of doing this?
if (!values.containsKey("to"))
{
try
{
Log.d("Wall try", "Click successfully");
for (String key : parameters.keySet()) {
if (parameters.getByteArray(key) != null) {
parameters.putByteArray(key, parameters.getByteArray(key));
Log.d("key", parameters.getByteArray(key).toString());
}
}
mHandler.post(new Runnable() {
#Override
public void run() {
performActivityInfo();
}
});
}
catch (Exception e)
{
// TODO: handle exception
System.out.println(e.getMessage());
}
}
}
protected void performActivityInfo() {
Log.d("perform wall", "Perform Activity");
mHandler.sendEmptyMessage(FRIEND_WALL);
parameters.putString("message", wall.getText().toString());
facebookClient.dialog(this, "stream.publish", parameters, this);// "stream.publish" is an API call
Log.d("Wall post", "Click successfully");
}
public Handler mHandler = new Handler() {
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
case FRIEND_WALL:
Log.d("Handler WALL", "Handler");
postOnWall(wall.getText().toString());
break;
}
super.handleMessage(msg);
}
};
#Override
public void onError(DialogError e)
{
System.out.println("Error: " + e.getMessage());
}
#Override
public void onFacebookError(FacebookError e)
{
System.out.println("Error: " + e.getMessage());
}
#Override
public void onCancel()
{
}
#Override
public void onClick(View v)
{
facebookClient = new Facebook(APP_ID);
// replace APP_API_ID with your own
Log.d("Wall click", "Click successfully");
facebookClient.authorize(this,
new String[] {"publish_stream", "read_stream", "offline_access"}, this);
}
public void postOnWall(String msg) {
Log.d("Tests", "Testing graph API wall post");
try {
String response = facebookClient.request("me");
Bundle parameters = new Bundle();
parameters.putString("message", msg);
parameters.putString("description", "test test test");
response = facebookClient.request("me/feed", parameters,
"POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} catch(Exception e) {
e.printStackTrace();
}
}
Thanks in Advance.
For getting the value from Edit Text just use :
EditText edittext;
edittext.getEditableText().toString();
Inside Button click Listener use this code then
button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
String entered_value=edittext.getEditableText().toString();
try{
parameters.putString("message", entered_value);
parameters.putString("target_id", "XXXXX"); // target Id in which you need to Post
parameters.putString("method", "stream.publish");
String response = authenticatedFacebook.request(parameters);
Log.v("response", response);
}
catch(Exception e){}
}
});
where button is your button Object.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have to send a link on user's facebook wall. I am trying but not getting success.
I wrote the code but its not working. First i write:
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class FacebookActivity extends Activity {
/** Called when the activity is first created. */
Facebook face;
AsyncFacebookRunner run;
String[] permission=new String[] {"publish_stream",
"read_stream", "offline_access"};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
face=new Facebook("my key");
run=new AsyncFacebookRunner(face);
face.authorize(this, permission,new MyLoginDialogListener());
}
private final class MyLoginDialogListener implements com.facebook.android
.Facebook.DialogListener {
public void onComplete(Bundle values) {
Toast.makeText(FacebookActivity.this, "Ho Gya Authorize",Toast.LENGTH_LONG).show();
run=new AsyncFacebookRunner(face);
Bundle bundle=new Bundle();
bundle.putString("message", " hello");
bundle.putString("name", "hello");
bundle.putString("description", "Hello");
bundle.putString("link", "http://www.facebook.com");
try {
face.request("me/feed",bundle, "POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} // here enable logout
public void onFacebookError(FacebookError error) {}
public void onError(DialogError error) {}
public void onCancel() {}
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
face.authorizeCallback(requestCode, resultCode, data);
}
}
Please suggest how to proceed further. My code is not posting on the wall of user's wall.
Sample code for posting wall on facebook
public class AndroidFacebookSample extends Activity {
private static final String FACEBOOK_APPID = "PUT YOUR FACEBOOK APP ID HERE";
private static final String FACEBOOK_PERMISSION = "publish_stream";
private static final String TAG = "FacebookSample";
private static final String MSG = "Message from FacebookSample";
private final Handler mFacebookHandler = new Handler();
private TextView loginStatus;
private FacebookConnector facebookConnector;
final Runnable mUpdateFacebookNotification = new Runnable() {
public void run() {
Toast.makeText(getBaseContext(), "Facebook updated !", Toast.LENGTH_LONG).show();
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.facebookConnector = new FacebookConnector(FACEBOOK_APPID, this, getApplicationContext(), new String[] {FACEBOOK_PERMISSION});
loginStatus = (TextView)findViewById(R.id.login_status);
Button tweet = (Button) findViewById(R.id.btn_post);
Button clearCredentials = (Button) findViewById(R.id.btn_clear_credentials);
tweet.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
postMessage();
}
});
clearCredentials.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
clearCredentials();
updateLoginStatus();
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
this.facebookConnector.getFacebook().authorizeCallback(requestCode, resultCode, data);
}
#Override
protected void onResume() {
super.onResume();
updateLoginStatus();
}
public void updateLoginStatus() {
loginStatus.setText("Logged into Twitter : " + facebookConnector.getFacebook().isSessionValid());
}
private String getFacebookMsg() {
return MSG + " at " + new Date().toLocaleString();
}
public void postMessage() {
if (facebookConnector.getFacebook().isSessionValid()) {
postMessageInThread();
} else {
SessionEvents.AuthListener listener = new SessionEvents.AuthListener() {
#Override
public void onAuthSucceed() {
postMessageInThread();
}
#Override
public void onAuthFail(String error) {
}
};
SessionEvents.addAuthListener(listener);
facebookConnector.login();
}
}
private void postMessageInThread() {
Thread t = new Thread() {
public void run() {
try {
facebookConnector.postMessageOnWall(getFacebookMsg());
mFacebookHandler.post(mUpdateFacebookNotification);
} catch (Exception ex) {
Log.e(TAG, "Error sending msg",ex);
}
}
};
t.start();
}
private void clearCredentials() {
try {
facebookConnector.getFacebook().logout(getApplicationContext());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
I just used a code for camera application in android. In this application, the photo that clicked is saved in to SD Card.My code for saving as shown bellow $
Camera.PictureCallback jpegCallback = new PictureCallback()
{
public void onPictureTaken(byte[] data, Camera camera)
{
FileOutputStream outStream = null;
try
{
outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis()));
outStream.write(data);
outStream.close();
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
Log.d(TAG, "on pictureTaken" + data.length);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{}
Log.d(TAG, "on pictureTaken-jpeg");
}
};
I just upload that image from sd card to facebook by using another activity by using FacebookSDK as shown bellow.
public class Upload extends Activity implements OnItemClickListener
{
/* Your Facebook Application ID must be set before running this example
* See http://www.facebook.com/developers/createapp.php
*/
public static final String APP_ID = "146770088755283";
private LoginButton mLoginButton;
private TextView mText;
private ImageView mUserPic;
private Handler mHandler;
ProgressDialog dialog;
final int AUTHORIZE_ACTIVITY_RESULT_CODE = 0;
final int PICK_EXISTING_PHOTO_RESULT_CODE = 1;
private ListView list;
String[] main_items = {"Upload Photo"};
String[] permissions = {"offline_access", "publish_stream", "user_photos", "publish_checkins", "photo_upload"};
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (APP_ID == null)
{
Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " +
"specified before running this example: see FbAPIs.java");
return;
}
setContentView(R.layout.main);
mHandler = new Handler();
mText = (TextView) Upload.this.findViewById(R.id.txt);
mUserPic = (ImageView)Upload.this.findViewById(R.id.user_pic);
//Create the Facebook Object using the app id.
Utility.mFacebook = new Facebook(APP_ID);
//Instantiate the asynrunner object for asynchronous api calls.
Utility.mAsyncRunner = new AsyncFacebookRunner(Utility.mFacebook);
mLoginButton = (LoginButton) findViewById(R.id.login);
//restore session if one exists
SessionStore.restore(Utility.mFacebook, this);
SessionEvents.addAuthListener(new FbAPIsAuthListener());
SessionEvents.addLogoutListener(new FbAPIsLogoutListener());
/*
* Source Tag: login_tag
*/
mLoginButton.init(this, AUTHORIZE_ACTIVITY_RESULT_CODE, Utility.mFacebook, permissions);
if(Utility.mFacebook.isSessionValid())
{
requestUserData();
}
list = (ListView)findViewById(R.id.main_list);
list.setOnItemClickListener(this);
list.setAdapter(new ArrayAdapter<String>(this, R.layout.main_list_item, main_items));
}
#Override
public void onResume()
{
super.onResume();
if(Utility.mFacebook != null && !Utility.mFacebook.isSessionValid())
{
mText.setText("You are logged out! ");
mUserPic.setImageBitmap(null);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode)
{
/*
* if this is the activity result from authorization flow, do a call back to authorizeCallback
* Source Tag: login_tag
*/
case AUTHORIZE_ACTIVITY_RESULT_CODE:
{
Utility.mFacebook.authorizeCallback(requestCode, resultCode, data);
break;
}
/*
* if this is the result for a photo picker from the gallery, upload the image after scaling it.
* You can use the Utility.scaleImage() function for scaling
*/
case PICK_EXISTING_PHOTO_RESULT_CODE:
{
if (resultCode == Activity.RESULT_OK)
{
Uri photoUri = data.getData();
if(photoUri != null) {
Bundle params = new Bundle();
try
{
params.putByteArray("photo", Utility.scaleImage(getApplicationContext(), photoUri));
} catch (IOException e)
{
e.printStackTrace();
}
params.putString("caption", "FbAPIs Sample App photo upload");
Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null);
}
else
{
Toast.makeText(getApplicationContext(), "Error selecting image from the gallery.", Toast.LENGTH_SHORT).show();
}
}
else
{
Toast.makeText(getApplicationContext(), "No image selected for upload.", Toast.LENGTH_SHORT).show();
}
break;
}
}
}
public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3)
{
switch(position)
{
/*
* Source Tag: upload_photo
* You can upload a photo from the media gallery or from a remote server
* How to upload photo: https://developers.facebook.com/blog/post/498/
*/
case 0:
{
if(!Utility.mFacebook.isSessionValid())
{
Util.showAlert(this, "Warning", "You must first log in.");
}
else
{
dialog = ProgressDialog.show(Upload.this, "", getString(R.string.please_wait), true, true);
new AlertDialog.Builder(this)
.setTitle(R.string.gallery_title)
.setMessage(R.string.gallery_msg)
.setPositiveButton(R.string.gallery_button, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
Intent intent = new Intent(Intent.ACTION_PICK, (MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
startActivityForResult(intent, PICK_EXISTING_PHOTO_RESULT_CODE);
}
})
.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface d) {
dialog.dismiss();
}
})
.show();
}
break;
}
}
}
/*
* callback for the feed dialog which updates the profile status
*/
public class UpdateStatusListener extends BaseDialogListener {
public void onComplete(Bundle values) {
final String postId = values.getString("post_id");
if (postId != null) {
new UpdateStatusResultDialog(Upload.this, "Update Status executed", values).show();
} else {
Toast toast = Toast.makeText(getApplicationContext(), "No wall post made", Toast.LENGTH_SHORT);
toast.show();
}
}
public void onFacebookError(FacebookError error) {
Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(), Toast.LENGTH_SHORT).show();
}
public void onCancel() {
Toast toast = Toast.makeText(getApplicationContext(), "Update status cancelled", Toast.LENGTH_SHORT);
toast.show();
}
}
/*
* callback for the apprequests dialog which sends an app request to user's friends.
*/
public class AppRequestsListener extends BaseDialogListener {
public void onComplete(Bundle values) {
Toast toast = Toast.makeText(getApplicationContext(), "App request sent", Toast.LENGTH_SHORT);
toast.show();
}
public void onFacebookError(FacebookError error) {
Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(), Toast.LENGTH_SHORT).show();
}
public void onCancel() {
Toast toast = Toast.makeText(getApplicationContext(), "App request cancelled", Toast.LENGTH_SHORT);
toast.show();
}
}
/*
* callback for the photo upload
*/
public class PhotoUploadListener extends BaseRequestListener {
public void onComplete(final String response, final Object state) {
dialog.dismiss();
mHandler.post(new Runnable() {
public void run() {
new UploadPhotoResultDialog(Upload.this, "Upload Photo executed", response).show();
}
});
}
public void onFacebookError(FacebookError error) {
dialog.dismiss();
Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(), Toast.LENGTH_LONG).show();
}
}
public class FQLRequestListener extends BaseRequestListener {
public void onComplete(final String response, final Object state) {
mHandler.post(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "Response: " + response, Toast.LENGTH_LONG).show();
}
});
}
public void onFacebookError(FacebookError error) {
Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(), Toast.LENGTH_LONG).show();
}
}
/*
* Callback for fetching current user's name, picture, uid.
*/
public class UserRequestListener extends BaseRequestListener {
public void onComplete(final String response, final Object state) {
JSONObject jsonObject;
try {
jsonObject = new JSONObject(response);
final String picURL = jsonObject.getString("picture");
final String name = jsonObject.getString("name");
Utility.userUID = jsonObject.getString("id");
mHandler.post(new Runnable() {
public void run() {
mText.setText("Welcome " + name + "!");
mUserPic.setImageBitmap(Utility.getBitmap(picURL));
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
}
/*
* The Callback for notifying the application when authorization
* succeeds or fails.
*/
public class FbAPIsAuthListener implements AuthListener {
public void onAuthSucceed() {
requestUserData();
}
public void onAuthFail(String error) {
mText.setText("Login Failed: " + error);
}
}
/*
* The Callback for notifying the application when log out
* starts and finishes.
*/
public class FbAPIsLogoutListener implements LogoutListener {
public void onLogoutBegin() {
mText.setText("Logging out...");
}
public void onLogoutFinish() {
mText.setText("You have logged out! ");
mUserPic.setImageBitmap(null);
}
}
/*
* Request user name, and picture to show on the main screen.
*/
public void requestUserData() {
mText.setText("Fetching user name, profile pic...");
Bundle params = new Bundle();
params.putString("fields", "name, picture");
Utility.mAsyncRunner.request("me", params, new UserRequestListener());
}
/**
* Definition of the list adapter
*/
public class MainListAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public MainListAdapter() {
mInflater = LayoutInflater.from(Upload.this.getBaseContext());
}
public int getCount() {
return main_items.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
View hView = convertView;
if(convertView == null) {
hView = mInflater.inflate(R.layout.main_list_item, null);
ViewHolder holder = new ViewHolder();
holder.main_list_item = (TextView) hView.findViewById(R.id.main_api_item);
hView.setTag(holder);
}
ViewHolder holder = (ViewHolder) hView.getTag();
holder.main_list_item.setText(main_items[position]);
return hView;
}
}
class ViewHolder {
TextView main_list_item;
}
}
I want to upload that photo to facebook without save to SD Card and from the same activity that photo clicked. If anyone knows about it, please help me....
It is not possible in your case. The reason looks to be you are using native camera to capture a snap.So by default your snap will be saved to sdcard in the default location. There is no way you can stop it. But still you can delete the image after it is captured using the data returned from the Activity Result.