Share content using Intent to Facebook Lite Android

拥有回忆 提交于 2021-01-29 08:01:03

问题


Am using the following code for sharing the content directly to facebook app,

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent
                .putExtra(
                        android.content.Intent.EXTRA_TEXT,
                        "Some text");
        PackageManager pm = v.getContext().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);
                v.getContext().startActivity(shareIntent);
                break;
            }
        }

it is working perfectly for facebook app, but facing issues with facebook lite app. For user who installed facebook-lite not able to share the content, It simply display the splash screen of fb-lite app. Please help me out.


回答1:


You acheive this by setting the package name in the intent.

It will look for the specified app, If present it will open the app. other wise it will show the error message that there is no app can perform this action. Try the approach for sharing using the Android default intent.

// Using Facebook App

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Example text"); 
intent.setPackage("com.facebook.katana");      
activity.startActivity(intent);

// Using Facebook Lite App

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Example text"); 
intent.setPackage("com.facebook.lite");      
activity.startActivity(intent);

Let me know how it goes...

NOTE : Facebook share will work fine at its best when using the Facebook SDK (use version greater than 4.X - recommended )




回答2:


  Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, activity.getString(R.string.share_subject));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Example text");    

activity.startActivity(Intent.createChooser(shareIntent, activity.getString(R.string.share_title)));


来源:https://stackoverflow.com/questions/32695114/share-content-using-intent-to-facebook-lite-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!