Uri add text from edittext to link - java

findNumber.setOnClickListener(new View.OnClickListener() {
Uri uri = Uri.parse("http://wwww.whitepages.ca/phone/" + phoneNumber.getText());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
#Override
public void onClick(View v) {
startActivity(intent);
}
});
When I do that it only opened up "http://www.whitepages.com/phone/"

Related

Getting the String Value to proceed to the next (specific) Activity

What I am trying here is, I want to get the string value of flevel and then when I click the search button it will proceed to the next (specific) Activity.
Goal is:
if the flevel is "Beginner" the next activity will be for the "Beginner", and if the flevel is "Experienced" the next activity will be for the "Experienced", and so on..
flevelfb = FilipinoBeginner
Bundle bnfb2 = getIntent().getExtras();
String flevelfb = bnfb2.getString("flevel");
flevel.setText(String.valueOf(flevelfb));
flevelfe = FilipinoExperienced
Bundle bnfe2 = getIntent().getExtras();
String flevelfe = bnfe2.getString("flevel");
flevel.setText(String.valueOf(flevelfe));
This part is for the search button:
search.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String flevels = flevel.getText().toString();
if (flevels.equals(flevelfb)){
Intent intent= new Intent(getApplicationContext(), FilipinoBeginner.class);
startActivity(intent);
}
else if (flevels.equals(flevelfe)){
Intent intent= new Intent(getApplicationContext(), FilipinoExperienced.class);
startActivity(intent);
}
}
});
you can change just search button click like this
search.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String flevels = flevel.getText().toString();
Intent intent = null;
if (flevels.equals("Beginner")){
intent = new Intent(getApplicationContext(), FilipinoBeginner.class);
}
else if (flevels.equals("Experienced")){
intent = new Intent(getApplicationContext(), FilipinoExperienced.class);
}
startActivity(intent);
}
});

Uploading images to different folder in firebase

I'm creating an application were users get to upload two type of image which is their profile picture and their profile cover picture. But I'm having issues defining the different process without interference from each other as I'm unable to call two onActivityResult.
this is the code I'm currently using to upload profile picture to firebase storage
coverbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(galleryIntent, "SELECT IMAGE"), GALLERY_PICKER);
}
});
mImagebtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(galleryIntent, "SELECT IMAGE"), GALLERY_PICK);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLERY_PICK && resultCode == RESULT_OK) {
mPdialog = new ProgressDialog(SettingsActivity.this);
mPdialog.setTitle("Uploading");
mPdialog.setMessage("please wait....");
mPdialog.show();
Uri imageUri = data.getData();
CropImage.activity(imageUri)
.setAspectRatio(1, 1)
.setMinCropWindowSize(500,500)
.start(SettingsActivity.this);
}
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
Uri resultUri = result.getUri();
File file_thumb = new File(resultUri.getPath());
String current_uid = mCurrentuser.getUid();
Bitmap thumb_bitmap = new Compressor(this)
.setMaxWidth(200)
.setMaxHeight(200)
.setQuality(75)
.compressToBitmap(file_thumb);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
thumb_bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
final byte[] thumb_byte = baos.toByteArray();
StorageReference filepath = mImageReference.child("profile_images").child(current_uid + ".jpg");
final StorageReference thumb_path = mImageReference.child("profile_images").child("thumbs").child(current_uid + ".jpg");
filepath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
#Override
public void onComplete(#NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful()){
final String download_url = task.getResult().getDownloadUrl().toString();
UploadTask uploadTask = thumb_path.putBytes(thumb_byte);
uploadTask.addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
#Override
public void onComplete(#NonNull Task<UploadTask.TaskSnapshot> thumb_task) {
String thumb_downloadurl = thumb_task.getResult().getDownloadUrl().toString();
if (thumb_task.isSuccessful()){
Map update_hashmap = new HashMap();
update_hashmap.put("image",download_url);
update_hashmap.put("thumb_image", thumb_downloadurl);
mDatabase.updateChildren(update_hashmap).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()){
mPdialog.dismiss();
Toast.makeText(SettingsActivity.this,"success",Toast.LENGTH_LONG).show();
}
}
});
}else {
Toast.makeText(SettingsActivity.this,"failed",Toast.LENGTH_LONG).show();
mPdialog.dismiss();
}
}
});
}else {
Toast.makeText(SettingsActivity.this,"failed",Toast.LENGTH_LONG).show();
mPdialog.dismiss();
}
}
});
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Exception error = result.getError();
}
}
Try this
Move startActivityForResult & intent outside
Set intent requestCode according to which button was clicked
Intent galleryIntent = new Intent();
coverbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
}
});
mImagebtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
}
});
}
startActivityForResult(Intent.createChooser(galleryIntent, "SELECT IMAGE"), GALLERY_PICKER);

How can I get the URI to the file with 3 different file choosers?

