Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从android手机摄像头拍摄照片并上传到facebook群组_Android_Facebook - Fatal编程技术网

从android手机摄像头拍摄照片并上传到facebook群组

从android手机摄像头拍摄照片并上传到facebook群组,android,facebook,Android,Facebook,我正在使用android教程hackbook中的代码,我已经能够将图片上传到我的墙上。我现在想要的是上传一张从我的相机拍摄的照片,然后上传到某个团体的某个相册 我认为需要修改的代码部分如下: /* * Source Tag: upload_photo You can upload a photo from the media * gallery or from a remote server How to upload photo: * https://developers.facebook.

我正在使用android教程hackbook中的代码,我已经能够将图片上传到我的墙上。我现在想要的是上传一张从我的相机拍摄的照片,然后上传到某个团体的某个相册

我认为需要修改的代码部分如下:

 /*
* Source Tag: upload_photo You can upload a photo from the media
* gallery or from a remote server How to upload photo:
* https://developers.facebook.com/blog/post/498/
*/
            case 3: {
                if (!Utility.mFacebook.isSessionValid()) {
                    Util.showAlert(this, "Warning", "You must first log in.");
                } else {
                    dialog = ProgressDialog.show(Hackbook.this, "",
                            getString(R.string.please_wait), true, true);
                    new AlertDialog.Builder(this)
                            .setTitle(R.string.gallery_remote_title)
                            .setMessage(R.string.gallery_remote_msg)
                            .setPositiveButton(R.string.gallery_button,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            Intent intent = new Intent(Intent.ACTION_PICK,
                                                    (MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
                                            startActivityForResult(intent,
                                                    PICK_EXISTING_PHOTO_RESULT_CODE);
                                        }

                                    })
                            .setNegativeButton(R.string.remote_button,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            /*
* Source tag: upload_photo_tag
*/
                                            Bundle params = new Bundle();
                                            params.putString("url",
                                                    "http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
                                            params.putString("caption",
                                                    "FbAPIs Sample App photo upload");
                                            Utility.mAsyncRunner.request("me/photos", params,
                                                    "POST", new PhotoUploadListener(), null);
                                        }

                                    }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                                @Override
                                public void onCancel(DialogInterface d) {
                                    dialog.dismiss();
                                }
                            }).show();
                }
                break;
            }
所以你能帮我吗 1) 可能吗?或者我必须先拍下这张照片,把它存放在某个地方,然后再找到它。我想避免这种情况(我的意思是从用户那里——如果可以通过编程实现,那么就没有问题了)。 2) 我需要更改哪些参数?

试试看-

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    this.imageView = (ImageView)this.findViewById(R.id.imageView1);
    Button photoButton = (Button) this.findViewById(R.id.button1);
    photoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
            startActivityForResult(cameraIntent, CAMERA_REQUEST); 
        }
    });
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_REQUEST) {  
        Bitmap bmp = intent.getExtras().get("data");
        ByteArrayOutputStream stream = new ByteArrayOutputStream();

        bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] byteArray = stream.toByteArray(); // convert camera photo to byte array
    }  
} 
你的facebook课程-

public void onClick(DialogInterface dialog, int which) {
     Bundle params = new Bundle();

     params.putByteArray("picture", <image in bytes>);
     params.putString("message", "Have fun");

     mAsyncRunner.request("me/photos", bundle, "POST", new SampleUploadListener());
}
public void onClick(DialogInterface dialog,int which){
Bundle params=新Bundle();
putByteArray参数(“图片”);
参数putString(“消息”,“玩得开心”);
request(“我/照片”,bundle,“POST”,newsampleuploadlistener());
}
试试看-

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    this.imageView = (ImageView)this.findViewById(R.id.imageView1);
    Button photoButton = (Button) this.findViewById(R.id.button1);
    photoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
            startActivityForResult(cameraIntent, CAMERA_REQUEST); 
        }
    });
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_REQUEST) {  
        Bitmap bmp = intent.getExtras().get("data");
        ByteArrayOutputStream stream = new ByteArrayOutputStream();

        bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] byteArray = stream.toByteArray(); // convert camera photo to byte array
    }  
} 
你的facebook课程-

public void onClick(DialogInterface dialog, int which) {
     Bundle params = new Bundle();

     params.putByteArray("picture", <image in bytes>);
     params.putString("message", "Have fun");

     mAsyncRunner.request("me/photos", bundle, "POST", new SampleUploadListener());
}
public void onClick(DialogInterface dialog,int which){
Bundle params=新Bundle();
putByteArray参数(“图片”);
参数putString(“消息”,“玩得开心”);
request(“我/照片”,bundle,“POST”,newsampleuploadlistener());
}
这是可能的。 在相机方面,你应该参考他们提供的信息,你可以知道如何临时存储数据并将图片上传到facebook。我使用了以下代码

private void upload_FB(Bitmap photo2) {
    // TODO Auto-generated method stub
    Calendar c = Calendar.getInstance();
    String name = c.getTime().toString()+" Vai vajadzētu iegādāties?";

    AsyncFacebookRunner fruner = new AsyncFacebookRunner(facebook);
    Log.d("adr", mCurrentPhotoPath);
    if(photo2!=null && mCurrentPhotoPath!=null){
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        photo2.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] bMapArray = baos.toByteArray();
        Bundle params = new Bundle();
        params.putByteArray("photo",bMapArray);
        params.putString("caption", name);
        params.putString("comments", ed1.getText().toString());
        fruner.request("me/photos",params,"POST",new PhotoUploadListener(),null);


    }
}
祝你好运:)

这是可能的。 在相机方面,你应该参考他们提供的信息,你可以知道如何临时存储数据并将图片上传到facebook。我使用了以下代码

private void upload_FB(Bitmap photo2) {
    // TODO Auto-generated method stub
    Calendar c = Calendar.getInstance();
    String name = c.getTime().toString()+" Vai vajadzētu iegādāties?";

    AsyncFacebookRunner fruner = new AsyncFacebookRunner(facebook);
    Log.d("adr", mCurrentPhotoPath);
    if(photo2!=null && mCurrentPhotoPath!=null){
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        photo2.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] bMapArray = baos.toByteArray();
        Bundle params = new Bundle();
        params.putByteArray("photo",bMapArray);
        params.putString("caption", name);
        params.putString("comments", ed1.getText().toString());
        fruner.request("me/photos",params,"POST",new PhotoUploadListener(),null);


    }
}
祝你好运:)