i have posted bug on facebook developer : https://developers.facebook.com/bugs/1598537583730278/
what i've done :
take hellofacebooksample facebook-android-sdk-4.4.0.zip , adapt make ot work android studio.
build.gradle :
apply plugin: 'com.android.application' android { compilesdkversion 22 buildtoolsversion "22.0.1" defaultconfig { applicationid "com.example.hellofacebook" minsdkversion 15 targetsdkversion 22 versioncode 1 versionname "1.0" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } } repositories { mavencentral() } dependencies { compile filetree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.0' compile 'com.facebook.android:facebook-android-sdk:4.4.0' } i have added logs in hellofacebooksampleactivity.java :
/** * copyright (c) 2014-present, facebook, inc. rights reserved. * * hereby granted non-exclusive, worldwide, royalty-free license use, * copy, modify, , distribute software in source code or binary form use * in connection web services , apis provided facebook. * * software integrates facebook platform, use of * software subject facebook developer principles , policies * [http://developers.facebook.com/policy/]. copyright notice shall * included in copies or substantial portions of software. * * software provided "as is", without warranty of kind, express or * implied, including not limited warranties of merchantability, fitness * particular purpose , noninfringement. in no event shall authors or * copyright holders liable claim, damages or other liability, whether * in action of contract, tort or otherwise, arising from, out of or in * connection software or use or other dealings in software. */ package com.example.hellofacebook; import android.app.alertdialog; import android.content.intent; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.location.location; import android.net.uri; import android.os.bundle; import android.support.v4.app.fragmentactivity; import android.util.log; import android.view.view; import android.widget.button; import android.widget.textview; import com.facebook.*; import com.facebook.appevents.appeventslogger; import com.facebook.login.loginmanager; import com.facebook.login.loginresult; import com.facebook.login.widget.profilepictureview; import com.facebook.share.shareapi; import com.facebook.share.sharer; import com.facebook.share.model.sharephoto; import com.facebook.share.model.sharephotocontent; import com.facebook.share.model.sharelinkcontent; import com.facebook.share.widget.sharedialog; import java.util.arraylist; import java.util.arrays; public class hellofacebooksampleactivity extends fragmentactivity { private static final string permission = "publish_actions"; private static final location seattle_location = new location("") { { setlatitude(47.6097); setlongitude(-122.3331); } }; private final string pending_action_bundle_key = "com.example.hellofacebook:pendingaction"; private button poststatusupdatebutton; private button postphotobutton; private profilepictureview profilepictureview; private textview greeting; private pendingaction pendingaction = pendingaction.none; private boolean canpresentsharedialog; private boolean canpresentsharedialogwithphotos; private callbackmanager callbackmanager; private profiletracker profiletracker; private sharedialog sharedialog; private facebookcallback<sharer.result> sharecallback = new facebookcallback<sharer.result>() { @override public void oncancel() { log.d("hellofacebook", "canceled"); } @override public void onerror(facebookexception error) { log.d("hellofacebook", string.format("error: %s", error.tostring())); string title = getstring(r.string.error); string alertmessage = error.getmessage(); showresult(title, alertmessage); } @override public void onsuccess(sharer.result result) { log.d("hellofacebook", "success!"); if (result.getpostid() != null) { string title = getstring(r.string.success); string id = result.getpostid(); string alertmessage = getstring(r.string.successfully_posted_post, id); showresult(title, alertmessage); } } private void showresult(string title, string alertmessage) { new alertdialog.builder(hellofacebooksampleactivity.this) .settitle(title) .setmessage(alertmessage) .setpositivebutton(r.string.ok, null) .show(); } }; private enum pendingaction { none, post_photo, post_status_update } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); facebooksdk.sdkinitialize(this.getapplicationcontext()); callbackmanager = callbackmanager.factory.create(); log.e("facebook sample", "on create"); loginmanager.getinstance().registercallback(callbackmanager, new facebookcallback<loginresult>() { @override public void onsuccess(loginresult loginresult) { log.e("facebook sample", "on success"); handlependingaction(); updateui(); } @override public void oncancel() { log.e("facebook sample", "on cancel"); if (pendingaction != pendingaction.none) { showalert(); pendingaction = pendingaction.none; } updateui(); } @override public void onerror(facebookexception exception) { log.e("facebook sample", "on error"); if (pendingaction != pendingaction.none && exception instanceof facebookauthorizationexception) { showalert(); pendingaction = pendingaction.none; } updateui(); } private void showalert() { new alertdialog.builder(hellofacebooksampleactivity.this) .settitle(r.string.cancelled) .setmessage(r.string.permission_not_granted) .setpositivebutton(r.string.ok, null) .show(); } }); sharedialog = new sharedialog(this); sharedialog.registercallback( callbackmanager, sharecallback); if (savedinstancestate != null) { string name = savedinstancestate.getstring(pending_action_bundle_key); pendingaction = pendingaction.valueof(name); } setcontentview(r.layout.main); profiletracker = new profiletracker() { @override protected void oncurrentprofilechanged(profile oldprofile, profile currentprofile) { updateui(); // it's possible waiting profile populated in order // post status update. handlependingaction(); } }; profilepictureview = (profilepictureview) findviewbyid(r.id.profilepicture); greeting = (textview) findviewbyid(r.id.greeting); poststatusupdatebutton = (button) findviewbyid(r.id.poststatusupdatebutton); poststatusupdatebutton.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { onclickpoststatusupdate(); } }); postphotobutton = (button) findviewbyid(r.id.postphotobutton); postphotobutton.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { onclickpostphoto(); } }); // can present share dialog regular links? canpresentsharedialog = sharedialog.canshow( sharelinkcontent.class); // can present share dialog photos? canpresentsharedialogwithphotos = sharedialog.canshow( sharephotocontent.class); } @override protected void onresume() { super.onresume(); // call 'activateapp' method log app event use in analytics , advertising // reporting. in onresume methods of primary activities app may // launched into. appeventslogger.activateapp(this); updateui(); } @override protected void onsaveinstancestate(bundle outstate) { super.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); callbackmanager.onactivityresult(requestcode, resultcode, data); } @override public void onpause() { super.onpause(); // call 'deactivateapp' method log app event use in analytics , advertising // reporting. in onpause methods of primary activities app may // launched into. appeventslogger.deactivateapp(this); } @override protected void ondestroy() { super.ondestroy(); profiletracker.stoptracking(); } private void updateui() { boolean enablebuttons = accesstoken.getcurrentaccesstoken() != null; poststatusupdatebutton.setenabled(enablebuttons || canpresentsharedialog); postphotobutton.setenabled(enablebuttons || canpresentsharedialogwithphotos); profile profile = profile.getcurrentprofile(); if (enablebuttons && profile != null) { profilepictureview.setprofileid(profile.getid()); greeting.settext(getstring(r.string.hello_user, profile.getfirstname())); } else { profilepictureview.setprofileid(null); greeting.settext(null); } } private void handlependingaction() { pendingaction previouslypendingaction = pendingaction; // these actions may re-set pendingaction if still pending, assume // succeed. pendingaction = pendingaction.none; switch (previouslypendingaction) { case none: break; case post_photo: postphoto(); break; case post_status_update: poststatusupdate(); break; } } private void onclickpoststatusupdate() { performpublish(pendingaction.post_status_update, canpresentsharedialog); } private void poststatusupdate() { profile profile = profile.getcurrentprofile(); sharelinkcontent linkcontent = new sharelinkcontent.builder() .setcontenttitle("hello facebook") .setcontentdescription( "the 'hello facebook' sample showcases simple facebook integration") .setcontenturl(uri.parse("http://developers.facebook.com/docs/android")) .build(); if (canpresentsharedialog) { sharedialog.show(linkcontent); } else if (profile != null && haspublishpermission()) { shareapi.share(linkcontent, sharecallback); } else { pendingaction = pendingaction.post_status_update; } } private void onclickpostphoto() { performpublish(pendingaction.post_photo, canpresentsharedialogwithphotos); } private void postphoto() { bitmap image = bitmapfactory.decoderesource(this.getresources(), r.drawable.icon); sharephoto sharephoto = new sharephoto.builder().setbitmap(image).build(); arraylist<sharephoto> photos = new arraylist<>(); photos.add(sharephoto); sharephotocontent sharephotocontent = new sharephotocontent.builder().setphotos(photos).build(); if (canpresentsharedialogwithphotos) { sharedialog.show(sharephotocontent); } else if (haspublishpermission()) { shareapi.share(sharephotocontent, sharecallback); } else { pendingaction = pendingaction.post_photo; // need new permissions, complete action when called back. loginmanager.getinstance().loginwithpublishpermissions( this, arrays.aslist(permission)); } } private boolean haspublishpermission() { accesstoken accesstoken = accesstoken.getcurrentaccesstoken(); return accesstoken != null && accesstoken.getpermissions().contains("publish_actions"); } private void performpublish(pendingaction action, boolean allownotoken) { accesstoken accesstoken = accesstoken.getcurrentaccesstoken(); if (accesstoken != null || allownotoken) { pendingaction = action; handlependingaction(); } } } the problem :
upon connection, facebook activity displays no error when click on cancel or on ok button, goes on hellofacebooksampleactivity fires oncreate() function. described in http://developer.android.com/reference/android/app/activity.html, activity can stopped , killed @ moment if still in activity stack , in case fires oncreate() when app goes on it. result callback reinitialized , it's not possible response authentication. bug happens lg g2 mini not samsung galaxy s4. app seems work fine otherwise.
i have had problem current app doing step step facebook android sdk tutorial , have same problem official sample app.
if go phone menu when in hellofacebooksampleactivity , go app, oncreate() not fired, if wait long enough before reopening app.
i hope i'm doing wrong.
anyway thank in advance given.
android studio version : 1.2.2
test telephones : lg g2 mini android 5.0.2, samsung galaxy s4 android 5.0.1
sdk version: 4.4.0
i facing same issue, have found solution overriding onactivityresult method.
after putting method in activity class, callback work
@override public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); mcallbackmanager.onactivityresult(requestcode, resultcode, data); }
Comments
Post a Comment