Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:54:36+00:00 2026-06-15T04:54:36+00:00

I have integrated Facebook API in an android application. Purpose of my main application

  • 0

I have integrated Facebook API in an android application. Purpose of my main application is shooting a image from camera and storing in SD card. Through integration of Facebook API i am posting photo on user’s wall with proper authentication. Problem, what i am facing is very dramatic.Sometimes i am able to post photo on user’s wall successfully, and sometimes my application has stopped with notification “Unfortunately XXXXXXXX has stopped working”. ratio of failure is 1/5 .Please help me as soon as possible
Code is here

public class FbshareScreen extends Activity implements OnClickListener{
    public  Button                  _share;
private Button                  _decline;
int check;

public static final String APP_ID ="433644253229338";

private static final String[] PERMISSIONS = new String[] {"publish_stream"};
private com.android.fb.Facebook facebook;
private String path = ProjectUtil.createSdCardDirectory("/Camera/Photo");

public void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);
    setContentView(R.layout.facebookshare);

    facebook = new Facebook(APP_ID);

    _decline = (Button) findViewById(R.id.Button02);
    _share = (Button)findViewById(R.id.Button01);

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;
    Bitmap bitmap = BitmapFactory.decodeFile(path+"/image.png",options);

    ImageView storedphoto= (ImageView)findViewById(R.id.storedphoto);
    storedphoto.setImageBitmap(bitmap);

    _decline.setOnClickListener(this);
    _share.setOnClickListener(this);

    facebook.setAccessExpires(5000);
}  

    private void logoutFromFacebook() 
    {
      AsyncFacebookRunner    mAsyncRunner = new AsyncFacebookRunner(facebook);
         mAsyncRunner.logout(FbshareScreen.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) {
                }
            });

    }   


    public void loginAndPostToWall()
    {
         facebook.authorize(this,PERMISSIONS,Facebook.FORCE_DIALOG_AUTH,new LoginDialogListener());
         //facebook.authorize(this, new String[] {"publish_stream"}, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener() {}); 
    }
    String  response;
    public void postToWall(String message)
    { 

        try {
            addVango(BitmapFactory.decodeResource(getResources(), R.drawable.imagepicker),BitmapFactory.decodeFile(ProjectUtil.createSdCardDirectory("/Camera/Photo")+"/image.png"));

            byte[] data = null;
            try
            {

                FileInputStream fis =  new FileInputStream(ProjectUtil.createSdCardDirectory("/Camera/Photo")+"/image.png");
                Bitmap bi = BitmapFactory.decodeStream(fis);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                bi.compress(Bitmap.CompressFormat.PNG, 10, baos);
                data = baos.toByteArray(); 
                }catch (Exception e) 
                {
                    Toast.makeText(FbshareScreen.this,e.toString(),Toast.LENGTH_SHORT).show();
                }
                response=facebook.request("me");
                Bundle parameters = new Bundle();       
                parameters.putString("message", message);   
                parameters.putByteArray("picture", data);
                 AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);   
                 mAsyncRunner.request("me/photos", parameters, "POST", new mRequestListener(), null);

                 Log.d("Tests", "got response: " + response);
                 if (response == null || response.equals("") || response.equals("false")) 
                 {   
                    Log.v("Error", "Blank response");
                    Toast.makeText(FbshareScreen.this,"Blank response",Toast.LENGTH_SHORT).show();

                    check=1;
                 }
                 else
                 {
                     check=2;


                     Intent FBshare_Home =  new Intent(FbshareScreen.this,FacebookFeedback.class);
                     startActivity(FBshare_Home);
                     File file= new File(path+"/image.png");
                     file.delete();
                     finish();

                 }

        } catch (Exception e) {
            Log.e("Error", e.toString());
        }
    }
    class LoginDialogListener implements com.android.fb.Facebook.DialogListener
    {
        public void onComplete(Bundle values) {
            new MailSendingTask().execute((Void[])null);


                //postToWall("");

        }

        public void onFacebookError(FacebookError error) 
        {
            showToast("Authentication with Facebook failed!");
            File f= new File("/mnt/sdcard/Camera/Photo/image.png");
            if(f.canRead())
            {
                f.delete();
            }
            Intent in=new Intent (FbshareScreen.this, HomeScreen.class);
            startActivity(in);
            finish();
        }
        public void onError(DialogError error) {
            showToast("Authentication with Facebook failed!");
            File f= new File("/mnt/sdcard/Camera/Photo/image.png");
            if(f.canRead())
            {
                f.delete();
            }
            Intent in=new Intent (FbshareScreen.this, HomeScreen.class);
            startActivity(in);
            finish();
        }
        public void onCancel() {
            showToast("Authentication with Facebook cancelled!");
            File f= new File("/mnt/sdcard/Camera/Photo/image.png");
            if(f.canRead())
            {
                f.delete();
            }
            Intent in=new Intent (FbshareScreen.this, HomeScreen.class);
            startActivity(in);
            finish();
        }
    }
    class WallPostDialogListener implements com.android.fb.Facebook.DialogListener {

        public void onComplete(Bundle values) {
            logoutFromFacebook();
                if (response != null)
                {
                 showToast("Message posted to your facebook wall!");

            } else {
                showToast("Wall post cancelled!");   
            }
            finish();

        }
        public void onFacebookError(FacebookError e) {
            showToast("Failed to post to wall!");
            e.printStackTrace();
            finish();
        }
        public void onError(DialogError e) {
            showToast("Failed to post to wall!");
            e.printStackTrace();
            finish();
        }
        public void onCancel() {
            showToast("Wall post cancelled!");
            finish();
        }
    }
    private void showToast(String message)
    {
        Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
    }
    public class mRequestListener implements RequestListener{

        private static final String TAG = "I am Tag";

        @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 *******************");
        }

    }


    public void onActivityResult(int requestCode, int resultCode, Intent data) 
    {
        super.onActivityResult(requestCode, resultCode, data);
        facebook.authorizeCallback(requestCode, resultCode, data);
    }

    public void onClick(View view) 
    {
        if(view == _share)
        {
            if(!ProjectUtil.haveNetworkConnection(FbshareScreen.this)){
                Toast.makeText(FbshareScreen.this,"Unable to connect at this time please check your network connection and try again.",Toast.LENGTH_LONG).show();
                return;
            }
            new FacebookSendingTask().execute((Void[])null);

            loginAndPostToWall(); 


        }else if(view == _decline){
            File file= new File(path+"/image.png");
            file.delete();
            //Toast.makeText(getApplicationContext(), "Photo Deleted \nClick Another Photo", Toast.LENGTH_SHORT).show();

            finish();
        }

    }
