Monday, November 17, 2014

Google plus Integration in android

Hi Friends Please Signed app from Google Developer console.



















































Then
follow these code and then u can get google+ login and share post on Google+ and user profile details .


Design    activity-main:-





code:-


<LinearLayout 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:orientation="vertical"
    android:padding="16dp"
    tools:context=".MainActivity" >

  <TextView
        android:id="@+id/txt"
        android:layout_width="300dp"
        android:gravity="center"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:text="Google Plus API"/>
   <Button
        android:id="@+id/sign_in_button"
        android:layout_width="300dp"
        android:layout_gravity="center"
        android:layout_height="wrap_content"
        android:text="Sign In to Google +"/>
   <Button
        android:id="@+id/post_button"
        android:layout_width="300dp"
        android:layout_gravity="center"
        android:text="Share on Google Plus"
        android:layout_height="wrap_content"/>
   <Button
        android:id="@+id/get_data_button"
        android:layout_width="300dp"
        android:layout_gravity="center"
        android:text="Get User Data"
        android:layout_height="wrap_content"/>
</LinearLayout>

Dialog Window for user details or profile display:-


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    
    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/post_name"
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:text="Name" />

        <TextView
            android:id="@+id/get_name"
            android:layout_width="150dp"
            android:layout_height="60dp" />
    </LinearLayout>

    
    
    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/post_id"
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:text="Profile ID" />

        <TextView
            android:id="@+id/get_id"
            android:layout_width="150dp"
            android:layout_height="60dp" />
    </LinearLayout>

    
    
    
    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/post_url"
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:text="Google Plus URL" />

        <TextView
            android:id="@+id/get_url"
            android:layout_width="150dp"
            android:layout_height="60dp" />
    </LinearLayout>

    
    
    
    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/postDateofBirth"
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:text="Age" />

        <TextView
            android:id="@+id/getDateofBirth"
            android:layout_width="150dp"
            android:layout_height="60dp" />
    </LinearLayout>

    
    
    
     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/postLocation"
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:text="Location" />

        <TextView
            android:id="@+id/getLocation"
            android:layout_width="150dp"
            android:layout_height="60dp" />
    </LinearLayout>
    
    
     
       <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/postGender"
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:text="Gender" />

        <TextView
            android:id="@+id/getGender"
            android:layout_width="150dp"
            android:layout_height="60dp" />
    </LinearLayout>
    
    
     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/postEmail"
            android:layout_width="150dp"
            android:layout_height="60dp"
            android:text="Email" />

        <TextView
            android:id="@+id/getEmail"
            android:layout_width="150dp"
            android:layout_height="60dp" />
    </LinearLayout>
    
    
    
    
    
    
    
    
    <Button
        android:id="@+id/ok_button"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:text="OK" />

</LinearLayout>





MainActivity.class:-



public class MainActivity extends Activity
implements
View.OnClickListener,
ConnectionCallbacks,
OnConnectionFailedListener,
com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks {
private static final String TAG = "MainActivity";
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
private ProgressDialog mConnectionProgressDialog;
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;
Button ShareButton, GetData, ok_btn;
Dialog get_data_dialog;
TextView name, url, id,dateofBirth,location,gender,email;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPlusClient = new PlusClient.Builder(this, this, this).setActions(
"http://schemas.google.com/AddActivity",
"http://schemas.google.com/BuyActivity").build();
setContentView(R.layout.activity_main);
// Progress bar to be displayed if the connection failure is not
// resolved.
mConnectionProgressDialog = new ProgressDialog(this);
mConnectionProgressDialog.setMessage("Signing in...");
findViewById(R.id.sign_in_button).setOnClickListener(this);
ShareButton = (Button) findViewById(R.id.post_button);
GetData = (Button) findViewById(R.id.get_data_button);

// location gender email
GetData.setOnClickListener(new View.OnClickListener() {
String disp_name, disp_url, disp_id,disp_DateofBirth,disp_location,disp_gender,disp_Email;

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (mPlusClient.isConnected()) {
get_data_dialog = new Dialog(MainActivity.this);
get_data_dialog.setContentView(R.layout.getdatafragment);
get_data_dialog.setTitle("User Details");
name = (TextView) get_data_dialog
.findViewById(R.id.get_name);
url = (TextView) get_data_dialog.findViewById(R.id.get_url);
id = (TextView) get_data_dialog.findViewById(R.id.get_id);
dateofBirth=(TextView)get_data_dialog.findViewById(R.id.getDateofBirth);
gender=(TextView)get_data_dialog.findViewById(R.id.getGender);
location=(TextView)get_data_dialog.findViewById(R.id.getLocation);
gender=(TextView)get_data_dialog.findViewById(R.id.getGender);
email=(TextView)get_data_dialog.findViewById(R.id.getEmail);
 
ok_btn = (Button) get_data_dialog
.findViewById(R.id.ok_button);
ok_btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
get_data_dialog.cancel();
}
});
Person currentPerson = mPlusClient.getCurrentPerson();
disp_name = currentPerson.getDisplayName();
disp_url = currentPerson.getUrl();
disp_id = currentPerson.getId();
disp_DateofBirth=currentPerson.getBirthday();
disp_location=currentPerson.getCurrentLocation();
 
/*
disp_gender=currentPerson.hasGender(); 
disp_Email=currentPerson.hasId(); */
 
name.setText(disp_name);
url.setText(disp_url);
id.setText(disp_id);
dateofBirth.setText(disp_DateofBirth);
location.setText(disp_location);
/* 
gender.setText(disp_gender); 
email.setText(disp_Email);*/
get_data_dialog.show();
} else {
Toast.makeText(getApplicationContext(), "Please Sign In",
Toast.LENGTH_LONG).show();
}
}
}); 
 
ShareButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Launch the Google+ share dialog with attribution to your app.
Intent shareIntent = new PlusShare.Builder(MainActivity.this)
.setType("text/plain")
.setText(
"Learn2Crack is a website for beginners to learn Android Programming")
.setContentUrl(Uri.parse("http://www.learn2crack.com"))
.getIntent();
startActivityForResult(shareIntent, 0);
}
});
}

@Override
protected void onStart() {
super.onStart();
mPlusClient.connect();
}

@Override
protected void onStop() {
super.onStop();
mPlusClient.disconnect();
}

@Override
public void onConnectionFailed(ConnectionResult result) {
if (mConnectionProgressDialog.isShowing()) {
// The user clicked the sign-in button already. Start to resolve
// connection errors. Wait until onConnected() to dismiss the
// connection dialog.
if (result.hasResolution()) {
try {
result.startResolutionForResult(this,
REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
}
// Save the result and resolve the connection failure upon a user click.
mConnectionResult = result;
}

@Override
protected void onActivityResult(int requestCode, int responseCode,
Intent intent) {
if (requestCode == REQUEST_CODE_RESOLVE_ERR
&& responseCode == RESULT_OK) {
mConnectionResult = null;
mPlusClient.connect();
}
}

@Override
public void onConnected(Bundle connectionHint) {
String accountName = mPlusClient.getAccountName();
Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG)
.show();
}

public void onDisconnected() {
Toast.makeText(this, " Disconnected.", Toast.LENGTH_LONG).show();
Log.d(TAG, "disconnected");
}

@Override
public void onClick(View view) {
if (view.getId() == R.id.sign_in_button && !mPlusClient.isConnected()) {
if (mConnectionResult == null) {
mConnectionProgressDialog.show();
} else {
try {
mConnectionResult.startResolutionForResult(this,
REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
// Try connecting again.
mConnectionResult = null;
mPlusClient.connect();
}
}
}
}

@Override
public void onConnectionSuspended(int arg0) {
// TODO Auto-generated method stub

}
}


manifest.xml file:-


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="in.amitsharma.glogin"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.NETWORK" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />

 
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" > 

        <activity
            android:name="in.amitsharma.glogin.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <meta-data
              android:name="com.google.android.gms.version"
              android:value="@integer/google_play_services_version" />
        
    </application> 
</manifest>







Thank you friends it may helpfull for you this is in details i have not added output just because of less time i have tested in my device 2.2.6 or 5.0 









error appcompat_v7 v21.0.1 in android Solution

Hi,
     friends i got same error then i solve this issue by following :-




after update these after that cleen all projects and remove all of apps from eclipse or change work space
after that Link his project and v7 to 4.4.2 from

Preporty>android>4.4.2>ok in both of them v7 or in project
and after that go to window then getprefrences>android>select4.4.2>ok

after that cleen project and then restart his eclipse Definatley your problem will solved i have checked by same way


get enjoyed ....Thank you ....

Thursday, November 13, 2014

integration with twitter or login with twitter in android

Hi friends it will help you more just i am going to add my code it will help u more :-


<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" >

    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp" android:onClick="onClickTwitt"
        android:text="        Twitt         " />

</RelativeLayout>







<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#d3d3d3" >

    <EditText
        android:id="@+id/twittext"
        android:layout_width="fill_parent"
        android:layout_height="110dp"
        android:layout_centerHorizontal="true"
        android:layout_margin="5dp"
        android:gravity="top"
        android:inputType="textMultiLine" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/btnpost"
        android:layout_width="150dp"
        android:layout_height="45dp"
        android:layout_below="@+id/twittext"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:background="#ff0f0f"
        android:text="   Twitt  "
        android:textColor="@android:color/white"
        android:textSize="17dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/invisibletext"
        android:layout_width="10dp"
        android:layout_height="10dp"
        android:layout_below="@+id/btnpost"
        android:layout_centerHorizontal="true"
        android:text="invisibletext"
        android:visibility="invisible" />

</RelativeLayout>




.class files are as below:-




public class MainActivity extends Activity {
public final String consumer_key =  "KJY9J7YxCjZ0your keys 2kOsaWMK";
public final String secret_key = "XnFgutp5jc0qIrzJrI1mW2mWb27Kyour secrate keys MJib02ygrUniy0M";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

public void onClickTwitt(View view) {
if (isNetworkAvailable()) {
Twitt twitt = new Twitt(MainActivity.this, consumer_key, secret_key);
twitt.shareToTwitter("http://samir-mangroliya.blogspot.in/");
} else {
showToast("No Network Connection Available !!!");
}
}

public boolean isNetworkAvailable() {
ConnectivityManager connectivity = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
private void showToast(String msg) {
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_LONG).show();

}
}





public class Twitt {

private TwitterApp mTwitter;
private Activity activity;
private String twitt_msg;

public Twitt(Activity act, String consumer_key, String consumer_secret) {
this.activity = act;
mTwitter = new TwitterApp(activity, consumer_key, consumer_secret);
}

public void shareToTwitter(String msg) {
this.twitt_msg = msg;
mTwitter.setListener(mTwLoginDialogListener);

if (mTwitter.hasAccessToken()) {
showTwittDialog();
} else {
mTwitter.authorize();
}
}

private void showTwittDialog() {

final Dialog dialog = new Dialog(activity);
dialog.setContentView(R.layout.twitt_dialog);
dialog.setTitle("Twitter");

Button btnPost = (Button) dialog.findViewById(R.id.btnpost);
final EditText et = (EditText) dialog.findViewById(R.id.twittext);
et.setText(twitt_msg);
et.setSelection(et.getText().length());
btnPost.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

twitt_msg = et.getText().toString().trim();

if (twitt_msg.length() == 0) {
showToast("Twitt is empty!!!");
return;
} else if (twitt_msg.length() > 140) {
showToast("Twitt is more than 140 characters not allowed!!!");
return;
}
dialog.dismiss();
new PostTwittTask().execute(twitt_msg);

}

});

dialog.show();

}

