push notification not showing - android

I am implementing invite friends from my app using facebook.All the things working fine but when I am inviting friend then push notification not showing in my friend notification.but notification send by app successfully.
How to solve this problem.
public class Trail extends Activity {
private CallbackManager sCallbackManager;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trail);
openDialogInvite(this);
}
public void openDialogInvite(final Activity activity) {
String AppURl = "https://fb.me/Id number...."; //Generated from //fb developers
String previewImageUrl = "";
sCallbackManager = CallbackManager.Factory.create();
if (AppInviteDialog.canShow()) {
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(AppURl).setPreviewImageUrl(previewImageUrl)
.build();
AppInviteDialog appInviteDialog = new AppInviteDialog(activity);
appInviteDialog.registerCallback(sCallbackManager,
new FacebookCallback<AppInviteDialog.Result>() {
#Override
public void onSuccess(AppInviteDialog.Result result) {
Log.d("Invitation", "Invitation Sent Successfully");
finish();
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException e) {
Log.d("Invitation", "Error Occured");
}
});
appInviteDialog.show(content);
}
}
}

Related

how uber app get mobile number from facebook in android

How could uber android application get my mobile number while facebook login
I am using Facebook login in my android app and i want user mobile number from facebook but i am not getting it following is my android code
private void FbInitialise() {
loginButton = (LoginButton) findViewById(R.id.fb_login);
callbackManager = CallbackManager.Factory.create();
loginButton.setReadPermissions(Arrays.asList("public_profile", "email", "user_friends"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
graphRequest(loginResult.getAccessToken());
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
}
});
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
graphRequest(loginResult.getAccessToken());
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
}
});
}
public void graphRequest(AccessToken token) {
GraphRequest request = GraphRequest.newMeRequest(token, new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
LoginType="FB";
String firstName = "";
String lastName = "";
String stremail = "";
String strmobile = "";
if (object.has("first_name")) {
firstName = object.getString("first_name");
}
if (object.has("last_name")) {
lastName = object.getString("last_name");
}if (object.has("email")) {
stremail = object.getString("email");
}
Intent intent=new Intent(SelectSocilaLoginActivity.this,ConfirmInfoActivity.class);
intent.putExtra("firstName",firstName);
intent.putExtra("lastName",lastName);
intent.putExtra("email",stremail);
intent.putExtra("parent","SocialLogin");
startActivity(intent);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle b = new Bundle();
b.putString("fields", "id, first_name, last_name, email,gender, birthday, location");
request.setParameters(b);
request.executeAsync();
}
please give me proper solution
Here is how I managed to extract mobile number from the Login user's profile:
public class UserAuth extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.OnConnectionFailedListener {
private Context context;
private Button btnViewProfile;
//For User data
private String userId, userFirstName, userMiddleName, userLastName, userProfileImage, userEmail, userGender, userMobile, userBirthdate;
//For Facebook
private CallbackManager callbackManager;
LoginButton loginButton = null;
private ImageButton btnFacebook;
private AccessTokenTracker accessTokenTracker;
private ProfileTracker profileTracker;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* Enabling strict mode */
setStrictThreadMode();
//initializing facebook sdk
FacebookSdk.sdkInitialize(getApplicationContext());
//Initialize your view components available in the layout
accessTokenTracker = new AccessTokenTracker() {
#Override
protected void onCurrentAccessTokenChanged(AccessToken oldToken,
AccessToken newToken) {
}
};
profileTracker = new ProfileTracker() {
#Override
protected void onCurrentProfileChanged(Profile oldProfile,
Profile newProfile) {
if (newProfile != null) {
userId = newProfile.getId();
userFirstName = newProfile.getFirstName();
userMiddleName = newProfile.getMiddleName();
userLastName = newProfile.getLastName();
userProfileImage = newProfile.getProfilePictureUri(400, 400).toString();
}
}
};
accessTokenTracker.startTracking();
profileTracker.startTracking();
}
//To enable single thread at a time mode
private void setStrictThreadMode() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
protected void onStop() {
super.onStop();
accessTokenTracker.stopTracking();
profileTracker.stopTracking();
}
#Override
public void onResume() {
super.onResume();
Profile profile = Profile.getCurrentProfile();
}
//This method initializes the facebook login button, sets the required permissions and changes its default background to our drawable
//It also registers the callback for the Login button
private void registerLoginButton() {
List<String> mPermissions = new ArrayList<>();
mPermissions.add("public_profile");
mPermissions.add("email");
mPermissions.add("user_birthday");
mPermissions.add("user_friends");
mPermissions.add("user_mobile_phone");
loginButton.setReadPermissions(mPermissions);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult result) {
GraphRequest request = GraphRequest.newMeRequest(result.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
userEmail = object.optString("email");
userGender = object.optString("gender");
userMobile = object.optString("mobile_phone");
String userBirthdate = object.optString("birthday");
logoutCurrentUser();
} catch (Exception e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,birthday");
request.setParameters(parameters);
request.executeAsync();
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
}
});
}
//This method is to end the current users session
private void logoutCurrentUser() {
LoginManager.getInstance().logOut();
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
}
Observe we have added permission for fetching mobile number: mPermissions.add("user_mobile_phone");
Also, please remember that you will only get the mobile number if the user has made it public.
Hope this works for you.

Get tweets from user's timeline

