- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含 ID 的纬度和经度数据库,并使用 json 检索了该数据库,并希望将邻近警报应用于数组中的地理位置。我不确定数组是否正确传递或者接近警报.java 是否正确调用
这是数据库检索
public class retrieveDB extends AsyncTask<Void, Integer, Void> {
@Override
protected Void doInBackground(Void... params) {
String result = "";
InputStream is = null;
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://cs1.ucc.ie/~am32/getDB.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
is.close();
result=sb.toString();
Log.i("json string", result);
}
catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
//parse json data
try{
JSONArray jArray = new JSONArray(result);
JSONObject json_data = null;
System.out.println("Length"+ jArray.length());
Log.d("DB","Length"+jArray.length());
for(int i=0; i<jArray.length(); i++){
json_data = jArray.getJSONObject(i);
int id = json_data.getInt("ID") ;
//String title = json_data.getString("Title");
double latitude = json_data.getDouble("Lat");
double longitude = json_data.getDouble("Lon");
//Adds proximity to POI's
ProxAlert inst = new ProxAlert();
inst.addProximityAlert(latitude,longitude, id);
//
inst.saveCoordinatesInPreferences((float)latitude, (float)longitude);
//prints to logCat
System.out.println(id+"&"+latitude+"&"+longitude);
}
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
Log.e("log_tag","Failed data as:\n"+result);
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
// invoked on UI thread publishProgress(Progress...).
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(Void result) {
// result of background comp is passed to this step its invoked on the ui thread
super.onPostExecute(result);
}
}
和我的接近警报类
public class ProxAlert extends Activity {
private static final long POINT_RADIUS = 10;
private static final long PROX_ALERT_EXPIRATION = -1;
private static final String POINT_LATITUDE_KEY = "POINT_LATITUDE_KEY";
private static final String POINT_LONGITUDE_KEY = "POINT_LONGITUDE_KEY";
private LocationManager locationManager;
private static final String PROX_ALERT_INTENT= "com.example.try0.ProximityIntentReceiver";
void addProximityAlert (double latitude, double longitude, int id){
Bundle extras = new Bundle();
extras.putInt("title", id);
extras.putDouble("lat", latitude);
extras.putDouble("lon", longitude);
Intent intent = new Intent(PROX_ALERT_INTENT + id);
//intent.putExtra("alert", "it works");
intent.putExtra(PROX_ALERT_INTENT, extras);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, id, intent, PendingIntent.FLAG_CANCEL_CURRENT);
//ProximityIntent will be used to generate an Intent to fire when entry to or exit from the alert region is detected
locationManager.addProximityAlert(latitude,longitude,POINT_RADIUS,PROX_ALERT_EXPIRATION,proximityIntent);
IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT + id);
registerReceiver(new ProximityIntentReciever(), filter);
}
void saveCoordinatesInPreferences(float currentlatitude, float currentlongitude){
SharedPreferences prefs = this.getSharedPreferences(getClass().getSimpleName(), Context.MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = prefs.edit();
prefsEditor.putFloat(POINT_LATITUDE_KEY, currentlatitude);
prefsEditor.putFloat(POINT_LONGITUDE_KEY, currentlongitude);
prefsEditor.commit();
}
Location retrievelocationFromPreferences(){
SharedPreferences prefs = this.getSharedPreferences(getClass().getSimpleName(), Context.MODE_PRIVATE);
Location location = new Location("POINT_LOCATION");
location.setLatitude(prefs.getFloat(POINT_LATITUDE_KEY, 0));
location.setLongitude(prefs.getFloat(POINT_LONGITUDE_KEY, 0));
return location;
}
}
我真的很感谢一些帮助,这让我很困惑
最佳答案
这是我的服务,它工作得很好,我知道它在市场上是这样的,就在数据库所在的位置,如果您插入 JSON,也许您可以根据您的需要更改它
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.graphics.Color;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class ProximityService extends Service{
String proximitysd = "com.apps.ProximityService";
int n = 0;
private BroadcastReceiver mybroadcast;
private LocationManager locationManager;
MyLocationListener locationListenerp;
public ProximityService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
mybroadcast = new ProximityIntentReceiver();
locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
double lat;
double lng;
float radius = 50f;
long expiration = -1;
MyDBAdapter db = new MyDBAdapter(this);
Cursor cursor;
db.read();
cursor = db.getAllEntries();
boolean go = cursor.moveToFirst();
while(cursor.isAfterLast() != true){
lat = cursor.getInt(MyDBAdapter.LATITUDE_COLUMN)/1E6;
lng = cursor.getInt(MyDBAdapter.LONGITUDE_COLUMN)/1E6;
String what = cursor.getString(MyDBAdapter.ICON_COLUMN);
String how = cursor.getString(MyDBAdapter.FISH_COLUMN);
String proximitys = "com.apps.ProximityService" + n;
IntentFilter filter = new IntentFilter(proximitys);
registerReceiver(mybroadcast, filter );
Intent intent = new Intent(proximitys);
intent.putExtra("alert", what);
intent.putExtra("type", how);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, n, intent, PendingIntent.FLAG_CANCEL_CURRENT);
locationManager.addProximityAlert(lat, lng, radius, expiration, proximityIntent);
//sendBroadcast(new Intent(intent));
n++;
cursor.moveToNext();
}
db.close();
cursor.close();
}
@Override
public void onDestroy() {
Toast.makeText(this, "Proximity Service Stopped", Toast.LENGTH_LONG).show();
try{
unregisterReceiver(mybroadcast);
}catch(IllegalArgumentException e){
Log.d("reciever",e.toString());
}
}
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "Proximity Service Started", Toast.LENGTH_LONG).show();
//IntentFilter filter = new IntentFilter(proximitys);
//registerReceiver(mybroadcast,filter);
}
public class ProximityIntentReceiver extends BroadcastReceiver{
private static final int NOTIFICATION_ID = 1000;
@Override
public void onReceive(Context arg0, Intent arg1) {
String key = LocationManager.KEY_PROXIMITY_ENTERING;
Boolean entering = arg1.getBooleanExtra(key, false);
String here = arg1.getExtras().getString("alert");
String happy = arg1.getExtras().getString("type");
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent pendingIntent = PendingIntent.getActivity(arg0, 0, arg1, 0);
Notification notification = createNotification();
notification.setLatestEventInfo(arg0,
"Entering Proximity!", "You are approaching a " + here + " marker.", pendingIntent);
notificationManager.notify(NOTIFICATION_ID, notification);
}
private Notification createNotification() {
Notification notification = new Notification();
notification.icon = R.drawable.icon;
notification.when = System.currentTimeMillis();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.ledARGB = Color.WHITE;
notification.ledOnMS = 1500;
notification.ledOffMS = 1500;
return notification;
}
//make actions
}
public class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
Toast.makeText(getApplicationContext(), "I was here", Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String s) {
}
public void onProviderEnabled(String s) {
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
}
}
关于java - Android 具有多个 POI 的接近警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18596854/
如何将扩展名为 ttf 和 otf 的新字体导入 POI API,而不将这些字体安装到环境中? Is there a jar that i should update it with the path
在这个问题的所有引用资料中,它没有解决并且不给maven因为没有在maven中做。错误是 包 org.apache.poi.ss.usermodel 可以从多个模块访问:poi、poi.ooxm在
上下文: 尝试使用 Apache POI 的 poi 和 poi-ooxml 4.0.0 版本 jar 打开 XLSX 文件 问题: 程序抛出错误,如下所示。当我使用 4.0.0 版本时,我发现此错误
刚开始使用 POI 3.10 创建 Word 文档(XWPF)。 大多数事情都是直截了当的,但我不明白如何添加页码。 我添加了页脚,但页脚中的文字在每一页上都相同 最佳答案 我在 LibreOffic
我正在使用 Apache POI 评估工作簿的每个公式单元格。当一个单元格包含对标准 excel 函数 NOW() 的调用时,Poi 会正确评估它并将调用替换为当前时间 - 格式为 VM 的默认时区。
我已经阅读了许多与我的要求相关的博客和论坛,但到目前为止,我能够在我得到的所有帮助下为第一级生成项目符号或编号。谁能指导我如何使用 apache poi 创建多级编号。 想知道 Apache POI
我正在使用 apache poi 创建 Excel 工作表。我有像 - 337499.939437217 这样的数字,我想在 Excel 中显示它,而不进行四舍五入。此外,单元格格式应为数字(对于某些
情况是,我合并了第一行的所有五个单元格,并在第一行的第一个单元格中插入了一个图像。我的要求是使图像在第一行水平居中。 我试过 cellStyle.setAlignment(CellStyle.ALIG
我正在尝试替换模板 DOCX使用 Apache 的文档 POI通过使用 XWPFDocument类(class)。我在文档中有标签和 JSON文件以读取替换数据。我的问题是 DOCX 中的文本行似乎以
好吧,老实说:标题并没有说出全部真相。我正在使用带有多个按钮(保存、关闭、编辑等)和一个执行 POI 操作的按钮的自定义控件 - 它生成一个 Word 文件。 我在这里遇到一个问题:点击 POI 按钮
有什么方法可以让我获得 excel 连续显示的格式化值,而不是我从流中返回的原始值? 或者这是否属于“公式评估”类别,这不支持? 最佳答案 如果您有 Cell您正在尝试从中获取数据,请尝试以下操作 D
在 xlsx 工作簿中,有一些单元格带有一些无界 SUMIF 公式,如下所示:SUMIF(MySheetname!$B:$B,$E4,MySheetname!$I:$I) . 使用 Apache PO
我正在创建一个 Java 程序来读取 Excel 工作表并创建一个逗号分隔的文件。当我运行带有空白列的示例 excel 文件时,第一行工作正常,但其余行跳过空白单元格。 我已经阅读了将空白单元格插入行
我目前正在使用 POI 使用 XSLF 编辑 PPTX 文件内嵌入图表中的数据。我找到了一个使用带有饼图的模板 ppt 的示例,效果非常好。我还尝试编辑折线图并且它有效。但是,当我尝试编辑嵌入式条形图
我正在学习使用 Selenium 和 Excel 进行数据驱动测试。我正在参加一门在线类(class),要求在 Maven 中添加 Apache poi 和 poi-ooxml 依赖项。 我正在努力理
我们有一个具有画廊功能的应用程序,我们想将图像导出到 powerpoint 演示文稿中。我能够做到这一点,但由于图像的大小和方向不同,图像边界几乎总是超出 ppt 幻灯片。我如何调整图像的大小(我不想
我有一个带有以下幻灯片布局的 pptx: System.out.println("Available slide layouts:"); for(XSLFSlideMaster master
我正在尝试使用 Java 中的 POI api 创建 Excel 工作表。在那个 Excel 工作表中,我想要一个只有 TIME 的单元格。通过设置它,我们可以像在数字列中那样将单元格包含在该特定列的
Apache Poi 可以计算和返回公式中函数的结果。但是对于特殊函数 HYPERLINK(),它只返回“显示值”,而不是实际计算的超链接值。 我有一个 Excel 文件,其中包含复杂的计算超链接,这
我正在使用 Apache POI。 我可以使用“org.apache.poi.hwpf.extractor.WordExtractor”从文档文件中读取文本 甚至使用“org.apache.poi.h
我是一名优秀的程序员,十分优秀!