3

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.

Pooja Roy
  • 545
  • 5
  • 25

2 Answers2

2

SocialAUth Android new version is working for facebook. The only thing is you need to use native facebook android login.

vineet
  • 269
  • 1
  • 4
  • 18
1

socialauth library uses old facebook sdk. dont use that. you can directly use intent filter to share on social networks.

[Updated one]

check this

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
 shareIntent.setType("image/png");
 shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"YOUR TEXT HERE");
 shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,"YOUR TEXT HERE");
 shareIntent.putExtra(android.content.Intent.EXTRA_STREAM,pngUri);
 PackageManager pm = getApplicationContext().getPackageManager();
 List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
    if ((app.activityInfo.name).contains("facebook")) {
        final ActivityInfo activity = app.activityInfo;
        final ComponentName name = new ComponentName(
                    activity.applicationInfo.packageName,
                    activity.name);
        shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                            | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        shareIntent.setComponent(name);
        startActivity(shareIntent);
            }
        }
    }
gandhi
  • 122
  • 6
  • @PoojaRoy You can download Facebook SDK 4.0 and run HelloSample, it contains this source code – BaDo Apr 05 '15 at 02:15