I have 3 different buttons: Upload Profile Picture, Upload Photo ID and Upload Criminal Record Photo, but after I call the openFileChooser() method which I created, I don't know how exactly I have to handle that to get 3 different URls.
I mean I did this
public class SignupCarrier extends AppCompatActivity {
EditText editfullname, editemail, editpassword, editconfirmpassword, editaddress, editcity, editstate, editzipcode, editcountry, editphone, editcardnumber, editexpiredate, editcvc;
Button upProfile, upIDPhoto, upCriminalRecord;
private Uri mProfilePic, mIdPhoto,mCriminalRecord;
FirebaseAuth mFirebaseAuth;
private StorageReference mStorageRef;
private StorageTask mUploadTask;
private static final int PICK_IMAGE_REQUEST = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup_carrier);
mFirebaseAuth = FirebaseAuth.getInstance();
upProfile = (Button) findViewById(R.id.profilePic);
upIDPhoto = (Button) findViewById(R.id.idphotoPic);
upCriminalRecord = (Button) findViewById(R.id.criminalRecord);
mStorageRef = FirebaseStorage.getInstance().getReference("carriersPictures");
upProfile.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openFileChooser();
}
});
upIDPhoto.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openFileChooser();
}
});
upCriminalRecord.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openFileChooser();
}
});
}
private void openFileChooser() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, PICK_IMAGE_REQUEST);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null)
{
mProfilePic = data.getData();
}
}
}
But this would probably work only for upProfile Button, how can I modify the onActivityResult to get for each buttons the URLs?
Thank you! I'm new to Android.
Add Uri as parameter to your openFileChooser() method.
private void openFileChooser(Uri uri)
and call it like this:
upProfile.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openFileChooser(mProfilePic);
}
});
Update your openFileChooser() method to this:
private void openFileChooser(Uri uri) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
if (uri == mProfilePic) {
startActivityForResult(intent, PICK_IMAGE_REQUEST);
} else if (uri == mIdPhoto) {
startActivityForResult(intent, PICK_IMAGE_REQUEST_ID);
} else if (uri == mCriminalRecord) {
startActivityForResult(intent, PICK_IMAGE_REQUEST_CR);
}
}
You need to declare these constants: PICK_IMAGE_REQUEST_ID, PICK_IMAGE_REQUEST_CR
And in your onActivityResult() method check the requestCode to handle each case

Is there a way to attach any type of file to an email using intents?

I'm trying to create a small app where the user can type in recepient, subject, the message and if they want to, also attach a file. I ran in to a minor issue, I can't choose any file freely. I go through my folders and find images and PDF files but none of them are clickable, I can't choose any (They're greyed out for some reason).
I was able to choose a file once(don't remember what type it was) but I got an IO error from the outlook app, it couldn't handle the file for some reason.
public class MainActivity extends AppCompatActivity {
private static final int PICKFILE_REQUEST_CODE = 8778;
private EditText mEditTextTo;
private EditText mEditTextSubject;
private EditText mEditTextMessage;
private Button sendBtn;
private Button fileBtn;
private String filePath = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEditTextTo = (EditText)findViewById(R.id.edit_text_to);
mEditTextSubject = (EditText)findViewById(R.id.edit_text_subject);
mEditTextMessage = (EditText)findViewById(R.id.edit_text_message);
sendBtn = (Button)findViewById(R.id.sendBtn);
fileBtn = (Button)findViewById(R.id.fileBtn);
sendBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sendMail();
}
});
fileBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);
}
});
}
private void sendMail() {
String recepientList = mEditTextTo.getText().toString();
String[] recepient = recepientList.split(",");
String subject = mEditTextSubject.getText().toString();
String message = mEditTextMessage.getText().toString();
Intent sendEmailIntent = new Intent(Intent.ACTION_SEND);
sendEmailIntent.putExtra(Intent.EXTRA_EMAIL, recepient);
sendEmailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sendEmailIntent.putExtra(Intent.EXTRA_TEXT, message);
sendEmailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new
File(filePath)));
sendEmailIntent.setType("text/plain");
startActivity(Intent.createChooser(sendEmailIntent, "Choose email
client"));
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
filePath = data.getDataString();
super.onActivityResult(requestCode, resultCode, data);
}
}
You can use below code:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"email#example.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
intent.putExtra(Intent.EXTRA_TEXT, "body text");
File root = Environment.getExternalStorageDirectory();
File file = new File(root, xmlFilename);
if (!file.exists() || !file.canRead()) {
Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
finish();
return;
}
Uri.fromFile(file);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Send email..."));

How can i use Create Chooser on button click inside a subclass of dialog

Using this code to share audio file through create chooser but not working...
public class ActionDialog extends Dialog {
static String sSongTitle="";
static String sSongPath = "";
static File fSongFile ;
public ActionDialog(final Context context, Message response) {
super(context);
// Inflate our UI from its XML layout description.
setContentView(R.layout.after_save_action);
setTitle(R.string.alert_title_success);
((Button)findViewById(R.id.button_share))
.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Uri StringUri = Uri.fromFile(new File(sSongPath));
Intent intent = new Intent(android.content.Intent.ACTION_SEND, StringUri);
Intent in = new Intent(android.content.Intent.ACTION_SEND, StringUri, context, null);
intent.setType("audio/*");
startActivity(Intent.createChooser(in, "select any from the list:"));//getting error here as create method startActivity(Intent)
}
});
}
}
your Intent is intent not ishare
Uri is stringUri but you mention ed as StringUri..
can you post entire code.. to see errors if any
see this
code
#Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((Button) findViewById(R.id.button_share))
.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Uri stringUri = Uri.fromFile(new File(""));
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);// intent for sharing
sendIntent.putExtra(Intent.EXTRA_TEXT, stringurl);
sendIntent.setType("audio/*");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, StringTitle);
startActivity(sendIntent);// getting error
// as create
// method
// startActivity(Intent)
}
});
}

Categories

Resources