Facebook에 사진 공유 (Share a Photo To Facebook)


문제 설명

Facebook에 사진 공유 (Share a Photo To Facebook)

활동 2에 활동이 2개 있습니다. 사용자는 활동에서 사진을 찍거나 사진을 선택할 수 있고 사진에 텍스트를 쓸 수 있고 활동 하나는 텍스트와 함께 사진을 표시하지만 문제는 저장할 수 없다는 것입니다. 텍스트가 있는 그림과 Facebook에서 공유할 수 없습니다. 누구든지 저를 도와주세요. 코드는 다음과 같습니다.

@Override 
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    //Teksti qe tregon qe kliko ne te per te kalu ne aktivitetin tjeter "Toast"
    Toast.makeText(getApplicationContext(), "Press The Photo For Customize", Toast.LENGTH_LONG).show();

    //Merr intentin
    Intent intent = getIntent();

    //Vendos tekstin emrin se kush e ka ditelindjen
    String message = intent.getStringExtra(MESSAGE_KEY);
    TextView textView = (TextView) findViewById(R.id.nameChange);
    textView.setText(message);

    // Vendos tekstin From
    String message1 = intent.getStringExtra(MESSAGE_KEY1);
    TextView textView1 = (TextView) findViewById(R.id.FromName);
    textView1.setText(message1);

    // Vendos Foton
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        return;
    }
    int res = extras.getInt("resourseInt");
    ImageView view = (ImageView) findViewById(R.id.cakeView);

    view.setImageResource(res);

    //vendos foton qe vjen nga galeria
    File picture = (File) getIntent().getExtras().get("image_path");
    if (picture != null) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 3;

        Bitmap bitmap = BitmapFactory.decodeFile(String.valueOf(picture), options);

        try {
            // Jepja orientimin
            ExifInterface exif = new ExifInterface(String.valueOf(picture));
            int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

            // Determine Rotation
            int rotation = 0;
            if (orientation == 6) rotation = 90;
            else if (orientation == 3) rotation = 180;
            else if (orientation == 8) rotation = 270;

            // ktheje nqs eshte e detyrueshme
            if (rotation != 0) {
                // Create Matrix
                Matrix matrix = new Matrix();
                matrix.postRotate(rotation);

                // Rotate Bitmap
                Bitmap rotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

                // Pretend none of this ever happened!
                bitmap.recycle();
                bitmap = rotated;
                rotated = null;
            }
        } catch (Exception e) {

        }
        view.setImageBitmap(bitmap);
    }
    // ATTENTION: This was auto‑generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
}

//krijimi i menus share
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.my_menu, menu);
    return true;
}

// kur klienti klikon ne butonin qe ndodhet tek menuja
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    //per menun qe te dallojm kur dikush klikon ne te ti ndajm zakonisht kur jan me shum se 1
    if (id == R.id.id_share) {
        registerForContextMenu(findViewById(R.id.id_share));
        openContextMenu(findViewById(R.id.id_share));
    }
    return true;
}

//konteksi qe fut listen qe deshiron tek butoni share
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.item_contect, menu);
}

//i ben share fotos per ne facebook
private void sharePhotoToFacebook() {

    ImageView test = (ImageView) findViewById(R.id.cakeView);

        Bitmap image = BitmapFactory.decodeFile(String.valueOf(test));
        SharePhoto photo = new SharePhoto.Builder()
                .setBitmap(image)
                .build();
        SharePhotoContent content = new SharePhotoContent.Builder()
                .addPhoto(photo)
                .build();

        ShareApi.share(content, null);
}

// kjo eshte nje pjese e facebook sdk
@Override
protected void onActivityResult(int requestCode, int responseCode, Intent data) {
    super.onActivityResult(requestCode, responseCode, data);
    callbackManager.onActivityResult(requestCode, responseCode, data);
}

@Override
public boolean onContextItemSelected(MenuItem item) {

    int id = item.getItemId();

    if (id == R.id.facebook) {
        FacebookSdk.sdkInitialize(getApplicationContext());

        callbackManager = CallbackManager.Factory.create();

        List<String> permissionNeeds = Arrays.asList("publish_actions");

        //kjo te ndihmon qe te mos kete nevoj klienti te kyqet
        loginManager = LoginManager.getInstance();

        loginManager.logInWithPublishPermissions(this, permissionNeeds);
        loginManager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                sharePhotoToFacebook();
                Toast.makeText(getApplicationContext(), "The Photo Is Now Share On Facebook", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onCancel() {
                System.out.println("onCancel");
            }

            @Override
            public void onError(FacebookException error) {
                System.out.println("onError");
            }
        });

        if (id == R.id.instagram) {

        }
    }
    return true;
}

//Kliko ne Foto Onclick
public void clickPhoto(View view) {
    Intent intent = new Intent(this, SecondActivity.class);
    startActivity(intent);
}

참조 솔루션

방법 1:

Now photo share is much simple than the previous. Please follow the latest facebook share Facebook Share

** ShareLinkContent sh = new ShareLinkContent.Builder()
                    .setContentUrl(Uri.parse(mImageUrl))
                    .setContentTitle(mPostingMessage)
                    .setImageUrl(Uri.parse(mImageUrl)).build();**

(by Fation JoniNivedh)

참조 문서

  1. Share a Photo To Facebook (CC BY‑SA 2.5/3.0/4.0)

#facebook #Android






관련 질문

cocos2d-x Facebook 통합(집중된 보기 때문에 초점이 있는 보기를 저장할 수 없음) (cocos2d-x Facebook integration (couldn't save which view has focus because the focused view))

썸네일이 있는 Facebook 공유 웹사이트 문제 (Facebook sharing website issue with thumbnail)

정의되지 않은 omniauth_authorize_path 메서드 오류 (Undefined omniauth_authorize_path method Error)

Facebook은 드래그하여 이미지를 닫는 데 어떤 라이브러리를 사용합니까? (What library does Facebook use for dismiss image by dragging?)

모든 애플리케이션에 대한 Android 앱에서 데이터 공유 (Share Data in android app for all applications)

Facebook에 사진 공유 (Share a Photo To Facebook)

Android Facebook API, 친구 목록을 얻는 방법? API 버전이 v2.5인데도 Retuning Data가 null (Android Facebook API, How to get friend list?Retuning Data is null, Even though API version is v2.5)

Facebook 오류 #100: 사진 URL이 제공된 경우 링크를 제공해야 합니다. (Facebook Error #100 : A link must be provided if a picture URL is given)

Facebook Graph API에 사용할 Django 라이브러리는 무엇입니까? (Which Django library to use for Facebook Graph API?)

Facebook "좋아요" 버튼 URL에서 일본어(비라틴어) URL 전달 실패 (Passing Japanese (non-Latin) URLs in Facebook "like" button URL fails)

Facebook iOS SDK를 사용하는 동안 PhoneGap 및 SBJSON 중복 충돌 (PhoneGap and SBJSON duplicate conflict while using Facebook iOS SDK)

Facebook 댓글 소셜 플러그인에 댓글을 추가할 수 있는 API가 있습니까? (Does the Facebook Comments Social Plugin have an API where comments can be added?)







코멘트