I am developing an application. In that I am trying to share information of my application as a Status of Facebook and Twitter when button is clicked.
When I click on twitter button the status as I want to share is twitted automatically but In facebook I cant share info as I want in show blank textbox of facebook share status window.
Where I am wrong please tell me ?
This is my code.
final String msg="Hie - " +
"Message to share";
@Override
protected void onCreate(Bundle savedInstanceState)
{
.....................
.....................
static SocialAuthAdapter adapter;
adapter = new SocialAuthAdapter(new ResponseListener());
try
{
adapter.addConfig(Provider.TWITTER, "key", "BsiY4LH5Y4naSmb.............",null);
}
catch (Exception e)
{
e.printStackTrace();
}
imgtellfriend.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
anim = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.sequence);
imgtellfriend.startAnimation(anim);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, msg);
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
});
imgFb.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
anim = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.sequence);
imgFb.startAnimation(anim);
adapter.authorize(Catagories.this, Provider.FACEBOOK);
initShareIntent("com.facebook.katana");
}
});
imgtwiter.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
anim = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.sequence);
imgtwiter.startAnimation(anim);
adapter.authorize(Catagories.this, Provider.TWITTER);
}
});
}
private final class ResponseListener implements DialogListener
{
@Override
public void onComplete(Bundle values)
{
Log.d("Share-Bar", "Authentication Successful");
final String providerName = values.getString(SocialAuthAdapter.PROVIDER);
Log.d("Share-Bar", "Provider Name = " + providerName);
Toast.makeText(Catagories.this, providerName + " connected", Toast.LENGTH_SHORT).show();
adapter.updateStatus(msg, new MessageListener(), true);
}
@Override
public void onCancel()
{
Log.d("Share-Bar", "Authentication Cancelled");
}
@Override
public void onBack()
{
Log.d("Share-Bar", "Dialog Closed by pressing Back Key");
}
@Override
public void onError(SocialAuthError error)
{
initShareIntent("com.facebook.katana");
error.printStackTrace();
Log.d("Share-Bar 1", error.toString());
Log.d("Share-Bar 2", error.getMessage());
}
}
@SuppressLint("DefaultLocale")
private void initShareIntent(String type)
{
boolean found = false;
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
// gets the list of intents that can be loaded.
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty()){
for (ResolveInfo info : resInfo) {
Log.d("MEssage FB","--------- App :: "+info.activityInfo.packageName.toLowerCase());
if (info.activityInfo.packageName.toLowerCase().contains(type) ||
info.activityInfo.name.toLowerCase().contains(type) )
{
share.putExtra(Intent.EXTRA_SUBJECT, "ECard");
share.putExtra(Intent.EXTRA_TEXT, msg);
share.setPackage(info.activityInfo.packageName);
found = true;
break;
}
}
if (!found)
return;
startActivity(Intent.createChooser(share, "Select"));
}
}
private class MessageListener implements SocialAuthListener<Integer>
{
@Override
public void onExecute(String provider, Integer t)
{
Integer status = t;
if (status.intValue() == 200 || status.intValue() == 201 || status.intValue() == 204)
Toast.makeText(Catagories.this, "Message posted on " + provider, Toast.LENGTH_LONG).show();
else
Toast.makeText(Catagories.this, "Message not posted on " + provider, Toast.LENGTH_LONG).show();
}
@Override
public void onError(SocialAuthError e) {
}
I am using socialauth library for that.