如何将照片从图库上传到Facebook的脸书?

时间:2011-04-28 08:50:50

标签: android facebook

public class PickImage extends Activity   {
    /** Called when the activity is first created. */

    private static final int PICK_IMAGE = 1;
    Bitmap bitmap;
    byte[] data;
    Button upload,facebbok;
    String imageFilePath;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        upload=(Button)findViewById(R.id.btnupload); 
        facebbok=(Button)findViewById(R.id.btnfacebook);

        upload.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
             intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("image/*");
                startActivityForResult(intent,PICK_IMAGE);


            }                       
         }          
        );


        facebbok.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                startActivity(new Intent(PickImage.this,FacebookShare.class));
                //InitiateUpload();     
                 //finish();
            }                       
         }          
        );



            }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent d) 
        {
            if(requestCode == PICK_IMAGE && d != null && d.getData() != null){
                Uri _uri = d.getData();

                if (_uri != null) {
                    //User had pick an image.
                    Cursor cursor = getContentResolver().query(_uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
                    cursor.moveToFirst();

                    String imageFilePath = cursor.getString(0);
                    BitmapFactory.Options o2 = new BitmapFactory.Options();
                    //o2.inSampleSize = scale;
                    bitmap = BitmapFactory.decodeFile(imageFilePath, o2);
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    bitmap.compress(CompressFormat.JPEG, 100, bos);
                    data = bos.toByteArray();
                    cursor.close();
                }
            }
            super.onActivityResult(requestCode, resultCode, d);
        }


        void InitiateUpload() {
                Intent uploader_intent = new Intent(this, FacebookShare.class);
            startActivity(uploader_intent);


        } 

}

当我点击Facebook按钮时,应用程序崩溃了?

你能为Facebook上的照片上传提供解决方案。

由于

0 个答案:

没有答案