androidquery
‘壹’ android里queryIntentActivities(resolveIntent, 0);返回的list的size为什么是0
resolveIntent设置数凳的薯悉旅有问题陆悉。
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PackageManager pm = context.getPackageManager();
List<ResolveInfo> apps = pm.queryIntentActivities(resolveIntent, 0);
‘贰’ Android用query怎么进行多条件查询
sqliteDatabase 给我提供的方法很不实用,还是建议楼主自己写sql语句,参数想怎么传都可以x0dx0a例如:Cursor c = db.rawQuery("select * from user where username=? and password = ?",x0dx0anew Stirng[]{"用户名","密码"});x0dx0ax0dx0a如果你非要调用SQLiteDatabase的query方法,那可以这样x0dx0adb.query("表名", new String[]{"字段1,字段2"}, "条件1=? and 条件2=?", new String[]{"条件1的值,条件2的值"},null,null,null)
‘叁’ android sqllite query()查询
public Cursor query (String table, String[] columns, String selection, String[] selectionArgs,String groupBy, String having,String orderBy,String limit)参数如下:
table:表名。相当于select语句from关键字后面的部分。如果皮首是多表联合查询,可以用逗号将两个表名分开。
columns:要查询出来的列名。相当于select语句select关键字后面的部分。
selection:查询条件子句,相当于select语句where关键字后面的部分,在条件子句允许使用占位符“?”
selectionArgs:对应于selection语句中占位符的值,值在数组中的位置与占位符在语句中的位置必须一致燃铅数,否则就会有异常。
groupBy:相当于select语句group by关键字后面的部分
having:相当于select语句having关键字后面的部分
orderBy:相当于select语句order by关键字后面的部分,如:personid desc, age asc;
limit:指定激拍偏移量和获取的记录数,相当于select语句limit关键字后面的部分。
‘肆’ Android编程query的orderBy参数怎么填
String orderBy. 你用的是逗握态 3,
return dbYx.query(YX_TABLE, new String[]{ KEY_YX_ID, KEY_YX_NAME, KEY_YX_NO, KEY_YX_VALUE}, null, null, null, null, null);
java">1.query(Stringtable,String[]columns,Stringselection,String[]selectionArgs,StringgroupBy,Stringhaving,StringorderBy,Stringlimit)
2.query(booleandistinct,Stringtable,String[]columns,Stringselection,String[]selectionArgs,StringgroupBy,Stringhaving,StringorderBy,Stringlimit,)
3.query(Stringtable,String[]columns,Stringselection,String[]selectionArgs,String皮李groupBy,Stringhaving,StringorderBy)
4.query(booleandistinct,Stringtable,String[]columns,山源Stringselection,String[]selectionArgs,StringgroupBy,Stringhaving,StringorderBy,Stringlimit)
‘伍’ 我把文件从保险箱移入存储位置androidquery。现应怎么查找
随便下一个文件管理器都有搜索功能,搜索文件夹名称就找到了
‘陆’ android query 模糊查询怎么使用
Android中SQLite模糊查询,可以直接使用Cursor 的query加入模糊查询的条件即可。 使用query有如下方式: 1.使用这种query方法%号前不能加',以下为示例代码: Cursor c_test = mDatabase.query(tab_name, new String[]{tab_field02}, tab_field02+" LIKE ? ", new String[] { "%" + str[0] + "%" }, null, null, null); 2.使用这种query方法%号前必须加',以下为示例代码 : Cursor c_test=mDatabase.query(tab_name, new String[]{tab_field02},tab_field02+" like '%" + str[0] + "%'", null, null, null, null); 3.使用这种方式必须在%号前加' ,以下为示例代码 : String current_sql_sel = "SELECT * FROM "+tab_name +" where "+tab_field02+" like '%"+str[0]+"%'"; Cursor c_test = mDatabase.rawQuery(current_sql_sel, null);
‘柒’ android如何保存html文件,包括其中的图片。
1、先示例图片
2、操作代码
package com.nekocode.xue.utils;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.androidquery.AQuery;
import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.AjaxStatus;
import com.nekocode.xue.PublicData;
import com.nekocode.xue.PublicData.Subscribe;
public class HtmlStorageHelper {
private String URL = "http://eproject.sinaapp.com/fetchurl.php/getcontent/";
private PublicData pd;
private AQuery aq;
private SQLiteDatabase mDB;
private String mDownloadPath;
public HtmlStorageHelper(Context context) {
pd = PublicData.getInstance();
aq = new AQuery(context);
mDB = context.openOrCreateDatabase("data.db", Context.MODE_PRIVATE, null);
mDB.execSQL("create table if not exists download_html(_id INTEGER PRIMARY KEY AUTOINCREMENT, content_id TEXT NOT NULL, title TEXT NOT NULL)");
mDownloadPath = pd.mAppPath + "download/";
File dir_file = new File(pd.mAppPath + "download/");
if(!dir_file.exists())
dir_file.mkdir();
}
public void saveHtml(final String id, final String title) {
if(isHtmlSaved(id))
return;
aq.ajax(URL+id, String.class, new AjaxCallback<String>() {
@Override
public void callback(String url, String html, AjaxStatus status) {
File dir_file = new File(mDownloadPath + id);
if(!dir_file.exists())
dir_file.mkdir();
Pattern pattern = Pattern.compile("(?<=src=")[^"]+(?=")");
Matcher matcher = pattern.matcher(html);
StringBuffer sb = new StringBuffer();
while(matcher.find()){
downloadPic(id, matcher.group(0));
matcher.appendReplacement(sb, formatPath(matcher.group(0)));
}
matcher.appendTail(sb);
html = sb.toString();
writeHtml(id, title, html);
}
});
}
private void downloadPic(String id, String url) {
File pic_file = new File(mDownloadPath + id + "/" + formatPath(url));
aq.download(url, pic_file, new AjaxCallback<File>() {
@Override
public void callback(String url, final File file, AjaxStatus status) {
}
});
}
private void writeHtml(String id, String title, String html) {
File html_file = new File(mDownloadPath + id + "/index.html");
FileOutputStream fos = null;
try {
fos=new FileOutputStream(html_file);
fos.write(html.getBytes());
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
fos.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
ContentValues values = new ContentValues();
values.put("content_id", id);
values.put("title", title);
mDB.insert("download_html", "_id", values);
}
public boolean isHtmlSaved(String id) {
File file = new File(mDownloadPath + id);
if(file.exists()) {
file = new File(mDownloadPath + id + "/index.html");
if(file.exists())
return true;
}
deleteHtml(id);
return false;
}
public String getTitle(String id) {
Cursor c = mDB.rawQuery("select * from download_html where content_id=?", new String[]{id});
if(c.getCount() == 0)
return null;
c.moveToFirst();
int index1 = c.getColumnIndex("title");
return c.getString(index1);
}
public ArrayList<Subscribe> getHtmlList() {
Cursor c = mDB.rawQuery("select * from download_html", null);
ArrayList<Subscribe> list = new ArrayList<Subscribe>();
if(c.getCount() != 0) {
c.moveToFirst();
int index1 = c.getColumnIndex("content_id");
int index2 = c.getColumnIndex("title");
while (!c.isAfterLast()) {
String id = c.getString(index1);
if(isHtmlSaved(id)) {
Subscribe sub = new Subscribe(
id,
c.getString(index2),
Subscribe.FILE_DOWNLOADED
);
list.add(sub);
}
c.moveToNext();
}
}
return list;
}
public void deleteHtml(String id) {
mDB.delete("download_html", "content_id=?", new String[]{id});
File dir_file = new File(mDownloadPath + id);
deleteFile(dir_file);
}
private void deleteFile(File file) {
if (file.exists()) { // 判断文件是否存在
if (file.isFile()) { // 判断是否是文件
file.delete(); // delete()方法 你应该知道 是删除的意思;
} else if (file.isDirectory()) { // 否则如果它是一个目录
File files[] = file.listFiles(); // 声明目录下所有的文件 files[];
for (int i = 0; i < files.length; i++) { // 遍历目录下所有的文件
this.deleteFile(files[i]); // 把每个文件 用这个方法进行迭代
}
}
file.delete();
} else {
//
}
}
private String formatPath(String path) {
if (path != null && path.length() > 0) {
path = path.replace("\", "_");
path = path.replace("/", "_");
path = path.replace(":", "_");
path = path.replace("*", "_");
path = path.replace("?", "_");
path = path.replace(""", "_");
path = path.replace("<", "_");
path = path.replace("|", "_");
path = path.replace(">", "_");
}
return path;
}
}
3、这段代码简单修改就可以用到自己的项目中了
‘捌’ Android-Android用query怎么进行多条件查询
SQLiteDatabase db=dbHelper.getWritableDatabase();
db.delete("record","pulse=?and dia_pre=?"世闭,new String[]{record.get_pulse(),record.get_dia_pre()});//删除所有pulse等于给定值并且dia_pre等于给定值的记茄桐录
Cursor cursor=db.query("record",null,"sys_pre>?and dia_pre<?",new String[]{"120","85"},null,null,null);//多条件查询记得String是数颤返坦组
‘玖’ android数据库查询query的“不等于”条件怎么写
不等于皮扮是"<>"。
示隐握者灶薯例:
SELECT*FROMPersonsWHERECity<>'Beijing'查询数据库表Persons中,City字段不等于Beijing的记录。
‘拾’ Arcgis for Android identify 和query查询遇到的问题,求教
1、QueryTask:是一个进行空间和属性查询的功能类,它可以在某个地图服务的某个子图层内进行查询,顺便提一下的是,QueryTask进行查询的地图服务并不必须加载到Map中进行显示。QueryTask的执行需要两个先决条件:闷腊戚一个是需要查询的图层URL、一个是进行查询的过滤条件。
下面是QueryTask的基本过程:
//新建一个QueryTask
QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5");
// Query对象
Query query = new Query();
//传入空间几何范围,可以不设置
//合法的geometry类型是Extent, Point, Multipoint, Polyline, Polygon
query.Geometry = geometry;
//是否返回查询结果的空间几何信息
query.ReturnGeometry = true;
//查询结果返回的字段,字段必须在图层中,字段的大小写可忽略
query.OutFields.AddRange(new string[] { "AREANAME", "POP2000" });
//quer.OutField.Add("*"局弯); //返回所有字段
//查询的where条件,可以是任何合法的SQL语句,可以不设置
query.Where = "POP2000 > 350000";
//异步查询,需要绑定queryTask的两个事件,通过ExecuteCompleted得到查询结果
queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
queryTask.Failed += QueryTask_Failed;
queryTask.ExecuteAsync(query);
//同步查询,不需要绑定事件,直接返回查询结果
//FeatureSet featureSet = queryTask.Execute(query);
2、蚂陵FindTask:允许对地图中一个或多个图层的要素进行基于属性字段值的查询(search one or more layers in a map for features with attribute values that match or contain an input value)。FindTask不能进行“空间查询”,因为FindTask可以对多个图层进行查询,所有它的url属性需要指向所查询的地图服务的REST URL,而不像QueryTask需要指定某个图层的URL。
下面是FindTask的基本过程:
//新建一个Find task
FindTask findTask = new FindTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/");
//异步执行,绑定事件
findTask.ExecuteCompleted += FindTask_ExecuteCompleted;
findTask.Failed += FindTask_Failed;
//初始化FindParameters参数
FindParameters findParameters = new FindParameters();
findParameters.LayerIds.AddRange(new int[] { 3 }); //查找的图层
findParameters.SearchFields.AddRange(new string[] { "NAME" }); //查找的字段范围
findParameters.ReturnGeometry = true;
findParameters.SearchText = FindTextBox.Text; //查找的“属性值”
//设置查询的LayerDefinitions
ESRI.ArcGIS.Client.LayerDefinition myDefinition = new ESRI.ArcGIS.Client.LayerDefinition();
myDefinition.LayerID = 3;
//设置LayerDefinition,属性字段“Name”属于ID为0的图层
//LayerDefinition的设置语句和Query中的Where语句一样
myDefinition.Definition = "NAME = 'XXX'";
//创建一个ObservableCollection,add设置的LayerDefinition
System.Collections.ObjectModel.ObservableCollection<LayerDefinition> myObservableCollection =
new System.Collections.ObjectModel.ObservableCollection<LayerDefinition>();
myObservableCollection.Add(myDefinition);
findParameters.LayerDefinitions = myObservableCollection; //设置查询的LayerDefinitions
//异步执行
findTask.ExecuteAsync(findParameters);
3、IdentifyTask:是一个在地图服务中识别要素(Feature)的功能类。通过IdentifyTask可以搜索地图层中与输入几何形相交的要素(search the layers in a map for features that intersect an input geometry)。因为也是在多个图层中查询,所以Task的URL是动态图层服务的地址。同样,返回的要素都可以作为Graphic被添加到地图的GraphicsLayer上。
基本过程如下:
//新建一个Identify task
IdentifyTask identifyTask = new IdentifyTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer");
//异步执行,绑定事件
identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
identifyTask.Failed += IdentifyTask_Failed;
//初始化 Identify parameters
IdentifyParameters identifyParameters = new IdentifyParameters();
identifyParameters.LayerOption = LayerOption.all;
//传递地图属性给 identify parameters
identifyParameters.MapExtent = MyMap.Extent;
identifyParameters.Width = (int)MyMap.ActualWidth;
identifyParameters.Height = (int)MyMap.ActualHeight;
//输入的几何参数为一个点,args来自点击事件
identifyParameters.Geometry = args.MapPoint; //Point Envelop Extent polyline polygon
//设置查询的LayerDefinitions
ESRI.ArcGIS.Client.LayerDefinition myDefinition = new ESRI.ArcGIS.Client.LayerDefinition();
myDefinition.LayerID = 3;
//设置LayerDefinition,属性字段“Name”属于ID为0的图层
//LayerDefinition的设置语句和Query中的Where语句一样
myDefinition.Definition = "NAME = 'XXX'";
//创建一个ObservableCollection,add设置的LayerDefinition
System.Collections.ObjectModel.ObservableCollection<LayerDefinition> myObservableCollection =
new System.Collections.ObjectModel.ObservableCollection<LayerDefinition>();
myObservableCollection.Add(myDefinition);
identifyParameters.LayerDefinitions = myObservableCollection; //设置查询的LayerDefinitions
//异步执行
identifyTask.ExecuteAsync(identifyParameters);
三种查询的返回结果:
QueryTask:返回的是一个FeatureSet。Featureset.features[i]可以加入到GraphicsLayer上显示,也可以通过Attributes属性字段得到属性信息。
FindTask:返回的是一个FindResults数组, FindResults[i].feature可以加入到GraphicsLayer上显示,也可以通过Attributes属性字段得到属性信息。
IdentifyTask:返回的是一个IdentifyResults数组,IdentifyResults[i].feature可以加入到GraphicsLayer上显示,也可以通过Attributes属性字段得到属性信息。