Menü seçeneğini seçtiğimde, hiçbir şey olmamasına rağmen, şu andaki konumumun bir SMS'sini göndermeye çalışıyorum. Bu benim kodum: Çalışmasını nasıl sağlayabileceğime dair olası bir çözüm var mı? menüsü altındaGeçerli konum SMS yoluyla gönderme
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingLeft="40dp"
android:paddingRight="40dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/myLocationText"
/>
</LinearLayout>
Benim menu_main Öğelerimin ilan etti:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
final LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
final LocationListener mlocListener = new MyLocationListener();
final Location location = mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
updateWithNewLocation(location);
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
if (Build.VERSION.SDK_INT >= 21) {
// Call some material design APIs here
} else {
// Implement this feature without material design
}
}
public class MyLocationListener implements LocationListener
{
public void onLocationChanged(final Location location)
{
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
private void updateWithNewLocation(final Location location)
{
String latLongString;
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.myLocationText);
String addressString = "No address found";
if (location != null)
{
final double lat = location.getLatitude();
final double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
final double latitude = location.getLatitude();
final double longitude = location.getLongitude();
final Geocoder gc = new Geocoder(this, Locale.getDefault());
try
{
final List<Address> addresses = gc.getFromLocation(latitude, longitude, 4);
final StringBuilder sb = new StringBuilder();
if (addresses.size() > 0)
{
final Address address = addresses.get(0);
for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
{
sb.append(address.getAddressLine(i)).append("\n");
}
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
addressString = sb.toString();
}
catch (final IOException e)
{
}
}
else
{
latLongString = "No location found";
}
myLocationText.setText("Your Current Position is:\n" +
latLongString + "\n" + addressString);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater inf = getMenuInflater();
inf.inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
String tv1;
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.myLocationText);
tv1= myLocationText.getText().toString();
switch (item.getItemId()) {
case R.id.sms_location:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", tv1);
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
return(true);
case R.id.email_location:
/* Create the Intent */
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
/* Fill it with Data */
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, tv1);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
return(true);
}
return super.onOptionsItemSelected(item);
}}
Bu benim faaliyettir. Gerçekten bir çözüm aradım ve log kedisinde hiçbir şey göremiyorum! Konumunuzu aldığınızdan beri
Herhangi bir yer alıyor musunuz? –
@UmerAsif Evet, bir yere gidiyorum – Zed