public Bitmap   addVango(Bitmap c, Bitmap s)
{
    Bitmap cs = null; 

    int width, height = 0; 

    if(c.getWidth() > s.getWidth()) 
    { 
      width = c.getWidth();   
      height = c.getHeight() + s.getHeight(); 
    } else { 
      width = s.getWidth(); 
      height = c.getHeight() + s.getHeight(); 
    } 


    cs = Bitmap.createBitmap(c.getWidth(), c.getHeight(), Bitmap.Config.ARGB_8888); 
    Canvas comboImage = new Canvas(cs); 
    comboImage.drawBitmap(c, 0f, 0f, null);
    comboImage.drawBitmap(s, c.getWidth()-s.getWidth()-75, c.getHeight()-s.getHeight()-155, null);



    OutputStream os = null; 
    try { 
      os = new FileOutputStream(ProjectUtil.createSdCardDirectory("/Camera/Photo")+"/image.png"); 
      cs.compress(CompressFormat.PNG, 100, os); 
    } catch(IOException e) 
    { 
      Log.e("combineImages", "problem combining images", e); 
      Toast.makeText(FbshareScreen.this,""+e,Toast.LENGTH_SHORT).show();
    }

    return cs; 
}


 public class MailSendingTask extends AsyncTask <Void, Void, Void> {

        private ProgressDialog progressDialog;
        public  Looper mLooper;

        @Override
        protected void onPreExecute() {

            this.progressDialog = ProgressDialog.show(
                    FbshareScreen.this,

                    "Doing Processing", // title
                    "Posting Photo", // message
                    true // indeterminate
            );
        }

        @Override
        protected Void doInBackground(Void... params) {
            //if(haveNetworkConnection())

            try
            {
                postToWall("");
            }
            catch (Exception exception)
            {
                Log.e("Exception", exception.toString());
                check=1;
            }


            return null;
        }

        @Override
        protected void onPostExecute(Void v) {
            this.progressDialog.cancel();
            if(check==1)
                Toast.makeText(getApplicationContext(), "Wall Post Cancelled", Toast.LENGTH_SHORT).show();
            if(check==2)
                Toast.makeText(getApplicationContext(), "Message Posted To your Wall", Toast.LENGTH_SHORT).show();




        }

    }

 public boolean onKeyDown(int keyCode, KeyEvent event)  
    {
        if (keyCode == KeyEvent.KEYCODE_BACK) 
        {
            File file= new File(path+"/image.png");
            if(file.canRead())
            {
            file.delete();

            Intent in=new Intent(FbshareScreen.this,FacebookFeedback.class);
            in.putExtra("value", "1");
            startActivity(in);             
            return true;
            }

        }
        return super.onKeyDown(keyCode, event);

    }




 public class FacebookSendingTask extends AsyncTask <Void, Void, Void> {

        private ProgressDialog progressDialog;
        public  Looper mLooper;

        @Override
        protected void onPreExecute() {

            this.progressDialog = ProgressDialog.show(
                    FbshareScreen.this,

                    "Connecting To Facebook", // title
                    "Wait for a Moment", // message
                    true 
            );
        }

        @Override
        protected Void doInBackground(Void... params) {



            try {
                facebook.logout(getApplicationContext());
            } catch (Exception e) {
                Log.e("Error", e.toString());
            }


            return null;
        }

        @Override
        protected void onPostExecute(Void v) {
            this.progressDialog.cancel();
    }

    }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:54:37+00:00Added an answer on June 15, 2026 at 4:54 am

    Your problem is arising because your application is exceeding cache limit of your android device.The heap size of android device is causing this memory exception. Please upgrade memory or use higher end devices.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have integrated Facebook using library in my previous application and it works fine
I am new to the iPhone Programming. I have integrated facebook into my application
I'm trying to retrieve in my android app(in which I have facebook integrated )
I have integrated Facebook into my Android App. When a user now posts a
Hi I have integrated Facebook with asp.net web site through open id But now
I have integrated my application with Facebook, and for this I am using Facebook's
I am having a strange error in my android project. I have integrated Facebook
I have integrated the iOs Facebook API into my app successfully. Now, I want
I have integrated Facebook functionality into my applications. By using the link https://github.com/facebook/facebook-ios-sdk ,
I have simple facebook connect plugin on a wordpress blog and have integrated the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.