I have implemented admob interstitial in my android app. But I want to disable ads if users are ready to pay. i.e InAppPurchase. I have written below code for IAP and have also published apk in beta testing with product. But still it is showing that "No product found", when I am pressing "remove ads" button.
Anybody can help me to write a true code or check out that below code is right or wrong for IAP?
public static final String PRO_SKU = "removeads";
private final String BASE_64_PUBLIC_KEY = "KEY";
private Inventory mInventory;
IabHelper mHelper;
public static boolean isPro;
private InterstitialAd interstitial;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);}
interstitial = new InterstitialAd(getActivity(),
"AD UNIT");
AdRequest adRequest = new AdRequest();
interstitial.loadAd(adRequest);
mHelper = new IabHelper(getActivity().getApplicationContext(),
BASE_64_PUBLIC_KEY);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener()
{
#Override
public void onIabSetupFinished(IabResult result)
{
if (result.isSuccess())
{
loadInventory();
Log.d("IAP", "IAP Setup Succesful yeah!");
} else
{
Log.d("IAP", "IAP Setup Failed");
}
}
});
;
//AD CODE
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_quality, container,
false);
ImageView purchaseAds = (ImageView) rootView.findViewById(R.id.promo);
purchaseAds.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
purchasePro(PRO_SKU);
}
});
private void loadInventory() {
mHelper.queryInventoryAsync(true,
new IabHelper.QueryInventoryFinishedListener() {
#Override
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isSuccess()) {
mInventory = inventory;
Log.d("IAP inventory loader", "inventory loaded");
if (inventory.hasPurchase(PRO_SKU)) {
isPro = true;
Log.d("IAP inventory checker", "purchased");
} else {
Log.d("IAP inventory checker", "not purchased");
isPro = false;
}
} else {
Log.d("IAP inventory loader","inventory not loaded");
}
}
});
}
private void purchasePro(String sku) {
mHelper.launchPurchaseFlow(getActivity(), sku, 1000,
new IabHelper.OnIabPurchaseFinishedListener() {
#Override
public void onIabPurchaseFinished(IabResult result,
Purchase info) {
if (result.isSuccess()) {
isPro = true;
Log.d("IAP purchase person", "purchased!");
} else {
Toast.makeText(
getActivity().getApplicationContext(),
"Error in your purchase",
Toast.LENGTH_SHORT).show();
Log.d("IAP purchase person", "not purchased!");
}
}
}, null);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!mHelper.handleActivityResult(1000, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
Related
I use this code for in-app billing in my project, this code works well but I can not check which item is purchased.
This is my code:
public class MainActivity extends AppCompatActivity implements PurchasesUpdatedListener {
private BillingClient mBillingClient;
#BindView(R.id.btn_three_buy_health)
Button btn_three_buy_health;
#BindView(R.id.btn_ten_buy_health)
Button btn_ten_buy_health;
#BindView(R.id.btn_twenty_buy_health)
Button btn_twenty_buy_health;
#BindView(R.id.btn_fifty_buy_health)
Button btn_fifty_buy_health;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
mBillingClient = BillingClient.newBuilder(this).setListener(this).build();
mBillingClient.startConnection(new BillingClientStateListener() {
#Override
public void onBillingSetupFinished(#BillingClient.BillingResponse int billingResponseCode) {
if (billingResponseCode == BillingClient.BillingResponse.OK) {
enableOrDisableButtons(true);
} else {
enableOrDisableButtons(false);
}
}
#Override
public void onBillingServiceDisconnected() {
enableOrDisableButtons(false);
}
});
}
private void enableOrDisableButtons(boolean isEnabled) {
btn_three_buy_health.setEnabled(isEnabled);
btn_ten_buy_health.setEnabled(isEnabled);
btn_twenty_buy_health.setEnabled(isEnabled);
btn_fifty_buy_health.setEnabled(isEnabled);
}
#Optional
#OnClick(R.id.btn_three_buy_health)
void buyThreeHealth(View view) {
buyProduct("5_buy_health");
}
#Optional
#OnClick(R.id.btn_ten_buy_health)
void buyTenHealth(View view) {
buyProduct("10_buy_health");
}
#Optional
#OnClick(R.id.btn_twenty_buy_health)
void buyTwentyHealth(View view) {
buyProduct("20_buy_health");
}
#Optional
#OnClick(R.id.btn_fifty_buy_health)
void buyFiftyHealth(View view) {
buySubscription("50_buy_health");
}
private void buyProduct(String skuId) {
BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSku(skuId)
.setType(BillingClient.SkuType.INAPP)
.build();
mBillingClient.launchBillingFlow(this, flowParams);
}
private void buySubscription(String skuId) {
BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSku(skuId)
.setType(BillingClient.SkuType.SUBS)
.build();
mBillingClient.launchBillingFlow(this, flowParams);
}
#Override
public void onPurchasesUpdated(int responseCode, #Nullable List<Purchase> purchases) {
if (responseCode == BillingClient.BillingResponse.OK
&& purchases != null) {
for (final Purchase purchase : purchases) {
mBillingClient.consumeAsync(purchase.getPurchaseToken(), new ConsumeResponseListener() {
#Override
public void onConsumeResponse(int responseCode, String purchaseToken) {
if (responseCode == BillingClient.BillingResponse.OK) {
Toast.makeText(MainActivity.this, "You bought health", Toast.LENGTH_SHORT).show();
}
}
});
}
} else if (responseCode == BillingClient.BillingResponse.USER_CANCELED) {
billingCanceled();
} else {
billingCanceled();
}
}
private void billingCanceled() {
}
}
how Can I check whick item is purchased.
this toast appears in all purchases
Toast.makeText(MainActivity.this, "You bought health", Toast.LENGTH_SHORT).show();
but I want it to be like this
if a person buy 10 health toast should be like this
Toast.makeText(MainActivity.this, "You bought 10 health", Toast.LENGTH_SHORT).show();
if a person buy 20 health toast should be like this
Toast.makeText(MainActivity.this, "You bought 20 health", Toast.LENGTH_SHORT).show();
Also How to check if a user has a subscription when app start?
if the user has a subscription, the toast should appear in the beginning "You are gold member"
Sorry for my bad English.
Thanks.
I would like to use Facebook login in my App. I have just registred app and added SDK to project. However, I tried to follow the tutorial from documentation but nothing worked (I need to get ID and email from profile and send to to my server).
Fragment
public class LoginFragment extends Fragment {
#BindView(R.id.ivLogo) ImageView ivLogo;
#BindView(R.id.email) EditText edEmail;
#BindView(R.id.password) EditText edPassword;
#BindView(R.id.btnFbLogin) LoginButton btnFbLogin;
private CallbackManager callbackManager;
private AccessTokenTracker accessTokenTracker;
private ProfileTracker profileTracker;
String email, password, ID;
User user;
public LoginFragment() {
// Required empty public constructor
}
public static LoginFragment newInstance() {
LoginFragment fragment = new LoginFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
// App code
Log.i("success", "success");
}
#Override
public void onCancel() {
// App code
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_login_screen, container, false);
ButterKnife.bind(this, view);
btnFbLogin.setReadPermissions("email");
btnFbLogin.setFragment(this);
// Callback registration
btnFbLogin.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
// App code
}
#Override
public void onCancel() {
// App code
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
return view;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
#Override
public void onResume() {
super.onResume();
((MainActivity) getActivity()).getSupportActionBar().hide();
}
private void FBcallback() {
FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
try {
String email = object.getString("email");
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
#Override
public void onCancel() { }
#Override
public void onError(FacebookException e) { }
};
btnFbLogin.setReadPermissions("email");
btnFbLogin.registerCallback(callbackManager, callback);
}
private void loginEmail() {
FactoryAPI.getInstanceLogin().login("hardcoded mail", "hardcoded password").enqueue(new Callback<UserResponse>() {
#Override
public void onResponse(Call<UserResponse> call, Response<UserResponse> response) {
if (response.isSuccessful()) {
user = response.body().getUser();
startActivity();
} else {
Toast.makeText(getContext(), R.string.email_password_is_not_right, Toast.LENGTH_LONG).show();
}
}
#Override
public void onFailure(Call<UserResponse> call, Throwable t) {
}
});
}
private void loginFB() {
FactoryAPI.getServieFBlogin().loginFB(email, ID).enqueue(new Callback<UserResponse>() {
#Override
public void onResponse(Call<UserResponse> call, Response<UserResponse> response) {
if (response.isSuccessful()) {
user = response.body().getUser();
startActivity();
} else {
Toast.makeText(getContext(), "Something went wrong", Toast.LENGTH_LONG).show();
}
}
#Override
public void onFailure(Call<UserResponse> call, Throwable t) {
Log.e("error", "error");
}
});
}
public void getEmailPassword() {
email = edEmail.getText().toString();
password = edPassword.getText().toString();
if (email.isEmpty() || password.isEmpty()) {
Toast.makeText(getContext(), R.string.empty_properties, Toast.LENGTH_SHORT).show();
}
}
public static boolean emailValidation(CharSequence target) {
return !TextUtils.isEmpty(target) && Patterns.EMAIL_ADDRESS.matcher(target).matches();
}
public void startActivity() {
Intent intent = new Intent(getContext(), AccountActivity.class);
intent.putExtra("account", user);
startActivity(intent);
}
#Override
public void onActivityResult(int requestCode, int responseCode, Intent intent) {
super.onActivityResult(requestCode, responseCode, intent);
callbackManager.onActivityResult(requestCode, responseCode, intent);
}
#OnClick({R.id.sign_up_email, R.id.btnFbLogin})
public void onClick(View view) {
switch (view.getId()) {
case R.id.sign_up_email:
loginEmail();
case R.id.btnFbLogin:
break;
}
}
private void getProfile(Profile profile){
if(profile != null){
ID = profile.getId();
}
}
}
As your facebook login is in Fragment not in activity, so the
callback comes in onActivityResult() of Activity in which this fragment attached.
You can check this after override the onActivityResult() of your activity, and put a debug point there.
After you getting result in your activity onActivityResult() method, you can send it to your fragment's onActivityResult().
Hope this will help.
First of all if you are using LoginButton then you don't need to register with LoginManager. Here is the sample
//Using Facebook's LoginButton
//Register Callback
callbackManager = CallbackManager.Factory.create();
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("email")); //set permissions as public_profile, email, etc
loginButton.setFragment(this); //If you are using in a fragment
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
// App code
}
#Override
public void onCancel() {
// App code
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
Now with LoginManager when using Custom Button to login instead of FB's LoginButton
//To check if you are already logged In
boolean loggedIn = AccessToken.getCurrentAccessToken() == null;
// To Manually login. This will launch facebook's login screen.
LoginManager.getInstance().logInWithReadPermissions(this,
Arrays.asList("public_profile","email"));
In both the cases, for Fragment or Activity you need to handle onActivityResult
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
I am sharing a video on FB via share dialog in Android. The sharing works perfectly fine. However, FB post id returns null. The callback returns even before the video is uploaded. Please let me know, if I missing something. Below is my code.
public class TestFragment extends Fragment {
private CallbackManager callbackManager;
private ShareDialog shareDialog;
public TestFragment() {
// Required empty public constructor
}
public static TestFragment newInstance(String path, String json) {
TestFragment fragment = new TestFragment();
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getActivity());
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
// this part is optional
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Timber.d("result.getPostId() :: " + result.getPostId());
}
#Override
public void onCancel() {
Timber.d("Facebook : Cancelled");
}
#Override
public void onError(FacebookException e) {
Timber.d(e.getMessage());
}
});
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_test, container, false);
ButterKnife.inject(this, view);
return view;
}
#OnClick(R.id.facebookShare)
public void share() {
Timber.d("share button pressed");
if (ShareDialog.canShow(ShareVideoContent.class)) {
Timber.d("showing share dialog");
shareDialog.show(getVideoContent());
} else {
Timber.d("unable to show the share dialog");
}
}
private ShareVideoContent getVideoContent() {
Timber.d(mVideoMetadata.getVideoId());
ShareVideo shareVideo = new ShareVideo.Builder()
.setLocalUrl(Uri.parse("... file ..."))
.build();
ShareVideoContent content = new ShareVideoContent.Builder()
.setVideo(shareVideo)
.build();
return content;
}
#Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
shareDialog.show(shareContent, ShareDialog.Mode.FEED);
Set mode to ShareDialog.Mode.FEED.
It's working for me .
Here's example
When Login Success With Facebook Then Call This Method
shareOnFacebook()
private void shareOnFacebook(){
ShareLinkContent shareContent = new ShareLinkContent.Builder()
.setContentTitle("The Simpson!")
.setContentUrl(Uri.parse("http://www.codecube.in/airbucks-project"))
.build();
mFacebookShareDialog.show(shareContent, ShareDialog.Mode.FEED);
mFacebookShareDialog.registerCallback( this.callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Log.v("MyApp", "Share success!"); //Showed if I press the share or the cancel button
String postID = result.getPostId();
Log.v("MyApp", "Share success!" +result.getPostId());
}
#Override
public void onCancel() {
Log.v("MyApp", "Share canceled"); //Only showed when I press the close button
}
#Override
public void onError(FacebookException e) {
Log.v("MyApp","Share error: " + e.toString());
}
});
mFacebookShareDialog.show(shareContent, ShareDialog.Mode.FEED);
}
#Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
I have followed some tutorials how to use facebook with android app. I managed to implement working "log in" button and "share" button however I cant make like button work properly. After I press it i get this question image appearing for a second and then it disapears:
Here is my application code(its simple activity with fragment in it):
public class FacebookFragment extends Fragment {
private View rootView;
private TextView simpleTextView;
private CallbackManager callbackManager;
private AccessTokenTracker accessTokenTracker;
private ProfileTracker profileTracker;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//PODSTAWOWE RZECZY
FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); //facebook
callbackManager = CallbackManager.Factory.create();
registerCallback();
//JAKIEŚ TOKENY I INNE TRACKERY DO UPDATÓW
accessTokenTracker = new AccessTokenTracker() {
#Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
Toast.makeText(getActivity().getApplicationContext(), "currentAccessTokenChanged", Toast.LENGTH_LONG).show();
simpleTextView.setText("current access token changed");
}
};
profileTracker = new ProfileTracker() {
#Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
// App code
if (currentProfile != null) {
((TextView) rootView.findViewById(R.id.textView)).setText("Welcome " + currentProfile.getName());
} else {
Toast.makeText(getActivity().getApplicationContext(), "Profil null", Toast.LENGTH_LONG).show();
}
}
};
//ZACZYNAMY ŚLEDZIĆ
profileTracker.startTracking();
accessTokenTracker.startTracking();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_facebook, container, false);
//SPRAWDZAMY CZY ZALOGOWANY JEST UZYTKOWNIK I ROBIMY SET-UP PROGRAMU
simpleTextView = (TextView) rootView.findViewById(R.id.textView);
checkIfLogged();
setFacebookLoginButton();
setFacebookLikeButton();
setFacebookShareButton();
// Inflate the layout for this fragment
return rootView;
}
#Override
public void onStop() {
super.onStop();
//STOPUJEMY TRACKING
accessTokenTracker.stopTracking();
profileTracker.stopTracking();
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
//========================= CUSTOM METHODS ========================================
private void checkIfLogged(){
Profile profile = Profile.getCurrentProfile();
if (AccessToken.getCurrentAccessToken() != null) {
simpleTextView.setText("Welcome " + profile.getName());
} else {
Toast.makeText(getActivity().getApplicationContext(), "not logged in", Toast.LENGTH_LONG).show();
}
}
private void setFacebookLoginButton(){
LoginButton facebookButton = (LoginButton) rootView.findViewById(R.id.login_button);
facebookButton.setFragment(this);
}
private void registerCallback(){
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
}
#Override
public void onCancel() {
Toast.makeText(getActivity().getApplicationContext(), "too bad you didn't log in...", Toast.LENGTH_LONG).show();
}
#Override
public void onError(FacebookException exception) {
Toast.makeText(getActivity().getApplicationContext(), "that's that error shit...", Toast.LENGTH_LONG).show();
}
});
}
private void setFacebookLikeButton(){
LikeView likeView = (LikeView) rootView.findViewById(R.id.like_button);
likeView.setLikeViewStyle(LikeView.Style.STANDARD);
likeView.setFragment(this);
likeView.setOnErrorListener(new LikeView.OnErrorListener() {
#Override
public void onError(FacebookException e) {
Toast.makeText(getActivity().getApplicationContext(), "masz chuja nie lajka...", Toast.LENGTH_LONG).show();
}
});
likeView.setObjectIdAndType("https://www.facebook.com/FacebookDevelopers", LikeView.ObjectType.PAGE);
}
private void setFacebookShareButton(){
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("http://joemonster.org"))
.setImageUrl(Uri.parse("http://joemonster.org/i/2015/05/pasazer.jpg")).
setContentDescription("Prawdopodobnie najlepsza strona we wszechświecie!")
.setContentTitle("Joe Monster")
.build();
ShareButton shareButton = (ShareButton)rootView.findViewById(R.id.share_button);
shareButton.setFragment(this);
shareButton.setShareContent(content);
}
}
Other concerning behaviour:
If I use "share" button to log in then my "log in" button doesn't change to display "Log out". If I then click "log in" button and cancel it. I will have to "log in" again with "share" or "like" button.
If I use "log in" button to log in then below like button I see number of likes this site get.
I don't have facebook app installed in my virtual device.
Use of the Like button requires app approval, so during development, only users with Admin/Developer/Tester roles in your app can access it. Once it's approved, then any user can use the feature.
I want to publish my bitmap photo to my app's album without approving it from facebook. As far as I did it has a loginButton when a login is successfull a share button appears and the bitmap photo is uploaded when he share button is clicked. Everything is going fine but I had to approve the photo from the album to share it with my friends. here is my code which is described by developers site of facebook with fragment
public class MainFragment extends Fragment implements OnClickListener {
private static final String TAG = "MainFragment";
private UiLifecycleHelper uiHelper;
LoginButton authButton;
Button bShare;
private Session.StatusCallback callback = new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state,
Exception exception) {
onSessionStateChange(session, state, exception);
}
};
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.main, container, false);
authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setFragment(this);
bShare = (Button) view.findViewById(R.id.bShare);
bShare.setOnClickListener(this);
return view;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
#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();
}
#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);
}
private void onSessionStateChange(Session session, SessionState state,
Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
bShare.setVisibility(View.VISIBLE);
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
bShare.setVisibility(View.INVISIBLE);
}
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data,
new FacebookDialog.Callback() {
#Override
public void onError(FacebookDialog.PendingCall pendingCall,
Exception error, Bundle data) {
Log.e("Activity",
String.format("Error: %s", error.toString()));
}
#Override
public void onComplete(
FacebookDialog.PendingCall pendingCall, Bundle data) {
Log.i("Activity", "Success!");
}
});
}
#Override
public void onClick(View v) {
Bitmap image = Joursey.img;
Request.Callback UploadCallback = new Request.Callback() {
#Override
public void onCompleted(Response response) {
if (response.getError() != null) {
Log.d("Upload",
"photo upload problem. Error="
+ response.getError());
Toast.makeText(getActivity(),
"Problem occured while uploading",
Toast.LENGTH_LONG).show();
}
Object graphResponse = response.getGraphObject().getProperty(
"id");
if (graphResponse == null || !(graphResponse instanceof String)
|| TextUtils.isEmpty((String) graphResponse)) {
Log.d("Upload", "failed photo upload/no response");
Toast.makeText(getActivity(),
"Failed to upload/no response", Toast.LENGTH_LONG)
.show();
} else {
Log.d("Upload", "Successfully Uploaded");
Toast.makeText(getActivity(), "Successfully Uploaded",
Toast.LENGTH_LONG).show();
}
}
};
Request request = Request.newUploadPhotoRequest(
Session.getActiveSession(), image, UploadCallback);
Bundle params = request.getParameters();
params.putString("name", "This is my favorite jursey");
request.setParameters(params);
request.executeAsync();
}
}
I want such that I dont need to aprove it from my profile, it should be auto published? what change d I need to make here?