WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Twitter Integration Tutorial With Example In Android Studio


You can add application in twitter button and share anymore.


We need to Integrating Twitter SDK Create a new twitter application at dev.twitter.com/apps/new settings tab, change the access to read,write and access messages and save the settings
we need to generate oAuto SETTINGS
you will receive an consumer ID with the secret
Download twitter sdk here JAR into your project libs folder.

Posting tweets on twitter application

we need to add twitter 4J samples which can be found .here
then we can be done by calling the static method getsingleton()
// The factory instance is re-usable and thread safe.
Twitter twitter = TwitterFactory.getSingleton();

update stats massage
Status status = twitter.updateStatus(latestStatus);
System.out.println("Successfully updated the status to [" + status.getText() + "].");

Intent share

we can call the twitter application and pass the data to share . we have to specify the type of the share intent to ACTION_SEND
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
then type of data press
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello, from welookups");
startActivity(Intent.createChooser(shareIntent, "Share your thoughts"));

Example Twitter Integration Android

we can create the MainActivity.java.
package com.example.welookups .myapplication;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;

import android.widget.Button;
import android.widget.ImageView;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class MainActivity extends ActionBarActivity {
   private ImageView img;
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      img=(ImageView)findViewById(R.id.imageView);
      Button b1=(Button)findViewById(R.id.button);

      b1.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            Uri screenshotUri = Uri.parse("android.resource://comexample.welookups.myapplication/*");

            try {
               InputStream stream = getContentResolver().openInputStream(screenshotUri);
            } catch (FileNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }
               sharingIntent.setType("image/jpeg");
               sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
               startActivity(Intent.createChooser(sharingIntent, "Share image using"));
         }
      });
   }
}

then we need to create xml res/layout/activity_main.xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
   android:layout_height="match_parent" 
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

  <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/textView"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:textSize="30dp"
      android:text="Twitter share " />

   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Tutorials Point"
      android:id="@+id/textView2"
      android:layout_below="@+id/textView"
      android:layout_centerHorizontal="true"
      android:textSize="38dp"
      android:textColor="#ff0" />

  <ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/imageView"
      android:layout_below="@+id/textView2"
      android:layout_centerHorizontal="true"
      android:src="@drawable/abc"/>

  <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Share"
      android:id="@+id/button"
      android:layout_marginTop="61dp"
      android:layout_below="@+id/imageView"
      android:layout_centerHorizontal="true" />

</RelativeLayout>

then need to manifest AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.welookups.myapplication" >

 <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" >
      
     <activity
         android:name=".MainActivity"
         android:label="@string/app_name" >
         
     <intent-filter>
            
            
       </intent-filter>
         
    </activity>
      
  </application>
</manifest>