I'm using Nexmo Verify SDK to verify the phone number of the user. I am able to get the pin to the given phone number but when i enter the correct pin code and call checkPinCode method i get INVALID_CREDENTIALS error. This is the implementation.
//This is how i collected the phone number
final String phone = phoneNumber.getText().toString();
verifyClient.getVerifiedUser("LK",phone );
//This is how i collected the pin number
final String pin = pinNumberEditText.getText().toString();
verifyClient.checkPinCode(pin);
verifyClient.addVerifyListener(new VerifyClientListener() {
#Override
public void onVerifyInProgress(VerifyClient verifyClient, UserObject user) {
Toast.makeText(MainActivity.this, "Verifying", Toast.LENGTH_LONG).show();
}
#Override
public void onUserVerified(VerifyClient verifyClient, UserObject user) {
Toast.makeText(MainActivity.this, "Successfully Verified", Toast.LENGTH_LONG).show();
}
#Override
public void onError(VerifyClient verifyClient, com.nexmo.sdk.verify.event.VerifyError errorCode, UserObject user) {
Toast.makeText(MainActivity.this, "Error"+errorCode+user.getPhoneNumber(), Toast.LENGTH_LONG).show();
}
#Override
public void onException(IOException exception) {
Toast.makeText(MainActivity.this, "Exception", Toast.LENGTH_LONG).show();
}
});
Help much appreciated.
Thanks in advance
Related
I have a problem here. I want to know whether the user has verified the email or not. If the user has verified the email by clicking on the link given, the application should automatically go to the homeScreen. Or else, the user may remain on the same page.
Below is a part of my code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_email_verification);
emailVerify = findViewById(R.id.emailVerify);
final FirebaseUser user = auth.getCurrentUser();
Intent intent = getIntent();
name = intent.getStringExtra("name");
email = intent.getStringExtra("email");
password = intent.getStringExtra("password");
emailVerify.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
user.sendEmailVerification().addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
storeNewUsersData();
Toast.makeText(v.getContext(), "Verification email has been sent.", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.d(TAG, "onFailure: Email not sent " + e.getMessage());
}
});
//check whether the user has verified the email and go to homeScreen
}
});
}
Try this:
public void verifyEmail() {
if (firebaseAuth.getCurrentUser().isEmailVerified()) { //FirbaseUser must not be null!
Toast.makeText(view.getContext(), "Email has been verified.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(view.getContext(), "Email has not been verified.", Toast.LENGTH_SHORT).show();
}
}
https://www.youtube.com/watch?v=Wf7DDIaRYjk This tutorial maybe helpful I implemented mine from this.
full error message is :
The webpage at https://merchant.com/callback could not be loaded because : net::ERR_CONNECTION_TIME_OUT
my code for initiate paytm and get same error in app invocation :
private void startPayTMCall(InitiateAPIResponse apiResponse, PaytmInitRequestBody paytmInitRequestBody) {
String orderIdString = paytmInitRequestBody.getOrderId();
String MID = getString(R.string.MID);
String amount = String.valueOf(paytmInitRequestBody.getAmount());
/*
On completion of transaction, Paytm payment gateway will send the response on this URL. This can be a static response URL as mentioned below:
Staging Environment: "https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=<order_id>"
Production Environment: "https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=<order_id>"*/
// for test mode use it
// String host = "https://securegw-stage.paytm.in/";
// for production mode use it
String host = "https://securegw.paytm.in/";
String callBackUrl = host + "theia/paytmCallback?ORDER_ID=" + orderIdString;
PaytmOrder order = new PaytmOrder(orderIdString, MID, apiResponse.getBody().getTxnToken(), amount, callBackUrl);
TransactionManager transactionManager = new TransactionManager(order, new PaytmPaymentTransactionCallback() {
#Override
public void onTransactionResponse(Bundle bundle) {
Toast.makeText(getApplicationContext(), "Payment Transaction response " + bundle.toString(), Toast.LENGTH_LONG).show();
}
#Override
public void networkNotAvailable() {
Toast.makeText(MainActivity.this, "networkNotAvailable", Toast.LENGTH_SHORT).show();
}
#Override
public void onErrorProceed(String s) {
Toast.makeText(MainActivity.this, "onErrorProceed "+s, Toast.LENGTH_SHORT).show();
}
#Override
public void clientAuthenticationFailed(String s) {
Toast.makeText(MainActivity.this, "clientAuthenticationFailed : "+s, Toast.LENGTH_SHORT).show();
}
#Override
public void someUIErrorOccurred(String s) {
Toast.makeText(MainActivity.this, "someUIErrorOccurred : "+s, Toast.LENGTH_SHORT).show();
}
#Override
public void onErrorLoadingWebPage(int i, String s, String s1) {
Toast.makeText(MainActivity.this, "onErrorLoadingWebPage : "+s+" : "+s1, Toast.LENGTH_SHORT).show();
}
#Override
public void onBackPressedCancelTransaction() {
Toast.makeText(MainActivity.this, "onBackPressedCancelTransaction : ", Toast.LENGTH_SHORT).show();
}
#Override
public void onTransactionCancel(String s, Bundle bundle) {
Toast.makeText(MainActivity.this, "onTransactionCancel : "+s, Toast.LENGTH_SHORT).show();
}
});
transactionManager.setAppInvokeEnabled(false);
transactionManager.setEnableAssist(true);
transactionManager.startTransaction(this, REQ_CODE_ORDER);
}
i think there is problem in callback url tht could be worng, but i follow paytm official All in one SDK documentation. https://developer.paytm.com/docs/all-in-one-sdk/
Kindly use Paytm Static Callback URL in 'callbackUrl' request param of 'Initiate Transaction API'. The URL mentioned (merchant.com/callback) is just an example, either you can use your customised call back url or use below mentioned call back URL.
Paytm Static Callback URL ->
Staging: https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=<order_id>
Production: https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=<order_id>
So I have been trying to solve this problem but I can't seem to know what's wrong. I have a button that when clicked calls PhoneAuthProvider which has 4 options: OnVerifiicationCompleted, OnVerificationFailed, OnCodeSent, and onCodeAutoRetrieval. The problem is that oncodesent is being called but the code that I put in there doesn't work, not even a debug log. All I get is an SMS message showing a verification code. And when I set a string value to onCodeSent's verificationID, the string is value: null. Here's my code:
sendLink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
popSound.start();
if (greenCheck.getVisibility() == View.VISIBLE) {
//send link
// we will finish this activity and send the link to the number
// an option to resend code to the number: it will be provided at the link
// in this format: resend code to (XXX)-XxX-XXXX
String number = phoneNumber.getText().toString();
phoneNumber.setText("");
sendLink.setEnabled(false);
PhoneAuthProvider.getInstance().verifyPhoneNumber(
number,
60,
TimeUnit.SECONDS,
MobileNumberActivity.this,
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
signInWithPhoneAuthCredential(phoneAuthCredential);
}
#Override
public void onVerificationFailed(FirebaseException e) {
}
#Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
// verificationID never gets assigned s and it is null. log.d isn't on logcat
verificationID = s;
Log.d("testing", "onCodeSent: " + verificationID);
}
#Override
public void onCodeAutoRetrievalTimeOut(String s) {
super.onCodeAutoRetrievalTimeOut(s);
}
}
);
Intent i = new Intent(MobileNumberActivity.this, VerificationActivity.class);
startActivity(i);
finish();
} else if (phoneNumber.getText().toString().length() == 0) {
Toast.makeText(MobileNumberActivity.this, "Please enter a phone number", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MobileNumberActivity.this, "Please enter a valid phone number", Toast.LENGTH_SHORT).show();
}
}
});
Finally found the answer after trial and error. I don't know quite why this works but my guess is because since I am creating an instance of PhoneAuthProvider, it only works in oncreate. I had mine in oncreate but it was surrounded by a setOnClickListener as you see in the code above. So what worked for me is to start an intent to direct it to my verification activity, which in its oncreate method I created an instance of PhoneAuthProvider just by itself and it worked.
First activity:
sendLink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
popSound.start();
if (greenCheck.getVisibility() == View.VISIBLE) {
//send link
number = phoneNumber.getText().toString();
phoneNumber.setText("");
sendLink.setEnabled(false);
Intent i = new Intent(MobileNumberActivity.this, VerificationActivity.class);
startActivity(i);
finish();
} else if (phoneNumber.getText().toString().length() == 0) {
Toast.makeText(MobileNumberActivity.this, "Please enter a phone number", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MobileNumberActivity.this, "Please enter a valid phone number", Toast.LENGTH_SHORT).show();
}
}
});
Second activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_verification);
mAuth = FirebaseAuth.getInstance();
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
// This callback will be invoked in two situations:
// 1 - Instant verification. In some cases the phone number can be instantly
// verified without needing to send or enter a verification code.
// 2 - Auto-retrieval. On some devices Google Play services can automatically
// detect the incoming verification SMS and perform verification without
// user action.
Log.d("COmpleted", "onVerificationCompleted:" + credential);
signInWithPhoneAuthCredential(credential);
}
#Override
public void onVerificationFailed(FirebaseException e) {
// This callback is invoked in an invalid request for verification is made,
// for instance if the the phone number format is not valid.
Log.w("failed", "onVerificationFailed", e);
if (e instanceof FirebaseAuthInvalidCredentialsException) {
// Invalid request
// ...
} else if (e instanceof FirebaseTooManyRequestsException) {
// The SMS quota for the project has been exceeded
// ...
}
// Show a message and update the UI
// ...
}
#Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
// The SMS verification code has been sent to the provided phone number, we
// now need to ask the user to enter the code and then construct a credential
// by combining the code with a verification ID.
Log.d("codesent", "onCodeSent:" + verificationId);
// Save verification ID and resending token so we can use them later
mVerificationID = verificationId;
mResendToken = token;
// ...
}
};
PhoneAuthProvider.getInstance().verifyPhoneNumber(
MobileNumberActivity.number, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks);
}
I am new to Android App development. I want to retrieve user's score from Google Play Game service and i am using following code to get the high score but i do not have any knowledge how it returns the value and how to save it.
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(getApiClient(), getString(R.string.highscore), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC);
Saving it to int or string does not worked.
The complete parameters for loadCurrentPlayerLeaderboardScore is like below
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(getApiClient(),
getString(R.string.word_attack_leaderboard),
LeaderboardVariant.TIME_SPAN_ALL_TIME,
LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(
new ResultCallback<LoadPlayerScoreResult>() {
#Override
public void onResult(LoadPlayerScoreResult arg0) {
LeaderboardScore c = arg0.getScore();
long score = c.getRawScore();
}
}
R.string.word_attack_leaderboard is leaderboards id which get from google play game service
The method:
loadCurrentPlayerLeaderboardScore (GoogleApiClient apiClient, String leaderboardId, int span, int leaderboardCollection)
returns
PendingResult<Leaderboards.LoadPlayerScoreResult>
Then you must use the getScore() method of the Leaderboards.LoadPlayerScoreResult class to get it.
Please see these links...
The loadCurrentPlayerLeaderboardScore method
The LoadPlayerScoreResult in the PendingResult
EDIT: Here's how you can use it.
Games.Leaderboards.loadCurrentPlayerLeaderboardScore().setResultCallback(new ResultCallback<LoadPlayerScoreResult>() {
#Override
public void onResult(LoadPlayerScoreResult arg0) {
LeaderboardScore c = arg0.getScore();
}
});
This is how you get the score.
4 years later I was having a similar problem with this situation. Some stuff has been deprecated and stuff no longer works. So for those of you who want to know how to do it now, in 2018... check this answer-
First you have to get the LeaderBoardClient with
mLeaderboardsClient = Games.getLeaderboardsClient(MainActivity.this, googleSignInAccount);
Next you can the score
mLeaderboardsClient.loadCurrentPlayerLeaderboardScore(getString(R.string.leaderboard_id), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC)
.addOnSuccessListener(this, new OnSuccessListener<AnnotatedData<LeaderboardScore>>() {
#Override
public void onSuccess(AnnotatedData<LeaderboardScore> leaderboardScoreAnnotatedData) {
long score = 0L;
if (leaderboardScoreAnnotatedData != null) {
if (leaderboardScoreAnnotatedData.get() != null) {
score = leaderboardScoreAnnotatedData.get().getRawScore();
Toast.makeText(MainActivity.this, Long.toString(score), Toast.LENGTH_SHORT).show();
Log.d(TAG, "LeaderBoard: " + Long.toString(score));
} else {
Toast.makeText(MainActivity.this, "no data at .get()", Toast.LENGTH_SHORT).show();
Log.d(TAG, "LeaderBoard: .get() is null");
}
} else {
Toast.makeText(MainActivity.this, "no data...", Toast.LENGTH_SHORT).show();
Log.d(TAG, "LeaderBoard: " + Long.toString(score));
}
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(MainActivity.this, "Failure", Toast.LENGTH_SHORT).show();
Log.d(TAG, "LeaderBoard: FAILURE");
}
});
The 3 parameters to .loadCurrentPlayerLeaderboardScore are as follows
ID of the leaderboard to load the score from.
Time span to retrieve data for. Valid values are TIME_SPAN_DAILY, TIME_SPAN_WEEKLY, or TIME_SPAN_ALL_TIME.
The leaderboard collection to retrieve scores for. Valid values are either COLLECTION_PUBLIC or COLLECTION_SOCIAL.
Hi i'm working on facebook api. i have gone through facebook documentation and coded as instructed in it.The below code is working fine in android 2.1-3.2,But while running in android 4.0.4 its giving an error android.os.networkonmainthread. I'm not getting any idea how to write below code using AsynckTask or threads(Painless thread).Please anyone here Suggest me how to code so that it can execute on all versiosn of android.Here is my code.
public class Facebook4 extends Activity {
public static final String mAPP_ID = "222299217893177";
public Facebook mFacebook = new Facebook(mAPP_ID);
private static final String FACEBOOK_PERMISSION = "publish_stream";
private SharedPreferences mPrefs;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_facebook4);
((ImageView)findViewById(R.id.facebookLogin)).setOnClickListener( loginButtonListener );
SessionStore.restore(mFacebook, this);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mFacebook.authorizeCallback(requestCode, resultCode, data);
}
private OnClickListener loginButtonListener = new OnClickListener() {
public void onClick( View v ) {
if( !mFacebook.isSessionValid() ) {
Toast.makeText(Facebook4.this, "Authorizing", Toast.LENGTH_SHORT).show();
mFacebook.authorize(Facebook4.this, new String[] {FACEBOOK_PERMISSION},Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
//startActivity(new Intent(FacebookLogin.this,MainActivity.class));
}
else {
Toast.makeText( Facebook4.this, "Has valid session", Toast.LENGTH_SHORT).show();
try {
JSONObject json = Util.parseJson(mFacebook.request("me"));
String facebookID = json.getString("id");
String firstName = json.getString("first_name");
String lastName = json.getString("last_name");
Toast.makeText(Facebook4.this, "You already have a valid session, " + firstName + " " + lastName + ". No need to re-authorize.", Toast.LENGTH_SHORT).show();
}
catch( Exception error ) {
Toast.makeText( Facebook4.this, error.toString(), Toast.LENGTH_SHORT).show();
}
}
//startActivity(new Intent(FacebookLogin.this,MainActivity.class));
}
};
public final class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values) {
try {
//The user has logged in, so now you can query and use their Facebook info
JSONObject json = Util.parseJson(mFacebook.request("me"));
Log.i("id", json.getString("id"));
Log.i("FirstName", json.getString("first_name"));
Log.i("lastname", json.getString("last_name"));
Log.i("email", json.getString("email"));
Log.i("Name", json.getString("name"));
Log.i("gender",json.getString("gender"));
SessionStore.save(mFacebook, Facebook4.this);
}
catch( Exception error ) {
Toast.makeText( Facebook4.this, error.toString(), Toast.LENGTH_SHORT).show();
Log.i("error", error.toString());
}
}
public void onFacebookError(FacebookError error) {
Toast.makeText( Facebook4.this, "Something went wrong. Please try again.", Toast.LENGTH_LONG).show();
}
public void onError(DialogError error) {
Toast.makeText( Facebook4.this, "Something went wrong. Please try again.", Toast.LENGTH_LONG).show();
}
public void onCancel() {
Toast.makeText( Facebook4.this, "Something went wrong. Please try again.", Toast.LENGTH_LONG).show();
}
}
i have the same problem what i do was when i checker my manifest it was like this
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
i removed the targetSdkVersion
<uses-sdk
android:minSdkVersion="8"
/>
and it worked i think it will help you try
You are getting this error because you're doing a network operation, like accessing Facebook on your main UI Thread.
To fix it in the best way, move all network related code into a separate Thread or AsyncTask
In higher api's now you can not do network related task in the main thread. Run your code in other thread and the exception will not come.