private TwDialogListener mTwLoginDialogListener = new TwDialogListener() {

public void onError(String value) {
showToast("Login Failed");
mTwitter.resetAccessToken();
}

public void onComplete(String value) {
showTwittDialog();
}
};

void showToast(final String msg) {
activity.runOnUiThread(new Runnable() {

@Override
public void run() {
Toast.makeText(activity, msg, Toast.LENGTH_SHORT).show();

}
});

}

class PostTwittTask extends AsyncTask<String, Void, String> {
ProgressDialog pDialog;

@Override
protected void onPreExecute() {
pDialog = new ProgressDialog(activity);
pDialog.setMessage("Posting Twitt...");
pDialog.setCancelable(false);
pDialog.show();
super.onPreExecute();
}

@Override
protected String doInBackground(String... twitt) {
try {
mTwitter.updateStatus(twitt[0]);
return "success";

} catch (Exception e) {
if (e.getMessage().toString().contains("duplicate")) {
return "Posting Failed because of Duplicate message...";
}
e.printStackTrace();
return "Posting Failed!!!";
}

}

@Override
protected void onPostExecute(String result) {
pDialog.dismiss();

if (null != result && result.equals("success")) {
showToast("Posted Successfully");

} else {
showToast(result);
}

super.onPostExecute(result);
}
}
}







