Monday, 4 September 2017

Share Anything on Social Media Like Facebook | Twitter | Google+

About Example:- Here is the example that "How to Post any thing on Social Media  in Android Application By using Coding"

Basic Requirement:-
1. MainActivity.java
2. activity_main.xml

NOTE:- Make sure that your device should have Facebook App

Steps are:-
Step 1: Add a new project and open activity_main.xml and write following code:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
xmlns:app="http://schemas.android.com/apk/res-auto"   
 xmlns:tools="http://schemas.android.com/tools"    
android:layout_width="match_parent"    
android:layout_height="match_parent"    
android:background="#33B8FF"    
android:orientation="vertical"    
android:gravity="center"    
tools:context="com.example.supriyabharti.launchgooglemapexmp.MainActivity">

    
    <Button        
android:id="@+id/btn_share_fb"       
 android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="Share on Facebook"        
android:padding="5dp"
        android:textColor="#fff" />

</LinearLayout>

Step 2:- Open MainActivity.java and write following code:-
package com.example.supriyabharti.launchgooglemapexmp;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    Button btnFb;
    String uriString;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        btnFb=(Button)findViewById(R.id.btn_share_fb);
        

        //sharing on Facebook code start...        
btnFb.setOnClickListener(new View.OnClickListener() {
            @Override            
public void onClick(View view) {


                Intent share=new Intent(Intent.ACTION_SEND);
                share.setType("text/plain");
                uriString="http://www.opencv-tutorial-codes.blogspot.in";
                share.putExtra(Intent.EXTRA_TEXT, uriString);
                share.setPackage("com.facebook.katana"); //Facebook App package
              // share.setPackage("advanced.twitter.android");//Twitter App package    
 // share.setPackage("com.whatsapp");//WhatsApp App package
//share.setPackage("com.android.apps.plus");//Google+ App package
startActivity(Intent.createChooser(share, "Title of the dialog the system will open")); } }); } }
Step 3:- Open Manifeste  file and take INTERNET user permission :-

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
 Note :- As like facebook u can also open Other Social media like:-



No comments:

Post a Comment