I want to get the id from the Facebook User but what I've tried so far doesn't work...
public class fbLogin extends Activity {
public static final int LOGIN = Menu.FIRST;
public static final int GET_EVENTS = Menu.FIRST + 1;
public static final int GET_ID = Menu.FIRST + 2;
public static final String APP_ID = "361579407254212";
public static final String TAG = "FACEBOOK CONNECT";
private Facebook mFacebook;
private AsyncFacebookRunner mAsyncRunner;
private Handler mHandler = new Handler();
private static final String[] PERMS = new String[] { "user_events","email" };
private TextView mText;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
// setup the content view
initLayout();
// setup the facebook session
mFacebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
if (mFacebook.isSessionValid()) {
AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner(mFacebook);
asyncRunner.logout(this, new LogoutRequestListener());
} else {
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
mAsyncRunner.request("me", new IDRequestListener());
}
protected void initLayout() {
LinearLayout rootView = new LinearLayout(this.getApplicationContext());
rootView.setOrientation(LinearLayout.VERTICAL);
this.mText = new TextView(this.getApplicationContext());
this.mText.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
rootView.addView(this.mText);
this.setContentView(rootView);
}
private class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values) {}
public void onFacebookError(FacebookError e) {}
public void onError(DialogError e) {}
public void onCancel() {}
}
private class LogoutRequestListener implements RequestListener {
public void onComplete(String response, Object state) {
// Dispatch on its own thread
mHandler.post(new Runnable() {
public void run() {
mText.setText("Logged out");
}
});
}
public void onIOException(IOException e, Object state) {}
public void onFileNotFoundException(FileNotFoundException e, Object state) {}
public void onMalformedURLException(MalformedURLException e, Object state) {}
public void onFacebookError(FacebookError e, Object state) {}
}
private class IDRequestListener implements RequestListener {
public void onComplete(String response, Object state) {
try {
// process the response here: executed in background thread
Log.d(TAG, "Response: " + response.toString());
JSONObject json = Util.parseJson(response);
final String id = json.getString("id");
fbLogin.this.runOnUiThread(new Runnable() {
public void run() {
mText.setText("Hello there, " + id + "!");
}
});
} catch (JSONException e) {
Log.w(TAG, "JSON Error in response");
mText.setText("catch1...");
} catch (FacebookError e) {
mText.setText("catch2");
}
}
public void onIOException(IOException e, Object state) {mText.setText("Logging out...1");}
public void onFileNotFoundException(FileNotFoundException e, Object state) {mText.setText("Logging out...2");}
public void onMalformedURLException(MalformedURLException e,Object state) {mText.setText("Logging out...3");}
public void onFacebookError(FacebookError e, Object state) {mText.setText("Logging out...4");}
}
}
It gives a Facebook Error when I go to the OnComplete method from the IDRequestListener class...
How can I fix it? Can anyone help me, please?
You can use socialauth android sdk. Can get user profile, post messages , gets friends list
http://code.google.com/p/socialauth-android/
authorize() is not synchronous and will return immediately. You'll need to wait for the authorization request to complete before submitting requests requiring an access token. Basically, fire the me request only when onComplete() has been called in the authorize() listener.
Also your activity seems to be missing the onActivityResult() implementation that feeds the Facebook object with authorization results, i.e.
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mFacebook.authorizeCallback(requestCode, resultCode, data);
}
Related
i working facebook api in android. i successfully can sing in in facebook and try to check facebook user name
i wrote some code but i have
only the original thread that created a view hierarchy
exception
this is a my code:
public void LoginFacebook() {
mFacebook.authorize(this, mPermissions, new LoginDialogListener());
}
private final class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values) {
SessionStore.save(mFacebook, getApplicationContext());
getProfileInformation();
}
public void onCancel() {
SessionEvents.onLoginError("Action Canceled");
}
#Override
public void onFacebookError(FacebookError error) {
SessionEvents.onLoginError(error.getMessage());
}
#Override
public void onError(DialogError error) {
SessionEvents.onLoginError(error.getMessage());
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mFacebook.authorizeCallback(requestCode, resultCode, data);
}
#SuppressWarnings("deprecation")
#SuppressLint("SdCardPath")
public void getProfileInformation() {
mAsyncRunner.request("me", new BaseRequestListener() {
#SuppressLint("CommitPrefEdits")
#Override
public void onComplete(String response, Object state) {
Log.e("Profile", response);
String json = response;
try {
JSONObject profile = new JSONObject(json);
facebook_userid = profile.getString("id");
facebook_username = profile.getString("name");
facebook_username = facebook_username.replace("%20", " ");
fb_name.setText(facebook_username);
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
public void onIOException(IOException e, Object state) {
}
#Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
}
#Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
}
#Override
public void onFacebookError(FacebookError e, Object state) {
}
});
}
what am i doing wrong. i can sing in but i can't to show username in textview.
if anyone knows solution please help me
thanks
In your onComplete method you're trying to set the text of a UI element. Your onComplete method is getting called from a background(non main/UI thread). Any time you make a UI change, it must be on the UI thread. Try inserting a runOnUIThread call in your onComplete like this:
runOnUiThread(new Runnable() {
public void run() {
fb_name.setText(facebook_username);
}
});
Note: you will need to make variables declared outside the runnable final (ex: facebook_username)
Also note: most (if not all) web based calls will return on a background thread so you might need to use runOnUIThread frequently.
I have been searching a lot to find a way to do this. But nothing seems to be working for me. Can someone please help in doing this?
This is my image button for facebook status post:
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/hoributtons"
android:layout_alignTop="#+id/imageButton2"
android:background="#00000000"
android:contentDescription="#string/facebook"
android:onClick="shareOnFacebook"
android:src="#drawable/facebookbutton" />
This is my mainactivity.java file's corresponding part:
public class MainActivity extends FacebookActivity {
private static final String APP_ID = "xxxxxxxxxxxxx";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void shareOnFacebook(View v) {
//mfacebook = new Facebook("xxxxxxxxxxxxx");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Can someone point in the right direction? :)
Assuming that you want to post on your own wall (since the question is not clear), this should work for you.
public class MainActivity extends Activity {
private static final String APP_ID = "xxxxxxxxxxxxx";
private Facebook mFacebook;
private AsyncFacebookRunner mAsyncRunner;
private EditText yourEditText;
private String toShare;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mFacebook = new Facebook();
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
SessionEvents.addAuthListener(new SampleAuthListener());
SessionEvents.addLogoutListener(new SampleLogoutListener());
yourEditText = (EditText) findViewById(R.id.<youreditTextId>);
toShare = yourEditText.getText().toString();
}
public void shareOnFacebook(View v) {
Bundle params = new Bundle();
params.putString("message", toShare);
mAsyncRunner.request("me/feed", params, "POST", new RequestListener() {
public void onMalformedURLException(MalformedURLException e) {}
public void onIOException(IOException e) {}
public void onFileNotFoundException(FileNotFoundException e) {}
public void onFacebookError(FacebookError e) {}
public void onComplete(String response) {
}
});
Toast.makeText(MainActivity.this, "Posting to your Wall", Toast.LENGTH_SHORT).show();
}
}
For details on posting pictures to wall, Facebook has a good documentation.
The simplest way to post message on user`s wall who is successfully login using your android application is(my working code)_
public class AndroidFacebookWallPost extends Activity {
// Your Facebook APP ID:
private static String APP_ID = "your App ID here"; //
// Instance of Facebook Class:
private Facebook facebook;
private AsyncFacebookRunner mAsyncRunner;
// Your ImageButton that Post Message to Facebook Wall:
ImageButton btnPostToWall;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnPostToWall = (ImageButton) findViewById(R.id.imageButton1);// Your image button...
facebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(facebook);
// set listener for Post Message button
btnPostToWall.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
postToWall();
}
});
}
/**
* Method that Post a Text Status using Facebook API on user`s wall.
*/
public void postToWall() {
// post on user's wall.
facebook.dialog(this, "feed", new DialogListener() {
#Override
public void onFacebookError(FacebookError error) {
Toast.makeText(AndroidFacebookWallPost.this, "Post fail "+error, Toast.LENGTH_LONG).show();
}
#Override
public void onError(DialogError error) {
Toast.makeText(AndroidFacebookWallPost.this, "Post fail due to "+error, Toast.LENGTH_LONG).show();
}
#Override
public void onComplete(Bundle values) {
Toast.makeText(AndroidFacebookWallPost.this, "Post success.", Toast.LENGTH_LONG).show();
}
#Override
public void onCancel() {
Toast.makeText(AndroidFacebookWallPost.this, "Cancle by user!", Toast.LENGTH_LONG).show();
}
});
}
}
for more please gone through Getting Started with the Facebook SDK for Android.
Here is details of variable that you can out in bundle
Bundle params = new Bundle();
params.putString("message", "This string will appear as the status message");
params.putString("link", "This is the URL to go to");
params.putString("name", "This will appear beside the picture");
params.putString("caption", "This will appear under the title");
params.putString("description", "This will appear under the caption");
params.putString("picture", "This is the image to appear in the post");
And use AsyncFacebookRunner for post data to facebook :
mAsyncRunner.request("me/feed", params, "POST", new RequestListener() {
public void onMalformedURLException(MalformedURLException e) {}
public void onIOException(IOException e) {}
public void onFileNotFoundException(FileNotFoundException e) {}
public void onFacebookError(FacebookError e) {}
public void onComplete(String response) {
}
});
I followed this tutorial http://www.androidhive.info/2012/03/android-facebook-connect-tutorial/ to connect Facebook to my Android application. Instead of having many buttons, I have a button that will be used for both login and logout.
1) The first time I run the class, I could login and then logout successfully. And when I click on the same button to login again, the login page would not appear, however the Toast text "LOGGING IN" appear, which is after loginToFacebook() function in my if-else. Hence, I assume, it should have run the facebook login page like the first time I run the class. But the login page does not appear.
What did I do wrong? And what should I do?
2) And how do I display the username in String fbLoggedIn after logged in instead of the text "CONNECTED!!" ?
public class FacebookActivity extends Activity{
private static String APP_ID = "";
private Facebook facebook;
private AsyncFacebookRunner mAsyncRunner;
String FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;
private Button backButton;
private String name = "CONNECTED!!";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_share);
facebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(facebook);
RelativeLayout fbButton = (RelativeLayout) findViewById(R.id.fbLayout);
fbButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (!facebook.isSessionValid())
{
System.out.println("Not Connected. Clicked and Login.");
loginToFacebook();
Toast.makeText(getApplicationContext(), "LOGGING IN", Toast.LENGTH_LONG).show();}
else
{
System.out.println("Connected. Logged Out.");
logoutFromFacebook();
Toast.makeText(getApplicationContext(), "LOGGED OUT", Toast.LENGTH_LONG).show();}
}
});
}
public void loginToFacebook() {
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
facebook.setAccessToken(access_token);
}
if (expires != 0) {
facebook.setAccessExpires(expires);
}
if (!facebook.isSessionValid()) {
facebook.authorize(this, new String[] { "email", "publish_stream" }, new DialogListener() {
#Override
public void onCancel() {
// Function to handle cancel event
}
#Override
public void onComplete(Bundle values) {
// Function to handle complete event
// Edit Preferences and update facebook acess_token
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
TextView fbUser = (TextView) findViewById(R.id.fbUser);
fbUser.setVisibility(View.VISIBLE);
String fbLoggedIn = name;
fbUser.setText(fbLoggedIn);
Toast.makeText(getApplicationContext(), "LOGGED IN AS " + name, Toast.LENGTH_LONG).show();
}
#Override
public void onError(DialogError error) {
// Function to handle error
}
#Override
public void onFacebookError(FacebookError fberror) {
// Function to handle Facebook errors
}
});
}
}
public void getProfileInformation() {
mAsyncRunner.request("me", new RequestListener() {
#Override
public void onComplete(String response, Object state) {
Log.d("Profile", response);
String json = response;
try {
JSONObject profile = new JSONObject(json);
// getting name of the user
final String name = profile.getString("name");
// getting email of the user
final String email = profile.getString("email");
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(), "Name: " + name + "\nEmail: " + email, Toast.LENGTH_LONG).show();
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
public void onIOException(IOException e, Object state) { }
#Override
public void onFileNotFoundException(FileNotFoundException e, Object state) { }
#Override
public void onMalformedURLException(MalformedURLException e, Object state) { }
#Override
public void onFacebookError(FacebookError e, Object state) { }
});
}
//logout from Facebook
public void logoutFromFacebook() {
mAsyncRunner.logout(this, new RequestListener() {
#Override
public void onComplete(String response, Object state) {
Log.d("Logout from Facebook", response);
if (Boolean.parseBoolean(response) == true) {
// User successfully Logged out
}
}
#Override
public void onIOException(IOException e, Object state) { }
#Override
public void onFileNotFoundException(FileNotFoundException e, Object state) { }
#Override
public void onMalformedURLException(MalformedURLException e, Object state) { }
#Override
public void onFacebookError(FacebookError e, Object state) { }
});
}
Just to be clearer, I set my if-else like this (extracted from the complete codes above).
RelativeLayout fbButton = (RelativeLayout) findViewById(R.id.fbLayout);
fbButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (!facebook.isSessionValid())
{
System.out.println("Not Connected. Clicked and Login.");
loginToFacebook();
Toast.makeText(getApplicationContext(), "LOGGING IN", Toast.LENGTH_LONG).show();}
else
{
System.out.println("Connected. Logged Out.");
logoutFromFacebook();
Toast.makeText(getApplicationContext(), "LOGGED OUT", Toast.LENGTH_LONG).show();}
}
});
This is the behavior that Facebook wants you to take with their API.Your login method checks to see if you have already signed in once and that the facebook session is active. If the session is active then it sets the properties of the facebook object and connects it behind the sences so that the login page does not show again.
So you're not doing anything wrong, it's suppose to happen this way.
i'm using facebook runner to apply some facebook api tesk.
i want to check if i got a JSON object with data or and error message so i'm checking the "message" field to check if it's null.
if it is not null and i have a massage, i want to display the message and exit the application.
this is my code in my activity:
public class Loader extends Activity implements FacebookConnectionListener, ServerDataListener {
private TextView loaderStatus;
private Facebook facebook;
private AsyncFacebookRunner facebookRunner;
private FacebookConnection facebookConnection;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loader);
facebook = new Facebook(facebookAppId);
facebookRunner = new AsyncFacebookRunner(facebook);
facebookConnection = new FacebookConnection(this, 1);
facebookRunner.request("me",facebookConnection);
}
#Override
public void onFacebookResponse(final String response , int step) {
final JSONObject facebookResults = convertToJSON(response);
final Context thisContext = (Context) getBaseContext();
String id = "", name = "", gender = "", homeTown = "";
Drawable profilePicture = null;
if (step == 1) {
if (facebookResults.isNull("message")) {
try {
id = facebookResults.getString("id");
name = facebookResults.getString("name");
gender = facebookResults.getString("gender");
JSONObject homeTownObject = (JSONObject) facebookResults.get("hometown");
homeTown = homeTownObject.getString("name");
profilePicture = getProfilePicture(id);
} catch (JSONException e) {
alert("Facebook", e.toString(), "Ok", thisContext);
}
facebookCurrentUser = new FacebookCurrentUser(id, name, gender);
facebookCurrentUser.setHomeTown(homeTown);
facebookCurrentUser.setProfilePicture(profilePicture);
app.setFacebookCurrentUser(facebookCurrentUser);
facebookConnection = new FacebookConnection(this, 2);
this.runOnUiThread(new Runnable() {
public void run() {
loaderStatus.setText("Getting friends details");
}
});
}
else {
this.runOnUiThread(new Runnable() {
public void run() {
alert("Facebook", "Can't get user details! Please try again", "Ok", thisContext);
}
});
}
}
public void alert (String title, String message, String ok, Context listener)
{
AlertDialog.Builder alert = new AlertDialog.Builder(listener);
alert.setMessage(message);
alert.setTitle(title);
alert.setPositiveButton(ok, new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
alert.show();
}
this is FacebookConnection class:
public class FacebookConnection implements RequestListener {
private FacebookConnectionListener listener;
private int step;
public FacebookConnection (FacebookConnectionListener listener, int step) {
this.listener = listener;
this.step = step;
}
public void updateFacebookListener(String response) {
listener.onFacebookResponse(response, step);
}
#Override
public void onComplete(String response, Object state) {
updateFacebookListener(response);
}
#Override
public void onIOException(IOException e, Object state) { }
#Override
public void onFileNotFoundException(FileNotFoundException e, Object state) { }
#Override
public void onMalformedURLException(MalformedURLException e, Object state) { }
#Override
public void onFacebookError(FacebookError e, Object state) { }
}
the FacebookConnectionListener interface:
public interface FacebookConnectionListener {
public void onFacebookResponse(String response, int step);
}
my alerts keep giving me the :
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
and i can't understand why.. help ?
Well, try this:
public void alert (String title, String message, String ok) {
this.runOnUiThread(new Runnable() {
public void run() {
AlertDialog alert = new AlertDialog.Builder(Loader.this).create();
alert.setMessage(message);
alert.setTitle(title);
alert.setPositiveButton(ok, new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
alert.show();
}
});
}
Instead of what you have now, and when you call it, just call it like any other method:
this.alert("Facebook", "Can't get user details! Please try again", "Ok")
I'm not exactly sure where it goes wrong, it even might have to do with you forgetting the create() part when constructing the dialog.
Hope this will sort things for you.
The reason it is appearing is because you are trying to update Ui from a different thread. As this is a partial code, I can suggest you changing your code to
MyActivity.this.runOnUiThread(new Runnable() {
public void run() {
loaderStatus.setText("Getting friends details");
}
});
where MyActivity is your Activity's name.
the easy way:
u can publishProgress(something)
and process the publishing, to show your alert :D
I'm trying to upload pictures from my SD Card to my facebook account and still got no luck.
I'm not getting any errors but the pictures I'm trying to upload are not appearing on my wall.
Here's my code (full code of the Main Class):
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;
import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.facebook.android.Facebook.DialogListener;
public class Gallery extends Activity {
private static final String TAG = "Gallery";
// Constants
private static final int UPDATE_GRID_VIEW = 0;
// References to our images
private ArrayList<Uri> picUri = new ArrayList<Uri>();
private ArrayList<String> picName = new ArrayList<String>();
private GridView mGridview;
private ImageAdapter mImageAdapter;
// For FaceBook
private Facebook facebook;
private String fb_AppId = "MY_APP_ID";
// Progress Dialog
private ProgressDialog progressD;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.gallery);
initializeViews();
initFacebook();
authorizeFbUser();
}
public void initializeViews(){
PictureListThread picThread = new PictureListThread();
picThread.start();
mImageAdapter = new ImageAdapter(this);
mGridview = (GridView) findViewById(R.id.gallery_gridview);
mGridview.setAdapter(mImageAdapter);
mGridview.setOnItemClickListener(mOnItemClickListener);
}
// Facebook Methods and Classes
public void initFacebook(){
facebook = new Facebook(fb_AppId);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
public void authorizeFbUser(){
facebook.authorize(this, new String[] { "email", "read_stream" },
new DialogListener() {
#Override
public void onComplete(Bundle values) {
Log.d(TAG, "******************* FACEBOOK::authorize::onComplete *******************");
}
#Override
public void onFacebookError(FacebookError error) {
Log.d(TAG, "******************* FACEBOOK::authorize::onFacebookError *******************");
}
#Override
public void onError(DialogError e) {
Log.d(TAG, "******************* FACEBOOK::authorize::onError *******************");
}
#Override
public void onCancel() {
Log.d(TAG, "******************* FACEBOOK::authorize::onCancel *******************");
}
});
}
public class mRequestListener implements RequestListener{
#Override
public void onMalformedURLException(MalformedURLException e, Object state) {
Log.d(TAG, "******************* FACEBOOK::onMalformedURLException *******************");
}
#Override
public void onIOException(IOException e, Object state) {
Log.d(TAG, "******************* FACEBOOK::onIOException *******************");
}
#Override
public void onFileNotFoundException(FileNotFoundException e, Object state) {
Log.d(TAG, "******************* FACEBOOK::onFileNotFoundException *******************");
}
#Override
public void onFacebookError(FacebookError e, Object state) {
Log.d(TAG, "******************* FACEBOOK::onFacebookError *******************");
}
#Override
public void onComplete(String response, Object state) {
Log.d(TAG, "******************* FACEBOOK::onComplete *******************");
}
}
// Methods
private Handler mHandler = new Handler() {
#Override public void handleMessage(Message msg) {
if(msg.what == UPDATE_GRID_VIEW) {
mImageAdapter.notifyDataSetChanged();
}
}
};
// Inner Classes
private OnItemClickListener mOnItemClickListener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Log.d(TAG,"[][][][][][][][][][]-------------> PATH: "+picUri.get(position).toString());
byte[] data = null;
Bitmap bi = BitmapFactory.decodeFile(picUri.get(position).toString());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Log.d(TAG,"[][][][][][][][][][]-------------> DATA: "+data);
Bundle param = new Bundle();
param.putString("method", "photos.upload");
param.putString("message", picName.get(position));
param.putByteArray("picture", data);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request("me/photos", param, "POST", new mRequestListener(), null);
Log.d(TAG,"[][][][][][][][][][]-------------> Gallery::mOnItemClickListener END!");
}
};
private class PictureListThread extends Thread {
#Override
public void run() {
Log.d(TAG, "******************* PictureListThread::run() STARTED! *******************");;
System.gc();
String[] proj = { MediaStore.Images.Media.DATA, MediaStore.Images.Media.TITLE};
Cursor picturecursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
proj, null, null, MediaStore.Images.Media.TITLE);
if (picturecursor == null)
return;
if (!picturecursor.moveToFirst())
return;
do {
String picTitle = picturecursor.getString(picturecursor.getColumnIndex(MediaStore.Images.Media.TITLE));
if(picTitle.contains("KEYWORD")){
picName.add(picTitle);
picUri.add(Uri.parse(picturecursor.getString(picturecursor.getColumnIndex(MediaStore.Images.Media.DATA))));
Log.d(TAG,"[][][][][][][][][][]-------------> PICTURE ADDED: "+picTitle);
mHandler.sendEmptyMessage(UPDATE_GRID_VIEW);
}
} while (picturecursor.moveToNext());
}
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return picUri.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(150, 100));
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageURI(picUri.get(position));
return imageView;
}
}
}
My
mRequestListener()::onComplete()
is being called with no errors and so I'm wondering why the pictures are not displaying on my wall.
Am I missing something here?
Please help.
Thanks in advance!
put this line.
mAsyncRunner.request("me/photos", param, "POST", new mRequestListener(), null);
instead of
mAsyncRunner.request(null, param, "POST", new mRequestListener(), null);
and check photo will appear on wall or not?
add "publish_stream" in permission..
If I am not mistaken, your Bundle param is missing "method" property. Try adding:
param.putString("method", "photos.upload");