This is part of the code, and the question is, how can I INTENT this values
Log.i(TAG, "Display Name: " + person.getDisplayName());
Log.i(TAG, "Gender: " + person.getGender());
Log.i(TAG, "About Me: " + person.getAboutMe());
Log.i(TAG, "Birthday: " + person.getBirthday());
Log.i(TAG, "Current Location: " + person.getCurrentLocation());
Log.i(TAG, "Language: " + person.getLanguage());
To another activity.
My idea which do not work is to do it like this
userGenderG = person.getGender();
userAboutG = person.getAboutMe();
userBirthdayG = person.getBirthday();
userLanguageG = person.getLanguage();
Unsuccessful idea.
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
// G+
if (mGoogleApiClient.hasConnectedApi(Plus.API)) {
Person person = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
if (person != null) {
Log.i(TAG, "--------------------------------");
Log.i(TAG, "Display Name: " + person.getDisplayName());
Log.i(TAG, "Gender: " + person.getGender());
Log.i(TAG, "About Me: " + person.getAboutMe());
Log.i(TAG, "Birthday: " + person.getBirthday());
Log.i(TAG, "Current Location: " + person.getCurrentLocation());
Log.i(TAG, "Language: " + person.getLanguage());
userGenderG = person.getGender();
userAboutG = person.getAboutMe();
userBirthdayG = person.getBirthday();
userLanguageG = person.getLanguage();
} else {
Log.e(TAG, "Error!");
}
} else {
Log.e(TAG, "Google+ not connected");
}
}
}
Any suggestion about how could I user gender as value and intent them to another activity?
UPDATED (how send data)
GoToNewActivity.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, Index.class);
Bundle extras = new Bundle();
extras.putString("userGender", userGenderG);
extras.putString("userAbout", userAboutG);
extras.putString("userBirthday", userBirthdayG);
extras.putString("userLanguage", userLanguageG);
intent.putExtras(extras);
startActivity(intent);
}
});
Related
I have created this app based on tutorials, ATM it successfully open the camera and displays it as imgOriginal on the screen. When i press the compress button I get a error relating to '.compressToFile(imageBitmap);
Error Message:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.photocompressor, PID: 11123
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getName()' on a null object reference
at id.zelory.compressor.Compressor.compressToFile(Compressor.java:56)
at com.example.photocompressor.MainActivity$3.onClick(MainActivity.java:149)
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if (resultCode == RESULT_OK) {
// if (resultCode == RESULT_IMAGE && resultCode == RESULT_OK ) {
if (resultCode == RESULT_OK && resultCode != RESULT_IMAGE) {
btnCompress.setVisibility(View.VISIBLE);
final Uri imageUri = data.getData();
try {
final InputStream imageStream = getContentResolver().openInputStream(imageUri);
final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
imgOriginal.setImageBitmap(selectedImage);
////originalImage = new File(imageUri.getEncodedPath().replace("raw/", ""));
long size = DocumentFile.fromSingleUri(this, imageUri).length();
//txtOriginal.setText("Size: " + Formatter.formatShortFileSize(this, originalImage.length()));
txtOriginal.setText("Size: " + Formatter.formatShortFileSize(this, size));
Toast.makeText(MainActivity.this, "Size: " + size, Toast.LENGTH_LONG).show();
//Toast.makeText(MainActivity.this, "Size: " + Formatter.formatShortFileSize(this, originalImage.length()), Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(this, "Something went Wrong", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "No Image Selected", Toast.LENGTH_SHORT).show();
// }
Below is the compress button, error appears in '.compressToFile'. I would ideally like to have the option to replace the original file or to save as a new file, but havent even got the replace file to work yet.
btnCompress.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int quality = seekBar.getProgress();
int width = Integer.parseInt(txtWidth.getText().toString());
int height = Integer.parseInt(txtHeight.getText().toString());
Toast.makeText(MainActivity.this, "Quality " + quality, Toast.LENGTH_SHORT).show();
try {
compressedImage = new Compressor(MainActivity.this)
.setMaxWidth(width)
.setMaxHeight(height)
.setQuality(quality)
.setCompressFormat(Bitmap.CompressFormat.JPEG)
.setDestinationDirectoryPath(filepath)
//.compressToFile(originalImage);
.compressToFile(imageBitmap);
File finalFile = new File(filepath, originalImage.getName());
Bitmap finalBitmap = BitmapFactory.decodeFile(finalFile.getAbsolutePath());
imgCompressed.setImageBitmap(finalBitmap);
//long newsize = DocumentFile.fromSingleUri(this, image);
//txtCompressed.setText("size: " + Formatter.formatShortFileSize(MainActivity.this,newsize));
//Toast.makeText(MainActivity.this, filepath + " Something went Wrong", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "Error while Compressing", Toast.LENGTH_SHORT).show();
}
}
});
My App1 launch App2:
case R.id.launch_button: {
try {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.app1");
intent.putExtra("Price", getAmount());
intent.putExtra("Description", getProductId());
startActivityForResult(intent, PAYMENT_REQUEST);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
Log.i(TAG, "Activity not found" );
}
break;
}
When App2 finish processing should return RESULT_OK or RESULT_CANCELED:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i(TAG, "onActivityResult " + requestCode + " " + resultCode + " " + data);
if (requestCode == PAYMENT_REQUEST) {
if (resultCode == Activity.RESULT_OK) {
Toast.makeText(this, "Payment success", Toast.LENGTH_LONG).show();
}
if (resultCode == Activity.RESULT_CANCELED) {
Toast.makeText(this, "Payment fail", Toast.LENGTH_LONG).show();
}
}
}
but RESULT_CANCELED appears immediately when the App2 launch.
Why am I receiving RESULT_CANCELED before even the App2 launch? What I'm doing wrong?
App2 return result code:
#Override
public void onPaymentSuccess() {
activity.setResult(Activity.RESULT_OK);
activity.finish();
}
#Override
public void onPaymentFail() {
activity.setResult(Activity.RESULT_CANCELED);
activity.finish();
}
I also dont receive any result when App2 finish..
Note: App2 use Fragment
I am integrating payumoney payment gateway on my Android app. But when I tried to make an test transaction by a test debit card. It shows an error.
when i contact to the payumoney customer care they said to whitelist the url to the server. i dont know how to whitelist url ito server.
public void startpay() {
builder.setAmount(amount) // Payment amount
.setTxnId(txnid) // Transaction ID
.setPhone(phone) // User Phone number
.setProductName(prodname) // Product Name or description
.setFirstName(firstname) // User First name
.setEmail(email) // User Email ID
.setsUrl("https://www.payumoney.com/mobileapp/payumoney/success.php") // Success URL (surl)
.setfUrl("https://www.payumoney.com/mobileapp/payumoney/failure.php") //Failure URL (furl)
.setUdf1("")
.setUdf2("")
.setUdf3("")
.setUdf4("")
.setUdf5("")
.setUdf6("")
.setUdf7("")
.setUdf8("")
.setUdf9("")
.setUdf10("")
.setIsDebug(true) // Integration environment - true (Debug)/ false(Production)
.setKey(merchantkey) // Merchant key
.setMerchantId(merchantId);
try {
paymentParam = builder.build();
// generateHashFromServer(paymentParam );
getHashkey();
} catch (Exception e) {
Log.e(TAG, " error s " + e.toString());
}
}
public void getHashkey() {
ServiceWrapper service = new ServiceWrapper(null);
Call<String> call = service.newHashCall(merchantkey, txnid, amount, prodname,
firstname, email);
call.enqueue(new Callback<String>() {
#Override
public void onResponse(Call<String> call, Response<String> response) {
Log.e(TAG, "hash res " + response.body());
String merchantHash = response.body();
if (merchantHash.isEmpty() || merchantHash.equals("")) {
Toast.makeText(StartPaymentActivity.this, "Could not generate hash", Toast.LENGTH_SHORT).show();
Log.e(TAG, "hash empty");
} else {
// mPaymentParams.setMerchantHash(merchantHash);
paymentParam.setMerchantHash(merchantHash);
// Invoke the following function to open the checkout page.
// PayUmoneyFlowManager.startPayUMoneyFlow(paymentParam, StartPaymentActivity.this,-1, true);
PayUmoneyFlowManager.startPayUMoneyFlow(paymentParam, StartPaymentActivity.this, R.style.AppTheme_default, false);
}
}
#Override
public void onFailure(Call<String> call, Throwable t) {
Log.e(TAG, "hash error " + t.toString());
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//PayUMoneySdk: Success -- merchantResponse438104
// on successfull txn
// request code 10000 resultcode -1
// Result Code is -1 send from Payumoney activity
Log.e("StartPaymentActivity", "request code " + requestCode + " resultcode " + resultCode);
if (requestCode == PayUmoneyFlowManager.REQUEST_CODE_PAYMENT && resultCode == RESULT_OK && data != null) {
TransactionResponse transactionResponse = data.getParcelableExtra(PayUmoneyFlowManager.INTENT_EXTRA_TRANSACTION_RESPONSE);
if (transactionResponse != null && transactionResponse.getPayuResponse() != null) {
if (transactionResponse.getTransactionStatus().equals(TransactionResponse.TransactionStatus.SUCCESSFUL)) {
//Success Transaction
Toast.makeText(this, "Payment successful", Toast.LENGTH_SHORT).show();
} else {
//Failure Transaction
Toast.makeText(this, "Payment failed", Toast.LENGTH_SHORT).show();
}
// Response from Payumoney
//String payuResponse = transactionResponse.getPayuResponse();
// Response from SURl and FURL
//String merchantResponse = transactionResponse.getTransactionDetails();
//Log.e(TAG, "tran " + payuResponse + "---" + merchantResponse);
} /* else if (resultModel != null && resultModel.getError() != null) {
Log.d(TAG, "Error response : " + resultModel.getError().getTransactionResponse());
} else {
Log.d(TAG, "Both objects are null!");
}*/
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//PayUMoneySdk: Success -- merchantResponse438104
// on successfull txn
// request code 10000 resultcode -1
// Result Code is -1 send from Payumoney activity
Log.e("StartPaymentActivity", "request code " + requestCode + " resultcode " + resultCode);
if (requestCode == PayUmoneyFlowManager.REQUEST_CODE_PAYMENT && resultCode == RESULT_OK && data != null) {
TransactionResponse transactionResponse = data.getParcelableExtra(PayUmoneyFlowManager.INTENT_EXTRA_TRANSACTION_RESPONSE);
if (transactionResponse != null && transactionResponse.getPayuResponse() != null) {
if (transactionResponse.getTransactionStatus().equals(TransactionResponse.TransactionStatus.SUCCESSFUL)) {
//Success Transaction
Toast.makeText(this, "Payment successful", Toast.LENGTH_SHORT).show();
} else {
//Failure Transaction
Toast.makeText(this, "Payment failed", Toast.LENGTH_SHORT).show();
}
// Response from Payumoney
//String payuResponse = transactionResponse.getPayuResponse();
// Response from SURl and FURL
//String merchantResponse = transactionResponse.getTransactionDetails();
//Log.e(TAG, "tran " + payuResponse + "---" + merchantResponse);
}
}
}
Please keep this line in your android manifest file under application tag android:usesCleartextTraffic="true" as shown below
AndroidManifest.xml
<application
android:usesCleartextTraffic="true">
</application>
Please keep this line in your android manifest file under application tag android:usesCleartextTraffic="true" as shown below
<application
android:usesCleartextTraffic="true"
tools:replace="usesCleartextTraffic">
</application>
This is happening because web url is HTTP instead of HTTPS (http://XXX.XXX.XXX.XX:3000/.....)
This is already answered here.
Android 8: Cleartext HTTP traffic not permitted
I am new to android development, and I am using intent to choose a file locally so I can upload it to some cloud storage. I have been realizing a lot that the file names returned are in the form image:b for some number b. For example for a file I get path = /document/image:91 and filename = image:91. Does this mean that my result is wrong? I was expecting to get the actual file name. I just want to know if my code is correct.
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "requestCode: " + requestCode);
Log.d(TAG, "resultCode: " + resultCode);
Log.d(TAG, "Actiity.RESULT_OK: " + Activity.RESULT_OK);
Log.d(TAG, "intent data: " + data);
if (requestCode == CHOOSE_FILE_REQUESTCODE && resultCode == Activity.RESULT_OK && null != data) {
Uri image = data.getData();
String path = image.getPath();
this.file = new File(path);
String filename = image.getLastPathSegment();
//File destination = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/CustomFolder/" + filename);
Log.d(TAG, "file name: " + filename);
Log.d(TAG, "file path: " + path);
this.fileName.setText(filename);
}
}
Start Intent.
public void onClickSelectPhoto(View v){
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
}
I am trying to get e-mail address of the people the user has invited from my app
This is my code:
private void onInviteClicked() {
Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
.setMessage(getString(R.string.invitation_message))
.setDeepLink(Uri.parse(getString(R.string.invitation_deep_link)))
.setCustomImage(Uri.parse("http://jennstrends.com/wp-content/uploads/2013/10/bad-profile-pic-2.jpeg"))
.setCallToActionText(getString(R.string.invitation_cta)).setCallToActionText("email").build();
startActivityForResult(intent, REQUEST_INVITE);
}
int REQUEST_INVITE = 10101;
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode);
if (requestCode == REQUEST_INVITE) {
if (resultCode == RESULT_OK) {
// Get the invitation IDs of all sent messages
final String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
final List<String> members = new ArrayList();
members.add(GoogleAuthHelper.getInstance().getUser().getProjectId());
for (String id : ids) {
members.add(id);
}
ApiClient.getInstance(getBaseContext()).addMembers(members, new OnPostListener<String>() {
#Override
public void onError(ANError error) {
Log.e("Server", "Members: " + error.getErrorCode());
}
#Override
public void onResponse(String val) {
Log.d("Server", "Response from Member: " + val.toString());
}
});
} else {
// Sending failed or it was canceled, show failure message to
// the user
// ...
Log.d("Server", "Invitation Failed code: " + resultCode);
}
}
}
Now how do I get the email addresses of the list of people the user has invited. AppInviteInvitation.getInvitationIds() are not the email ids. Someone help me out! Please!