I am trying to retrieve the text from every tweet of a user.
I don't send a get request.
I successfully connect with a tweeter account to my app with :
activity.client.authorize(activity, new Callback<TwitterSession>()
{
#Override
public void success(Result<TwitterSession> result)
{
Toast.makeText(getApplicationContext(), "Login worked", Toast.LENGTH_LONG).show();
writeInfile(result);
}
#Override
public void failure(TwitterException e)
{
Toast.makeText(getApplicationContext(), "Login failed", Toast.LENGTH_LONG).show();
}
});
With the result I can access informations from my user such as his id or his name.
I also have the UserTimeLine
final UserTimeline userTimeline = new UserTimeline.Builder()
.userId(result.data.getUserId())
.build();
How can I get his tweets or the id of his tweets from there ?
Thank you
I managed to do it by looking at every methods given by auto completion so if it can help anyone, here is how I did it :
void writeData(ContentResolver contentResolver)
{
activity.client.authorize(activity, new Callback<TwitterSession>()
{
#Override
public void success(Result<TwitterSession> result)
{
writeInfile(result);
}
#Override
public void failure(TwitterException e)
{
Log.e("Twitter Log in", e.toString());
}
});
}
void writeInFile(Result<TwitterSession> result)
{
userTimeline = new UserTimeline.Builder()
.userId(result.data.getUserId())
.includeRetweets(false)
.maxItemsPerRequest(200)
.build();
userTimeline.next(null, callback);
}
Callback<TimelineResult<Tweet>> callback = new Callback<TimelineResult<Tweet>>()
{
#Override
public void success(Result<TimelineResult<Tweet>> searchResult)
{
List<Tweet> tweets = searchResult.data.items;
for (Tweet tweet : tweets)
{
String str = tweet.text; //Here is the body
maxId = tweet.id;
}
if (searchResult.data.items.size() == 200)
userTimeline.previous(maxId, callback);
else
closeOutputFile();
}
#Override
public void failure(TwitterException error)
{
//Do something
}
};

How to Check Facebook invite app to friends is successfully sent invitation or not sent in android [duplicate]

In the new Fb SDK 4.0 for Android you can register a callback for the LoginButton according to the docs. https://developers.facebook.com/docs/facebook-login/android/v2.3
The question is is this possible for the AppInviteDialog as well? Or is there any other way to identify if the App-Invite was successful or not?
Yes, this is possible.
public static void openDialogInvite(final Activity activity)
{
String appLinkUrl, previewImageUrl;
appLinkUrl = "your app link url";
previewImageUrl = "https://www.example.com/my_invite_image.jpg";
if (AppInviteDialog.canShow())
{
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(appLinkUrl)
.setPreviewImageUrl(previewImageUrl)
.build();
AppInviteDialog appInviteDialog = new AppInviteDialog(activity);
CallbackManager sCallbackManager = CallbackManager.Factory.create();
appInviteDialog.registerCallback(sCallbackManager, new FacebookCallback<AppInviteDialog.Result>()
{
#Override
public void onSuccess(AppInviteDialog.Result result)
{
}
#Override
public void onCancel()
{
}
#Override
public void onError(FacebookException e)
{
}
});
appInviteDialog.show(content);
}
}

Invite Friends using Facebook Lite app Android

I have implemented the Facebook invite friend in my app. It is working fine when I have installed the Facebook Application in my device. But if I uninstall the Facebook app and Download the Facebook lite application then it is not working.
Here is my code snippet.
Please help me.
Thanks in advance.
public void openDialogInvite(final Activity activity) {
String AppURl = "**************"; //Generated from //fb developers
CallbackManager sCallbackManager = CallbackManager.Factory.create();
if (AppInviteDialog.canShow()) {
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(AppURl)
.build();
AppInviteDialog appInviteDialog = new AppInviteDialog(activity);
appInviteDialog.registerCallback(sCallbackManager,
new FacebookCallback<AppInviteDialog.Result>() {
#Override
public void onSuccess(AppInviteDialog.Result result) {
Log.d("Invitation", "Invitation Sent Successfully");
System.out.println("test onSuccess");
}
#Override
public void onCancel() {
System.out.println("test on cancel");
}
#Override
public void onError(FacebookException e) {
Log.d("Invitation", "Error Occured");
System.out.println("test Error" + e.getMessage());
}
});
appInviteDialog.show(content);
}
}

Getting user full name upon facebook login Android app

I am trying to add a facebook login to an android app. While the login button and logging in works fine, I am also trying to obtain the first and last name of the user when they log in. However, the String username always stays null. Below is the complete code of this activity:
public class FacebookLoginActivity extends BaseActivity {
private TextView info;
private LoginButton loginButton;
private CallbackManager callbackManager;
private String username;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.fb_login_activity);
info = (TextView) findViewById(R.id.info);
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("public_profile"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
setData();
if(username != null) {
Intent intent = new Intent(FacebookLoginActivity.this, LoginActivity.class);
Bundle bundle = new Bundle();
bundle.putString("username", username);
intent.putExtras(bundle);
startActivity(intent);
}
}
#Override
public void onCancel() {
info.setText("Login attempt canceled.");
}
#Override
public void onError(FacebookException error) {
info.setText("Login attempt failed.");
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
private void setData(){
if(AccessToken.getCurrentAccessToken() != null){
final GraphRequest request = GraphRequest.newMeRequest(
AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
if(AccessToken.getCurrentAccessToken()!=null){
try {
username = response.getJSONObject().getString("first_name")+ " " + response.getJSONObject().getString("last_name");
}
catch(JSONException e){
e.printStackTrace();
}
}
}
});
}
}
}

Categories

Resources