public class TwitterApp {
private Twitter mTwitter;
private TwitterSession mSession;
private AccessToken mAccessToken;
private CommonsHttpOAuthConsumer mHttpOauthConsumer;
private OAuthProvider mHttpOauthprovider;
private String mConsumerKey;
private String mSecretKey;
private ProgressDialog mProgressDlg;
private TwDialogListener mListener;
private Activity context;

public static final String CALLBACK_URL = "twitterapp://connect";
private static final String TWITTER_ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token";
private static final String TWITTER_AUTHORZE_URL = "https://api.twitter.com/oauth/authorize";
private static final String TWITTER_REQUEST_URL = "https://api.twitter.com/oauth/request_token";

public TwitterApp(Activity context, String consumerKey, String secretKey) {
this.context = context;

mTwitter = new TwitterFactory().getInstance();
mSession = new TwitterSession(context);
mProgressDlg = new ProgressDialog(context);

mProgressDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);

mConsumerKey = consumerKey;
mSecretKey = secretKey;

mHttpOauthConsumer = new CommonsHttpOAuthConsumer(mConsumerKey,
mSecretKey);

String request_url = TWITTER_REQUEST_URL;
String access_token_url = TWITTER_ACCESS_TOKEN_URL;
String authorize_url = TWITTER_AUTHORZE_URL;

mHttpOauthprovider = new DefaultOAuthProvider(request_url,
access_token_url, authorize_url);
mAccessToken = mSession.getAccessToken();

configureToken();
}

public void setListener(TwDialogListener listener) {
mListener = listener;
}

private void configureToken() {
if (mAccessToken != null) {
mTwitter.setOAuthConsumer(mConsumerKey, mSecretKey);
mTwitter.setOAuthAccessToken(mAccessToken);
}
}

public boolean hasAccessToken() {
return (mAccessToken == null) ? false : true;
}

public void resetAccessToken() {
if (mAccessToken != null) {
mSession.resetAccessToken();

mAccessToken = null;
}
}

public String getUsername() {
return mSession.getUsername();
}

public void updateStatus(String status) throws Exception {
try {
mTwitter.updateStatus(status);
} catch (TwitterException e) {
throw e;
}
}

public void authorize() {
mProgressDlg.setMessage("Loading ...");
mProgressDlg.show();

new Thread() {
@Override
public void run() {
String authUrl = "";
int what = 1;

try {
authUrl = mHttpOauthprovider.retrieveRequestToken(
mHttpOauthConsumer, CALLBACK_URL);
what = 0;
} catch (Exception e) {
e.printStackTrace();
}
mHandler.sendMessage(mHandler
.obtainMessage(what, 1, 0, authUrl));
}
}.start();
}

public void processToken(String callbackUrl) {
mProgressDlg.setMessage("Finalizing ...");
mProgressDlg.show();

final String verifier = getVerifier(callbackUrl);

new Thread() {
@Override
public void run() {
int what = 1;

try {
mHttpOauthprovider.retrieveAccessToken(mHttpOauthConsumer,
verifier);

mAccessToken = new AccessToken(
mHttpOauthConsumer.getToken(),
mHttpOauthConsumer.getTokenSecret());

configureToken();

User user = mTwitter.verifyCredentials();

mSession.storeAccessToken(mAccessToken, user.getName());

what = 0;
} catch (Exception e) {
e.printStackTrace();
}

mHandler.sendMessage(mHandler.obtainMessage(what, 2, 0));
}
}.start();
}

private String getVerifier(String callbackUrl) {
String verifier = "";

try {
callbackUrl = callbackUrl.replace("twitterapp", "http");

URL url = new URL(callbackUrl);
String query = url.getQuery();

String array[] = query.split("&");

for (String parameter : array) {
String v[] = parameter.split("=");

if (URLDecoder.decode(v[0]).equals(
oauth.signpost.OAuth.OAUTH_VERIFIER)) {
verifier = URLDecoder.decode(v[1]);
break;
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
}

return verifier;
}

private void showLoginDialog(String url) {
final TwDialogListener listener = new TwDialogListener() {

public void onComplete(String value) {

processToken(value);

}

public void onError(String value) {
mListener.onError("Failed opening authorization page");
}
};

new TwitterDialog(context, url, listener).show();
}

@SuppressLint("HandlerLeak")
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
mProgressDlg.dismiss();

if (msg.what == 1) {
if (msg.arg1 == 1)
mListener.onError("Error getting request token");
else
mListener.onError("Error getting access token");
} else {
if (msg.arg1 == 1)
showLoginDialog((String) msg.obj);
else
mListener.onComplete("");
}
}
};

public interface TwDialogListener {
public void onComplete(String value);

public void onError(String value);
}
}





