问题
I'm trying to open Facebook Messenger programmatically for specific user using his user ID.
Here's my code:
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext);
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
android.view.View dialogView = inflater.inflate(R.layout.dialog_right_swipe, null);
dialogBuilder.setView(dialogView);
TextView contactForBuyingTxt = dialogView.findViewById(R.id.contact_for_buying_txt);
contactForBuyingTxt.setText("Would you like to contact " + mProfile.getPosterName() + " for buying this product?");
dialogBuilder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb-messenger://user/"+mProfile.getPosterID()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
});
dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//pass
}
});
AlertDialog b = dialogBuilder.create();
b.show();
Here's Profile.java:
public class Profile {
public Profile() {
}
@SerializedName("imageUrl")
@Expose
private ArrayList<String> imageUrl;
@SerializedName("pDescription")
@Expose
private String pDescription;
@SerializedName("pUsedDuration")
@Expose
private String pUsedDuration;
@SerializedName("pPrice")
@Expose
private String pPrice;
@SerializedName("postedAt")
@Expose
private String postedAt;
@SerializedName("pName")
@Expose
private String pName;
@SerializedName("pImage")
@Expose
private String pImage;
@SerializedName("pID")
@Expose
private String pID;
@SerializedName("listingID")
@Expose
private String listingID;
public Profile(ArrayList<String> pImageUrl, String pDescription, String pDuration, String pPrice, String postedAt, String pName, String pUrl, String pID, String listingID) {
this.imageUrl = pImageUrl;
this.pDescription = pDescription;
this.pDuration = pDuration;
this.pPrice = pPrice;
this.postedAt = postedAt;
this.pName = pName;
this.pImage = pImageUrl;
this.pID = pID;
this.listingID = listingID;
}
public String getPDescription() {
return pDescription;
}
public void setPDescription(String pDescription) {
this.pDescription = pDescription;
}
public ArrayList<String> getImageUrl() {
return imageUrl;
}
public void setImageUrl(ArrayList<String> imageUrl) {
this.imageUrl = imageUrl;
}
public String getPDuration() {
return pDuration;
}
public void setPDuration(String pDuration) {
this.pDuration = pDuration;
}
public String getPPrice() {
return pPrice;
}
public void setPPrice(String pPrice) {
this.pPrice = pPrice;
}
public String getPostedAt() {
return postedAt;
}
public void setPostedAt(String postedAt) {
this.postedAt = postedAt;
}
public String getPName() {
return pName;
}
public void setPName(String pName) {
this.pName = pName;
}
public String getPImage() {
return pImage;
}
public void setPImage(String pImage) {
this.pImage = pImage;
}
public String getPID() {
return pID;
}
public void setPID(String pID) {
this.pID = pID;
}
public String getListingID() {
return listingID;
}
public void setListingID(String listingID) {
this.listingID = listingID;
}
}
Please consider this: There are different listings like things in which mProfile.getPosterName()
is the name of one who posted the listing and mProfile.getPosterId()
is his facebook id.
This is opening up the chat head but it is not opening it up for a specific user and rather the chat head shows 'Facebook User' as name.
AccessToken.getCurrentAccessToken().getUserId()
one look like this:
1493******22153
and findmyfbid.com one look like this:
1000******00783
Why is this happening and please let me know how can I open chat head for the specific user?
来源:https://stackoverflow.com/questions/46782419/facebook-messenger-chathead-is-not-opening-up-with-the-accesstoken-getcurrentac