I'm trying to change GPS from 2 locations to 1 location
The code for 2 locations is:
ismi.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
String CURRENT_LOCATION = "37.967775, 23.720689";
String DESTINATION_LOCATION = "37.925942, 23.938683";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+ CURRENT_LOCATION +"&daddr="+DESTINATION_LOCATION)); //Added ampersand
startActivity(intent);
}
});
And to change to one location like: http://i.stack.imgur.com/zCvW5.png
I even changed on part but it takes from my location to the destination location
Code:
ismi.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
String DESTINATION_LOCATION = "37.925942, 23.938683";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" +"&daddr="+DESTINATION_LOCATION)); //Added ampersand
startActivity(intent);
}
});
Does anyone know the code?
Thanks
To start an Intent that will take you to a single GPS location, use:
String DESTINATION_LOCATION = "37.925942,23.938683";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?q="+DESTINATION_LOCATION));
startActivity(intent);
The URI contains The GPS coordinates as you defined previously. Note that there should be no spaces between latitude and longitude values in your DESTINATION_LOCATION String.
Edit: As response to your first question in your comment, to give a name to the label:
String DESTINATION_LOCATION = "My location name";
String latit = "37.925942";
String longit = "23.938683";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:<"+latit+">,<"+longit+">?q=<"+latit+">,<"+longit+">("+DESTINATION_LOCATION+")")); //name the label
startActivity(intent);
Related
I'm using intent to pass the string value to next Activity where I use getStringExtra to get the Value. The value is is User Contact no. in 10 digit which is in numeric value. when I setText in textview then It display the correct format but when I use intent on onclicklistener to open dialpad then instead of no, some random no. appears and in 4 digit also
Here I use to pass string
intent.putExtra(MOBILE, g.getSellermobile());
and I receive it by
tutor_mobile = intent.getStringExtra(MOBILE);
when I set it in textview as
TextView contact = (TextView) findViewById(R.id.tutor_near);
contact.setText(tutor_mobile);
It display correct format eg 9868336847
but when I use intent to open dialpad as
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"+String.valueOf(tutor_mobile)));
startActivity(intent);
I'm using below code to get the mobile no.
etMobile = (EditText) findViewById(R.id.user_mobile);
String sellermobile = etMobile.getText().toString();
and In class file I have
package com.nepalpolice.filmyduniya.maincategory;
public class location {
public String sellermobile;
// public Uri uri;
public location( String sellermobile) {
this.sellermobile = sellermobile;
// this.uri = uri;
}
public String getSellermobile() { return sellermobile;}
}
}
Then in activity I have
public static final String MOBILE = "other_mobile";
and
intent.putExtra(MOBILE, g.getSellermobile());
and in next activity I have
tutor_mobile = intent.getStringExtra(MOBILE); and
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"+String.valueOf(tutor_mobile)));
startActivity(intent);
Then random no. in 4 digit appears.
Then in activity I have
Please Help.
Your tutor_mobile is a String value, but thr you rearrange it toString:
intent.setData(Uri.parse("tel:"+String.valueOf(tutor_mobile)));
May be it's not a error, but it's strange. And what do you want to display in dialpad?
try {
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:" + "string format number"));
startActivity(callIntent);
} catch (Exception e) {
Log.d("Response", e.toString());
}
In my app I am trying to provide two functions to the users. One is uploading a post with an image and the other is to upload post without an image. To do so I created Strings nonselected_image and selected_image (or selected_bitmap). In case of pressing one of the TextViews by user one of the strings will be passed within the intent consequently. It works great when user wishes to create non photo post but when he wants to create one with a photo there are two posts emerging, one with photo and the other without. What did I wrong? Here is my code.
Sending an intent and strings to the next activity
TextView nextScreen = (TextView) view.findViewById(R.id.tvNext);
nextScreen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: navigating to the final share screen.");
if (isRootTask()) {
Intent intent = new Intent(getActivity(), NextActivity.class);
intent.putExtra(getString(R.string.selected_image), mSelectedImage);
startActivity(intent);
} else {
Intent intent = new Intent(getActivity(), AccountSettingsActivity.class);
intent.putExtra(getString(R.string.selected_image), mSelectedImage);
intent.putExtra(getString(R.string.return_to_fragment), getString(R.string.edit_profile_fragment));
startActivity(intent);
getActivity().finish();
}
}
});
noPhoto.setOnClickListener(new View.OnClickListener(){
public void onClick (View v) {
mSelectedImage = null;
Intent intent = new Intent(getActivity(), NextActivity.class);
intent.putExtra(getString(R.string.nonselected_image), nonSelectedImage);
startActivity(intent);
}
});
receiving an intent and taking actions accordingly to passed variable
public void onClick(View v) {
Log.d(TAG, "onClick: navigating to the final share screen.");
//upload the image to firebase
// Toast.makeText(NextActivity.this, "Attempting to upload new photo", Toast.LENGTH_SHORT).show();
String caption = mCaption.getText().toString();
if(intent.hasExtra(getString(R.string.selected_image))){
imgUrl = intent.getStringExtra(getString(R.string.selected_image));
Toast.makeText(NextActivity.this, "Attempting to upload a normal photo", Toast.LENGTH_SHORT).show();
mFirebaseMethods.uploadNewPhoto(getString(R.string.new_photo), caption, imageCount, imgUrl,null);
}
else if(intent.hasExtra(getString(R.string.selected_bitmap))){
bitmap = (Bitmap) intent.getParcelableExtra(getString(R.string.selected_bitmap));
Toast.makeText(NextActivity.this, "Attempting to upload a new bitmap", Toast.LENGTH_SHORT).show();
mFirebaseMethods.uploadNewPhoto(getString(R.string.new_photo), caption, imageCount, null,bitmap);
}
else if(intent.hasExtra(getString(R.string.nonselected_image)));{
Toast.makeText(NextActivity.this, "Attempting to upload new photo", Toast.LENGTH_SHORT).show();
imgUrl = intent.getStringExtra(getString(R.string.nonselected_image));
mFirebaseMethods.uploadNoPhoto(getString(R.string.new_photo), caption, imageCount, imgUrl, null); // HERE IS THE ERROR
}
Hi guys I need your help, I am stuck in that place. I would like to have first and secondname pasted to user area to appear automatically after logging in. The problem is the user area is in different java class than the one which comes next after log in activity.
Here is the part of the code from log in activity
if(session.loggedin()){
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
}
btnlogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final String email = etemail.getText().toString();
final String password = etpassword.getText().toString();
Response.Listener<String> responseListener = new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if(success){
String firstusername = jsonResponse.getString("firstusername");
String secondusername = jsonResponse.getString("secondusername");
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra("firstusername", firstusername);
intent.putExtra("secondusername", secondusername);
startActivity(intent);
finish();
session.SetLoggedIn(true);
And here is the code from the user activity
/*
Code for showing users name and last name
*/
final TextView firstUsername = (TextView) findViewById(R.id.firstusername);
final TextView secondUsername = (TextView) findViewById(R.id.secondusername);
Intent intent = getIntent();
String firstusername = intent.getStringExtra("firstusername");
String secondusername = intent.getStringExtra("secondusername");
firstUsername.setText(firstusername);
secondUsername.setText(secondusername);
Now I uploaded some more code.
You approach seems correct. First you should check if your extras are not null( for some reason).
Bundle extras = getIntent().getExtras();
if (extras!= null)
Or if the variables you pass(the one you deserialize from json) to intent are not empty
I wan to implicitly pass two string or variable from a dialoguebox to be used by another activity and at the same time opening that activity.
dialoguebox
String city = addresses.get(0).getLocality();
String category = "Hazard";
AlertDialog.Builder prompt = new
AlertDialog.Builder(MapsActivity.this);
prompt.setCancelable(false)
.setPositiveButton("Mineralization", new
DialogInterface.OnClickListener() {
.setPositivetiveButton("Geohazard", new
DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int which) {
startActivity(new
Intent(getApplicationContext(),MapsActivity.class));
//i want to pass the String city and category here
}
}
)
AlertDialog alert = prompt.create();
alert.setTitle("Please select an option");
alert.show();
TextView myTextView = (TextView) findViewById(R.id.PSString);
myTextView.setText(city);
New activity
package com.example.boneyflesh.homepage;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class GeohazardResults extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_geohazard_results);
}
}
how do i do this? what do i write on the onClickListener and what do i do on the new activity so that i can get the strings?
Instead of doing something like this in your onClick method
startActivity(new Intent(getApplicationContext(),MapsActivity.class));
You can just pass the two strings through the intent to the MapsActivity inside your onClick method as shown below
Intent lIntent = new Intent(getApplicationContext(), MapsActivity.class);
lIntent.putExtra("city", city);
lIntent.putExtra("category", category);
startActivity(lIntent);
and retrieve those values in MapsActivity as shown below
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_geohazard_results);
String city = getIntent().getStringExtra("city");
String category = getIntent().getStringExtra("category");
}
Pass Using Intent and Bundle like Below:
Intent intent = new Intent(getApplicationContext(),MapsActivity.class));
Bundle bundle =new Bundle();
bundle.putString("key1","value1");
bundle.putString("key2","value2");
intent.putExtras(bundle);
startActivity(intent );
And Retrieve value in next Activity like below:
Bundle bundle = getIntent().getExtras();
String value1= bundle.getString("key1");
String value2= bundle.getString("key2");
You need to use extras to send the data.
For example:
Intent intent = new Intent(getApplicationContext(),MapsActivity.class);
intent.putExtra("SOME_NAME_HERE", theString);
startActivity(intent);
Then, in the target activity you write - in onCreate:
Bundle extras = getIntent().getExtras();
if(extras == null) {
theString= null;
} else {
theString = extras.getString("SOME_NAME_HERE");
}
In your dialogbox:
Intent i = new Intent(MapsActivity.this, GeohazardResults.class);
i.putExtra("city", city);
i.putExtra("category", categoty);
startActivity(i);
In your new activity:
Intent i = getIntent();
Bundle extras = i.getExtras();
String city = extras.getString("city");
String category = extras.getString("category");
Instead of doing this -:
startActivity(new Intent(getApplicationContext(),MapsActivity.class));
Do something like this -:
Intent mapsActivityIntent = new Intent(getApplicationContext(), MapsActivity.class);
mapsActivityIntent.putExtra("CITY", city);
mapsActivityIntent.putExtra("CATEGORY", category);
startActivity(mapsActivityIntent);
In your activity you can then get them by doing :
getIntent().getStringExtra("CITY");
getIntent().getStringExtra("CATEGORY");
DialogInterface.OnClickListener() {
.setPositivetiveButton("Geohazard", new
DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int which) {
Intent intent = new Intent(getApplicationContext(),MapsActivity.class))
// intent.putExtra(key,value);
intent.putExtra("String1","value1");
intent.putExtra("String2","value2");
startActitvity(intent);
}
}
)
in Acivity
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if(extras != null){
//intent.getStringExtra(key)
string1 = intent.getStringExtra("String1");
string2 = intent.getStringExtra("String2");
}
i would suggest define keys as constants and use those while passing values, to avoid any confusion
pass intent from your dialog like this
Intent intent=new Intent(context, GeohazardResults.class);
Bundle parameters=new Bundle();
parameters.putString("city",city);
parameters.putString("category",category);
intent.putExtra("key",parameters);
startActivity(intent);
and in the next activity receive thiese values like this.
Intent receivedIntent=getIntent();
if(receivedIntent!=null){
Bundle parameters=receivedIntent.getBundleExtra("key");
if(parameters!=null){
String city=parameters.getString("city");
String category=parameters.getString("category");
}
}
I'm making a score list for a game, I had used the following code to pass the scoretime to ScoreActivity, but I don't know why it will only show the default number "1"
long timeSpent = System.currentTimeMillis() - initialTime;
timeSpent = (long) (timeSpent / 1000.0);
int apple = (int)timeSpent;
Intent scoreIntent = new Intent(GameActivity.this,ScoreActivity.class);
scoreIntent.putExtra("score",apple);
AlertDialog alertDialog = new AlertDialog.Builder(GameActivity.this).create();
alertDialog.setTitle("Game Over!");
alertDialog.setMessage(" Total time " + String.valueOf(timeSpent));
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE,"Exit", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Intent i =new Intent(getContext(), ScoreActivity.class);
getContext().startActivity(i);
}
In ScoreActivity
TextView myText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_score);
myText = (TextView)findViewById(R.id.text444);
Intent scoreIntent = getIntent();
int rating = scoreIntent.getIntExtra("score", 1);
String str = Integer.toString(rating);
myText.setText(rating);
}
It shows the default value because you created an intent and put extras in it
Intent scoreIntent = new Intent(GameActivity.this,ScoreActivity.class);
scoreIntent.putExtra("score",apple);
that's right but when you started the activity you used another intent
Intent i =new Intent(getContext(), ScoreActivity.class);
getContext().startActivity(i);
and the value of apple isn't in the new intent i so a solution is to make your intent scoreIntent as final which you can access from your onClick() method like:
final Intent scoreIntent = new Intent(GameActivity.this,ScoreActivity.class);
scoreIntent.putExtra("score",apple);
and from onClick() you do this
getContext().startActivity(scoreIntent );
You need pass your value here
Intent i =new Intent(getContext(), ScoreActivity.class);
i.putExtra("score",Apple);
getContext().startActivity(i);