我正在开发一个应用程序。因为我试图在单击按钮时将我的应用程序信息共享为 Facebook 和 Twitter 的状态。
当我点击 twitter 按钮时,我想要分享的状态会自动被 twitted,但在 facebook 中,我无法在显示 facebook 分享状态窗口的空白文本框中分享我想要的信息。
我哪里错了请告诉我?
这是我的代码。
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) {
}
我正在为此使用 socialauth 库。