我正在尝试从Geocoder获取位置地址,我能够获得纬度和经度,但它返回的地址长度为零.
这是我的代码片段
double longi = location.getLongitude();
double latt = location.getLatitude();
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.ENGLISH);
String add="";
try {
List<Address> address = geocoder.getFromLocation(latt/1E6,longi/1E6, 1);
System.out.println("in location listener "+address.size());
int i=0;
if(address.size()>0)
{
for(i=0;i<address.get(0).getMaxAddressLineIndex();i++)
{
add += address.get(0).getAddressLine(i);
}
Toast toast = new Toast(getApplicationContext());
toast.makeText(getApplicationContext(), add, Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
请帮我把它搞定.提前致谢!
我想在特定的日期和时间在android中设置我的通知,我通过在java中使用日期来尝试它,但我的通知在时间之前被触发.那么我可以在指定的时间内解雇它.提前致谢!
这是我的通知代码:
Calendar cal = java.util.Calendar.getInstance();
cal.set(2012, 00, 30);
Date date = cal.getTime();
date.setHours(17);
date.setMinutes(30);
date.setSeconds(15);
long time = date.getTime();
Log.e("date is",""+date);
long when = time;
Notification notification = new Notification(notificationIcon,tickerText,date.getTime());
notification.when = date.getTime();
RemoteViews contentView = new RemoteViews("com.LayoutDemo",R.layout.userscreen);
notification.contentView= contentView;
Intent intent = this.getIntent();
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification.contentIntent= contentIntent;
notification.flags= Notification.FLAG_AUTO_CANCEL;
int NOTIFICATION_ID =1;
nManager.notify(NOTIFICATION_ID,notification);
Run Code Online (Sandbox Code Playgroud)