Android - Share custom link via facebook

前端 未结 3 1149
没有蜡笔的小新
没有蜡笔的小新 2021-01-07 04:48

I need to share specific part in my app when user open it , if he download my app it navigate direct to this part (it may be nested fragment).

String AppURL          


        
相关标签:
3条回答
  • As mentioned by @Ragu Swaninathan, you can use ShareLinkContent from Facebook SDK.

    Now to achieve the redirection to the specific screen of the app, you can use Firebase dynamic link feature. You can generate dynamic links using Firebase SDK and then receive those links in the app to handle the navigation flow. You need to share these dynamic links along with the contents.

    0 讨论(0)
  • 2021-01-07 05:16

    In order to share the something in Facebook better go with latest Facebook SDK. It will make your task simpler. Because Android Intent has its own restrictions when we use share to facebook. Refer my answer below regarding this

    Share text via Intent on Facebook without using Facebook sdk

    The screenshot that you posted seems to have the sharing of link from the App.

    Here is how you will integrate the Facebook SDK to your project.

    Facebook SDK integration

    Then use the following code to share link on the facebook.

    ShareDialog shareDialog;
    FacebookSdk.sdkInitialize(Activity.this);
    shareDialog = new ShareDialog(act);
    ShareLinkContent linkContent = new ShareLinkContent.Builder()
                        .setContentTitle("title")
                        .setContentDescription(
                                "Description")
                        .setContentUrl(Uri.parse("your url")).build();
                shareDialog.show(linkContent);
    

    More sharing options from Facebook can be found here, which is pretty simple and straightforward.

    Happy coding..!!

    0 讨论(0)
  • 2021-01-07 05:23

    Try the following code:

    File mFileImagePath = " /storage/emulated/0/Image Editor/Media/FilterImages/Image_Editor_1547816365839.jpg  ";  // Just example you use file URL
    
    private void shareFacebook(File mFileImagePath) {
        String application = "com.facebook.katana";
        boolean installed = checkAppInstall(application);
        if (installed) {
            Intent mIntentShare = new Intent(Intent.ACTION_SEND);
            String mStrExtension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(mFileImagePath).toString());
            String mStrMimeType = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(mStrExtension);
            if (mStrExtension.equalsIgnoreCase("") || mStrMimeType == null) {
                // if there is no extension or there is no definite mimetype, still try to open the file
                mIntentShare.setType("text*//*");
            } else {
                mIntentShare.setType(mStrMimeType);
            }
            mIntentShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mFileImagePath));
            mIntentShare.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    
            mIntentShare.setPackage(application);
            startActivity(mIntentShare);
        } else {
    
            Toast.makeText(mContext, "Facebook have not been installed.", Toast.LENGTH_SHORT).show();
        }
    
    }
    
    private boolean checkAppInstall(String uri) {
        PackageManager pm = getPackageManager();
        try {
            pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
            return true;
        } catch (PackageManager.NameNotFoundException e) {
            //Error
        }
        return false;
    }
    

    This code works for me and will work on all Android devices.

    0 讨论(0)
提交回复
热议问题