gpt4 book ai didi

android - 如何使用 Android 在 Facebook 中分享我们自己的静态状态

转载 作者:太空狗 更新时间:2023-10-29 12:42:34 25 4
gpt4 key购买 nike

我正在开发一个应用程序。因为我试图在单击按钮时将我的应用程序信息共享为 Facebook 和 Twitter 的状态。

我点击 Twitter 按钮时,我想要分享的状态会自动显示在 Twitter 上但是在 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 库。

最佳答案

SocialAUth Android新版本适用于 facebook。唯一的问题是你需要使用 native facebook android login .

关于android - 如何使用 Android 在 Facebook 中分享我们自己的静态状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23211634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com