티스토리 뷰
페이스북 공유기하기
Dexx 2016. 6. 23. 01:55이번에 런칭한 앱에 욕심이 생겨 자꾸 기능을 추가하고 있다.
원래는 간단한 게시판 네이티브앱을 만드는 것이었는데 이것저것 추가하다 보니 이번엔 페이스북 공유기능을 추가하게 되었다.
제가 만든 앱이 궁금해요?! 궁금하면 설치해 주십쇼~ 굽신굽신~
https://play.google.com/store/apps/details?id=com.zzanfactory.interpoll
기존에 페이스북 로그인을 구현해 놓았기 때문에 크게 뭔가를 하지 않아도 가능하다.
일단 기초부터 정리하자면
1. build.gradle(app) 에 페이스북SDK를 추가한다.
1 2 3 4 5 6 7 | dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' .... compile 'com.facebook.android:facebook-android-sdk:4.10.1' .... } | cs |
2.manifests.xml에 provider추가
1 2 3 4 5 6 7 | <application ..... <provider android:authorities="com.facebook.app.FacebookContentProvider1669185xxxxxx" android:name="com.facebook.FacebookContentProvider" android:exported="true"/> ..... </application> | cs |
3.share코드 구현
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | CallbackManager callbackManager; ShareDialog shareDialog; Button btnFacebook; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FacebookSdk.sdkInitialize(getApplicationContext()); //페이스북SDK 초기화 callbackManager = CallbackManager.Factory.create(); //콜백메소드 생성 shareDialog = new ShareDialog(this); //공유를 위한 다이얼로그 박스 btnFacebook = (Button) view.findViewById(R.id.btnFacebook); btnFacebook.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (ShareDialog.canShow(ShareLinkContent.class)) { ShareLinkContent linkContent = new ShareLinkContent.Builder() .setContentTitle("공유할 콘텐츠의 타이틀") .setContentDescription("공유할 콘텐츠의 내용") .setImageUrl(Uri.parse("공유할 콘텐츠의 이미지 Url")) .setContentUrl(Uri.parse("공유할 웹사이트 주소")) .build(); shareDialog.show(linkContent); } } }); } build.gradle | cs |
그 외에 Bitmap 또는 비디오 공유도 가능하다. 관련 내용은
https://www.numetriclabz.com/share-on-facebook-through-android-app-tutorial/
'Android 개발 메모' 카테고리의 다른 글
현재 메모리와 토탈 메모리 확인하기 (0) | 2016.06.24 |
---|---|
Background 상태에서 Foregound상태 전환 시 앱 새로 시작하기 (0) | 2016.06.15 |
구글 애널리틱스 적용하기 (0) | 2016.06.02 |
댓글