i am trying to create a future payment flow into my android app. I already send to my server the OaUTH2 authentication in my method sendAuthorizationToServer; My question is, what and how should i do next, i know that i have to implement a http request to set the future payment but the documetns in paypal are using curl. what should i do next?
here is my paypal activity:
package studio.brunocasamassa.ajudaaqui.payment;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import com.google.firebase.database.DatabaseReference;
import com.paypal.android.sdk.payments.PayPalAuthorization;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalFuturePaymentActivity;
import com.paypal.android.sdk.payments.PayPalService;
import studio.brunocasamassa.ajudaaqui.R;
import studio.brunocasamassa.ajudaaqui.helper.Base64Decoder;
import studio.brunocasamassa.ajudaaqui.helper.FirebaseConfig;
/**
* Created by bruno on 02/07/2017.
*/
public class PaymentActivity extends AppCompatActivity implements View.OnClickListener{
private static final int REQUEST_CODE_FUTURE_PAYMENT = 123;
private static PayPalConfiguration config = new PayPalConfiguration()
// Start with mock environment. When ready, switch to sandbox (ENVIRONMENT_SANDBOX)
// or live (ENVIRONMENT_PRODUCTION)
.environment(PayPalConfiguration.ENVIRONMENT_NO_NETWORK)
.clientId(PayPalConfig.PAYPAL_CLIENT_ID)
// Minimally, you will need to set three merchant information properties.
// These should be the same values that you provided to PayPal when you registered your app.
.merchantName("Hipster Store")
.merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
private ImageButton buttonPay;
private TextView editTextAmount;
private String userKey = Base64Decoder.encoderBase64(FirebaseConfig.getFirebaseAuthentication().getCurrentUser().getEmail());
private DatabaseReference dbUser = FirebaseConfig.getFireBase().child("usuarios").child(userKey);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paypal);
buttonPay = (ImageButton) findViewById(R.id.buttonPay);
editTextAmount = (TextView) findViewById(R.id.editTextAmount);
buttonPay.setOnClickListener(this);
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(intent);
}
#Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PayPalAuthorization auth = data
.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
if (auth != null) {
String authorization_code = auth.getAuthorizationCode();
Log.i("FuturePaymentExample", authorization_code);
sendAuthorizationToServer(auth);
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("FuturePaymentExample", "The user canceled.");
} else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i("FuturePaymentExample",
"Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
}
}
private void sendAuthorizationToServer(PayPalAuthorization auth) {
dbUser.child("auth").setValue(auth);
}
public void onFuturePaymentPressed(View pressed) {
Intent intent = new Intent(PaymentActivity.this, PayPalFuturePaymentActivity.class);
// send the same configuration for restart resiliency
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startActivityForResult(intent, REQUEST_CODE_FUTURE_PAYMENT);
}
public void onFuturePaymentPurchasePressed(View pressed) {
// Get the Client Metadata ID from the SDK
String metadataId = PayPalConfiguration.getClientMetadataId(this);
// TODO: Send metadataId and transaction details to your server for processing with
// PayPal...
dbUser.child("metadata").setValue(metadataId);
}
#Override
public void onDestroy() {
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
#Override
public void onClick(View v) {
onFuturePaymentPressed(v);
//onFuturePaymentPurchasePressed(v);
}
}
if someone knows, please tell me, i will be very gratefull
tks,
Related
I am using Firebase UI, it is working fine.
When I open the app I give one phone number and I sign in, but when I close and again open the app again give me a code.
I want that when I close the app and again open it doesn't give me again the code.
I know then this make with one if but I don't know how to make the best.
I was using firebase UI, I did see something about smart lock password of google but I don't know if this is right because the storage should be local
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.IdpResponse;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.FirebaseDatabase;
import com.xx.xx.R;
import java.util.Arrays;
import java.util.List;
public class Login extends AppCompatActivity {
EditText et_login, et_password;
Button bt_login, bt_register;
private static int RC_SIGN_IN = 123;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
setContentView(R.layout.activity_login);
et_login = (EditText) findViewById(R.id.et_login);
et_password = (EditText) findViewById(R.id.et_password);
bt_login = (Button) findViewById(R.id.bt_login);
bt_register = (Button) findViewById(R.id.bt_register);
bt_login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Login.this, MainActivity.class);
startActivity(intent);
finish();
}
});
bt_register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Login.this, RegisterActivity.class);
startActivity(intent);
}
});
// Choose authentication providers
List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.PhoneBuilder().build());
// Create and launch sign-in intent
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.build(),
RC_SIGN_IN);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
if (requestCode == RC_SIGN_IN) {
IdpResponse response = IdpResponse.fromResultIntent(data);
if (resultCode == RESULT_OK) {
// Successfully signed in
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
//Save user to local database
// ...
} else {
// Sign in failed. If response is null the user canceled the
// sign-in flow using the back button. Otherwise check
// response.getError().getErrorCode() and handle the error.
// ...
}
}
}
}
The app should give me one number and save it, then when I close the app and open again it will not give me access again if not log in with before credential stored in the app.
What you can do is that in onStart check if the user is signed in or not, if the user is signed in then navigate to your MainActivity or any other Activity -
#Override
public void onStart() {
super.onStart();
// Check if the user is signed in (non-null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();
// do your stuff
if (currentUser != null) {
// go to MainActivity
} else {
// user doesn't exist
}
}
I'm using Android Studio and I want to use Google API as a login. If the login is succesful, it can change to another activity. Besides that, I want to show the account name and profile picture in another activity, but I got this error:
error: identifier expected GoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this,this).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
My code:
package com.example.alif.angkotcoba;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
public class MainActivity extends AppCompatActivity implements
View.OnClickListener,GoogleApiClient.OnConnectionFailedListener {
private SignInButton SignIn;
private GoogleApiClient GoogleApiClient;
private static final int RC_SIGN_IN =9001;
private static final String TAG ="signInActivity";
GoogleSignInOptions gso=new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
GoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this,this).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SignIn = (SignInButton) findViewById(R.id.btngoogle);
SignIn.setOnClickListener(this);
}
public void gotoSecondActivity (View view) {
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btngoogle:
signIn ();
break;
}
}
public void signIn ()
{
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(GoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
public void handleResult (GoogleSignInResult result) {
GoogleSignInAccount account = result.getSignInAccount();
String name = account.getDisplayName();
String email = account.getEmail();
String img_url = account.getPhotoUrl().toString();
}
#Override
public void onActivityResult(int requestcode,int resultcode,Intent data) {
super.onActivityResult(requestcode,resultcode,data);
if (requestcode==RC_SIGN_IN){
GoogleSignInResult result=Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
private void handleSignInResult(GoogleSignInResult result) {
Log.d(TAG,"handleSignInResult:"+ result.isSuccess());
if (result.isSuccess()){
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
}
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
Log.d(TAG,"onConnectionFailed:"+connectionResult);
}
}
You need a variable name in the declaration. The problem is that you are trying to declare a variable with the same name as a class:
private GoogleApiClient GoogleApiClient;
That won't work. As far as the compiler is concerned, all you have on the left side of the assignment is the type name GoogleApiClient. Try something like this:
private GoogleApiClient googleApiClient; // note change of case!
googleApiClient = ...
Also, you are probably better off initializing anything that depends on this inside onCreate rather than when the variable is declared.
I am fairly new to android studio and developing with android. I have been trying this for months now, I need to record and save a video using Google Glass. The code that I currently have follows. This is code inspired from https://developers.google.com/glass/develop/gdk/camera#images
When I run this process, the video will start recording and then when the recording is stopped, it will give me the option "tap to accept" When I tap, nothing happens. I understand this is because my method "processVideoWhenReady" does absolutely nothing.
I would like to know if anyone could help me with what I should include in that method to save the video and allow it to be viewed by the user within my application.
Any literature or websites that have useful information about developing for Google Glass would also be a huge help if possible. Google's documentation doesn't seem very helpful to me and very limited.
import android.app.Activity;
import android.graphics.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.content.Intent;
import android.os.FileObserver;
import android.provider.MediaStore;
import android.util.Log;
import android.widget.VideoView;
import com.google.android.glass.content.Intents;
import com.google.android.glass.widget.CardBuilder;
import java.io.File;
import java.io.IOException;
public class RecordActivity extends Activity {
private static final int CAMERA_VID_REQUEST = 1337;
static final int REQUEST_VIDEO_CAPTURE = 1;
public VideoView mVideoView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_record);
takeVideo();
}
private void takeVideo(){
Intent startVideo = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (startVideo.resolveActivity(getPackageManager()) != null){
startActivityForResult(startVideo, REQUEST_VIDEO_CAPTURE);
}
//RecordActivity.this.startActivityForResult(startVideo, CAMERA_VID_REQUEST);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
//System.out.println("Entered onActivityResult() method");
String a = getIntent().getStringExtra("record");
System.out.println(a);
if(requestCode == CAMERA_VID_REQUEST && resultCode == RESULT_OK) {
//System.out.println("Result Okay");
Uri videoUri = data.getData();
mVideoView.setVideoURI(videoUri);
String videoPath = data.getStringExtra(Intents.EXTRA_VIDEO_FILE_PATH);
processVideoWhenReady(videoPath);
}
super.onActivityResult(requestCode, resultCode, data);
}
protected void processVideoWhenReady(final String videoPath){
final File videoFile = new File(videoPath);
if (videoFile.exists()){
//Process Video
}
else {
final File parentDirectory = videoFile.getParentFile();
FileObserver observer = new FileObserver(parentDirectory.getPath(), FileObserver.CLOSE_WRITE | FileObserver.MOVED_TO) {
private boolean isFileWritten;
#Override
public void onEvent(int event, String path) {
if (!isFileWritten) {
//make sure file was created in directory expected
File affectedFile = new File(parentDirectory, path);
isFileWritten = affectedFile.equals(videoFile);
if (isFileWritten) {
stopWatching();
runOnUiThread(new Runnable() {
#Override
public void run() {
processVideoWhenReady(videoPath);
}
});
}
}
}
};
observer.startWatching();
}
}
}
I have the following piece of code:
package audiovisuales.aventuresengulpiyuri;
import android.content.Intent;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import util.Utilidades;
public class PaginaPrimera extends AppCompatActivity implements OnInitListener{
private TextToSpeech tts;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pagina_primera);
if (!Utilidades.verificaConexion(this)){
Utilidades.mostrarVentanaErrorDeConexion(this);
}
else if(Portada.getLecturaAutomatica()){
tts= new TextToSpeech(PaginaPrimera.this, this);
tts.speak(getResources().getString(R.string.primeraPagina), TextToSpeech.QUEUE_FLUSH, null);
}
}
The minimum API I have set is API 19. I have checked that it enters in the else block and it detects the text to tell, but when I execute it doesn't say anything.
You need to check if TTS is available on the device.
First, in your onCreate method have this:
#Override
protected void onCreate(Bundle savedInstanceState) {
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, REQUEST_DATA_CHECK_CODE);
}
Then in you onActivityResult, check if it is ok to use TTS.
protected void onActivityResult(
int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, this);
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
}
Then check if the language of the device is available.
if (mTts.isLanguageAvailable(Locale.getDefault()) >= 0) {
mTts.setLanguage(Locale.getDefault());
mTts.speak(textToBeSpoken, TextToSpeech.QUEUE_FLUSH, null);
}
If the language is not available, you may try to install the data for that language or you may change the language.
I am working on an android code and trying to update the user information. I am able to retrieve the information but have not been able to update. Not sure what I am doing wrong.
In the if-else statement, it does not hit the If statement, goes directly to the error(else statement.
here is the code
package com.example.autrui;
import com.parse.GetCallback;
import com.parse.ParseACL;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
import com.parse.SaveCallback;
import com.parse.SendCallback;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class EditPP extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.editpp);
final Button confirmChangeEditPP = (Button) findViewById(R.id.bconfirmChangeEditPP);
final EditText fullName = (EditText) findViewById(R.id.etFullName);
final EditText email = (EditText) findViewById(R.id.etEmail);
//final ParseUser currentUser = new ParseUser();
final ParseUser currentUser = ParseUser.getCurrentUser();
System.out.println(currentUser);
String objectId = currentUser.getObjectId();
System.out.println(objectId);
String fName = currentUser.getString("fullName");
fullName.setText(fName);
email.setText(currentUser.getString("email"));
ParseQuery<ParseObject> userQuery = ParseQuery.getQuery("User");
userQuery.getInBackground((String)objectId, new GetCallback<ParseObject>(){
public void done(final ParseObject object, ParseException e) {
if (e == null) {
confirmChangeEditPP.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
ParseACL acl = new ParseACL();
acl.setPublicReadAccess(true);
acl.setPublicWriteAccess(true);
currentUser.setACL(acl);
object.put("fullName", fullName.getText().toString());
object.put("email", email.getText().toString());
object.saveInBackground();
}
});
} else {
Log.e("error","error");
}
}
});
}
#Override
public void onBackPressed() {
finish();
// Go to settings
/*
* if(MainActivity.s.isEmpty()) return; else { View v =
* MainActivity.s.pop(); Class c = MainActivity.s2.pop(); Intent intent
* = new Intent(v.getContext(), c); startActivityForResult(intent, 0); }
*/
}
private void showUserDetailsActivity() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
}
I got the answer. the error was regarding the ACL and yes we did not need the query. I wrote the whole code again and made it simpler.