public class TwitterDialog extends Dialog {

static final float[] DIMENSIONS_LANDSCAPE = { 460, 260 };
static final float[] DIMENSIONS_PORTRAIT = { 280, 420 };
static final FrameLayout.LayoutParams FILL = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
static final int MARGIN = 4;
static final int PADDING = 2;
private String mUrl;
private TwDialogListener mListener;
private ProgressDialog mSpinner;
private WebView mWebView;
private LinearLayout mContent;
private TextView mTitle;
private boolean progressDialogRunning = false;

public TwitterDialog(Context context, String url, TwDialogListener listener) {
super(context);

mUrl = url;
mListener = listener;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSpinner = new ProgressDialog(getContext());

mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
mSpinner.setMessage("Loading...");

mContent = new LinearLayout(getContext());

mContent.setOrientation(LinearLayout.VERTICAL);

setUpTitle();
setUpWebView();

Display display = getWindow().getWindowManager().getDefaultDisplay();
final float scale = getContext().getResources().getDisplayMetrics().density;
float[] dimensions = (display.getWidth() < display.getHeight()) ? DIMENSIONS_PORTRAIT
: DIMENSIONS_LANDSCAPE;

addContentView(mContent, new FrameLayout.LayoutParams(
(int) (dimensions[0] * scale + 0.5f), (int) (dimensions[1]
* scale + 0.5f)));
}

private void setUpTitle() {
requestWindowFeature(Window.FEATURE_NO_TITLE);

Drawable icon = getContext().getResources().getDrawable(
R.drawable.twitter_icon);

mTitle = new TextView(getContext());

mTitle.setText("Twitter");
mTitle.setTextColor(Color.WHITE);
mTitle.setTypeface(Typeface.DEFAULT_BOLD);
mTitle.setBackgroundColor(0xFFbbd7e9);
mTitle.setPadding(MARGIN + PADDING, MARGIN, MARGIN, MARGIN);
mTitle.setCompoundDrawablePadding(MARGIN + PADDING);
mTitle.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);

mContent.addView(mTitle);
}

@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView() {
mWebView = new WebView(getContext());

mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
mWebView.setWebViewClient(new TwitterWebViewClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(mUrl);
mWebView.setLayoutParams(FILL);

mContent.addView(mWebView);
}

private class TwitterWebViewClient extends WebViewClient {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith(TwitterApp.CALLBACK_URL)) {
mListener.onComplete(url);

TwitterDialog.this.dismiss();

return true;
} else if (url.startsWith("authorize")) {
return false;
}
return true;
}

@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
mListener.onError(description);
TwitterDialog.this.dismiss();
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
mSpinner.show();
progressDialogRunning = true;
}

@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
String title = mWebView.getTitle();
if (title != null && title.length() > 0) {
mTitle.setText(title);
}
progressDialogRunning = false;
mSpinner.dismiss();
}

}

@Override
protected void onStop() {
progressDialogRunning = false;
super.onStop();
}

public void onBackPressed() {
if (!progressDialogRunning) {
TwitterDialog.this.dismiss();
}
}
}






public class TwitterSession {
private SharedPreferences sharedPref;
private Editor editor;

private static final String TWEET_AUTH_KEY = "auth_key";
private static final String TWEET_AUTH_SECRET_KEY = "auth_secret_key";
private static final String TWEET_USER_NAME = "user_name";
private static final String SHARED = "Twitter_Preferences";

public TwitterSession(Context context) {
sharedPref = context.getSharedPreferences(SHARED, Context.MODE_PRIVATE);

editor = sharedPref.edit();
}

public void storeAccessToken(AccessToken accessToken, String username) {
editor.putString(TWEET_AUTH_KEY, accessToken.getToken());
editor.putString(TWEET_AUTH_SECRET_KEY, accessToken.getTokenSecret());
editor.putString(TWEET_USER_NAME, username);

editor.commit();
}

public void resetAccessToken() {
editor.putString(TWEET_AUTH_KEY, null);
editor.putString(TWEET_AUTH_SECRET_KEY, null);
editor.putString(TWEET_USER_NAME, null);

editor.commit();
}

public String getUsername() {
return sharedPref.getString(TWEET_USER_NAME, "");
}

public AccessToken getAccessToken() {
String token = sharedPref.getString(TWEET_AUTH_KEY, null);
String tokenSecret = sharedPref.getString(TWEET_AUTH_SECRET_KEY, null);

if (token != null && tokenSecret != null)
return new AccessToken(token, tokenSecret);
else
return null;
}
}




manifest file are as below:-


        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />



hi friends it will help you more thanks.....