首页 文章 精选 留言 我的

精选列表

搜索[网站开发],共10000篇文章
优秀的个人博客,低调大师

Android开发之自定义万能BaseAdapter

话不多说哦,直接上模板: package com.zyzpp.adapter; import android.content.Context; import android.util.SparseArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; public abstract class MyAdapter<T> extends BaseAdapter { private ArrayList<T> mData; private int mLayoutRes; //布局id public MyAdapter() { } public MyAdapter(ArrayList<T> mData, int mLayoutRes) { this.mData = mData; this.mLayoutRes = mLayoutRes; } @Override public int getCount() { return mData != null ? mData.size() : 0; } @Override public T getItem(int position) { return mData.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = ViewHolder.bind(parent.getContext(), convertView, parent, mLayoutRes , position); bindView(holder, getItem(position)); return holder.getItemView(); } public abstract void bindView(ViewHolder holder, T obj); //添加一个元素 public void add(T data) { if (mData == null) { mData = new ArrayList<>(); } mData.add(data); notifyDataSetChanged(); } //往特定位置,添加一个元素 public void add(int position, T data) { if (mData == null) { mData = new ArrayList<>(); } mData.add(position, data); notifyDataSetChanged(); } public void remove(T data) { if (mData != null) { mData.remove(data); } notifyDataSetChanged(); } public void remove(int position) { if (mData != null) { mData.remove(position); } notifyDataSetChanged(); } public void clear() { if (mData != null) { mData.clear(); } notifyDataSetChanged(); } public static class ViewHolder { private SparseArray<View> mViews; //存储ListView 的 item中的View private View item; //存放convertView private int position; //游标 private Context context; //Context上下文 //构造方法,完成相关初始化 private ViewHolder(Context context, ViewGroup parent, int layoutRes) { mViews = new SparseArray<>(); this.context = context; View convertView = LayoutInflater.from(context).inflate(layoutRes, parent, false); convertView.setTag(this); item = convertView; } //绑定ViewHolder与item public static ViewHolder bind(Context context, View convertView, ViewGroup parent, int layoutRes, int position) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(context, parent, layoutRes); } else { holder = (ViewHolder) convertView.getTag(); holder.item = convertView; } holder.position = position; return holder; } @SuppressWarnings("unchecked") public <T extends View> T getView(int id) { T t = (T) mViews.get(id); if (t == null) { t = (T) item.findViewById(id); mViews.put(id, t); } return t; } /** * 获取当前条目 */ public View getItemView() { return item; } /** * 获取条目位置 */ public int getItemPosition() { return position; } /** * 设置文字 */ public ViewHolder setText(int id, CharSequence text) { View view = getView(id); if (view instanceof TextView) { ((TextView) view).setText(text); } return this; } /** * 设置图片 */ public ViewHolder setImageResource(int id, int drawableRes) { View view = getView(id); if (view instanceof ImageView) { ((ImageView) view).setImageResource(drawableRes); } else { view.setBackgroundResource(drawableRes); } return this; } /** * 设置点击监听 */ public ViewHolder setOnClickListener(int id, View.OnClickListener listener) { getView(id).setOnClickListener(listener); return this; } /** * 设置可见 */ public ViewHolder setVisibility(int id, int visible) { getView(id).setVisibility(visible); return this; } /** * 设置标签 */ public ViewHolder setTag(int id, Object obj) { getView(id).setTag(obj); return this; } /** * 设置文字and颜色 */ public ViewHolder setTextAndColor(int id, CharSequence text,int color) { View view = getView(id); if (view instanceof TextView) { ((TextView) view).setText(text); ((TextView) view).setTextColor(color); } return this; } //其他方法可自行扩展 } } 下面说一下ListView(GridView)的使用流程: private void useListView() { //绑定View listview = (ListView) view.findViewById(R.id.grid_ico); //添加头部View listview.addHeaderView(headview); //添加数据 mData = new ArrayList<>(); mData.add(new ListItem(R.mipmap.dot, "这是自定义JavaBean")); //添加数据源 mAdapter = new MyAdapter<ListItem>(mData, R.layout.item_grid_icon) { @Override public void bindView(ViewHolder holder, ListItem obj) { holder.setImageResource(R.id.img_icon, obj.getId()); holder.setText(R.id.txt_js, obj.getContent()); } }; //把数据源set进视图 listview.setAdapter(mAdapter); //监听点击事件 listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getActivity(), "你点击了~" + position + "~项", Toast.LENGTH_SHORT).show(); switch (position) { case 1: break; } } }); //监听长按事件 listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getActivity(), "你长按了第~" + position + "~项", Toast.LENGTH_SHORT).show(); return true; //默认不处理返回false } }); }

优秀的个人博客,低调大师

iOS开发之将XML转换成树II

前面一篇文章,很好将xml转换成树,并进行操作,但是忽略了对xml节点上属性的操作,现在让我来修改代码,将属性添加进来。 1、在treenode中加一个类型为NSDictionary的attributeDict用于存放属性。代码如下: NSDictionary * attributeDict; 2、在中可以在parser:didStartElement:方法中取到属性列表,在其中添加添加下面代码。 leaf.attributeDict = [[ NSDictionary alloc] initWithDictionary:attributeDict]; 3、修改样例xml。 <? xml version="1.0" encoding="UTF-8"?> < Login > < LoginResult id="1">True</ LoginResult > < LoginInfo >OK</ LoginInfo > < LastLogin >2011-05-09 12:20</ LastLogin > < Right > < A >1</ A > < B >1</ B > < C >0</ C > </ Right > </ Login > 4、取属性id的值。 TreeNode * resultTreeNode = [node objectForKey:@ "LoginResult" ]; NSString *result = [resultTreeNode.attributeDict objectForKey:@ "id" ]; 本文转自麒麟博客园博客,原文链接:http://www.cnblogs.com/zhuqil/archive/2011/07/27/2117904.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

使用Spring Boot来加速Java web项目的开发

我想,现在企业级的Java web项目应该或多或少都会使用到Spring框架的。 回首我们以前使用Spring框架的时候,我们需要首先在(如果你使用Maven的话)pom文件中增加对相关的的依赖(使用gradle来构建的话基本也一样)然后新建Spring相关的xml文件,而且往往那些xml文件还不会少。然后继续使用tomcat或者jetty作为容器来运行这个工程。基本上每次创建一个新的项目都是这么一个流程,而我们有时候仅仅想快速的创建一个Spring web工程来测试一些东西,或者是希望能节省时间。 现在我们使用Spring Boot就可以快速的做到这些了。 我们先来看一个非常简单的使用Spring boot的例子吧: 1. 我们创建一个Maven工程,假定工程名字为spring-boot,然后我们在pom.xml文件中加入依赖: 1 2 3 4 5 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version> 1.0 . 2 .RELEASE</version> </dependency> 2. 新建一个Controller来接受处理我们的请求: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; /** * Created by wenchao.ren on 2014/4/26. */ @Controller @EnableAutoConfiguration public class SimpleController { @RequestMapping (value = "/hello" , method = RequestMethod.GET) @ResponseBody public String hello(){ return "hello world" ; } public static void main(String[] args) { SpringApplication.run(SimpleController. class , args); } } 相信大家已经看到了这个Controller有一个main方法,不要急,我们直接运行这个main方法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | ' _| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1. 0.2 .RELEASE) 2014 - 04 - 26 22 : 54 : 40.985 INFO 7236 --- [ main] c.r.spring.boot.SimpleController : Starting SimpleController on rollen with PID 7236 (D:\workspace\GitHub\SpringDemo\spring-boot\target\classes started by wenchao.ren in D:\workspace\GitHub\SpringDemo\spring-boot) 2014 - 04 - 26 22 : 54 : 41.008 INFO 7236 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext @50de0926 : startup date [Sat Apr 26 22 : 54 : 41 CST 2014 ]; root of context hierarchy 2014 - 04 - 26 22 : 54 : 41.583 INFO 7236 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080 2014 - 04 - 26 22 : 54 : 41.706 INFO 7236 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2014 - 04 - 26 22 : 54 : 41.706 INFO 7236 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/ 7.0 . 52 2014 - 04 - 26 22 : 54 : 41.785 INFO 7236 --- [ost-startStop- 1 ] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2014 - 04 - 26 22 : 54 : 41.785 INFO 7236 --- [ost-startStop- 1 ] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 779 ms 2014 - 04 - 26 22 : 54 : 42.055 INFO 7236 --- [ost-startStop- 1 ] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2014 - 04 - 26 22 : 54 : 42.057 INFO 7236 --- [ost-startStop- 1 ] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [ /*] 2014-04-26 22:54:42.289 INFO 7236 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/ favicon.ico] onto handler of type [ class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2014 - 04 - 26 22 : 54 : 42.368 INFO 7236 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.rollenholt.spring.boot.SimpleController.hello() 2014 - 04 - 26 22 : 54 : 42.376 INFO 7236 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [ class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2014 - 04 - 26 22 : 54 : 42.377 INFO 7236 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [ class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2014 - 04 - 26 22 : 54 : 42.447 INFO 7236 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2014 - 04 - 26 22 : 54 : 42.459 INFO 7236 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 /http 2014 - 04 - 26 22 : 54 : 42.460 INFO 7236 --- [ main] c.r.spring.boot.SimpleController : Started SimpleController in 1.675 seconds (JVM running for 1.944 ) 2014 - 04 - 26 22 : 54 : 54.963 INFO 7236 --- [nio- 8080 -exec- 1 ] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2014 - 04 - 26 22 : 54 : 54.963 INFO 7236 --- [nio- 8080 -exec- 1 ] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet' : initialization started 2014 - 04 - 26 22 : 54 : 54.971 INFO 7236 --- [nio- 8080 -exec- 1 ] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet' : initialization completed in 8 ms 会产生上面的输出,查看日志可以发现默认使用的是tomcat,端口绑定在8080,现在让我们来访问:http://localhost:8080/hello 就可以看到我们代码中输出的字样:hello world了。 回首这个过程,是不是相比于以前快速了许多呢 参考资料: 1. Spring Boot Reference Guide ============================================================================== 本文转自被遗忘的博客园博客,原文链接:http://www.cnblogs.com/rollenholt/p/3693055.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS开发之在google地图上显示自己的位置

一行代码显示你的位置 iOS中的MapKit集成了定位的功能,使用一行代码就可以在google地图上展示出自己当前的位置,代码如下: -( IBAction ) showLocation:( id ) sender { if ([[btnShowLocation titleForState:UIControlStateNormal] isEqualToString:@ "Show My Location" ]) { [btnShowLocation setTitle:@ "Hide My Location" forState:UIControlStateNormal]; mapView.showsUserLocation = YES ; } else { [btnShowLocation setTitle:@ "Show My Location" forState:UIControlStateNormal]; mapView.showsUserLocation = NO ; } } 关键的代码就是:mapView.showUserLocation=YES. 使用CLLocationManager和MKMapView 还有就是通过CoreLocation框架写代码去请求当前的位置,一样也非常简单: 第一步:创建一个CLLocationManager实例 CLLocationManager *locationManager = [[CLLocationManager alloc] init]; 第二步:设置CLLocationManager实例委托和精度 locationManager.delegate = self ; locationManager.desiredAccuracy = kCLLocationAccuracyBest; 第三步:设置距离筛选器distanceFilter,下面表示设备至少移动1000米,才通知委托更新 locationManager.distanceFilter = 1000.0f; 或者没有筛选器的默认设置: locationManager.distanceFilter = kCLDistanceFilterNone; 第四步:启动请求 [locationManager startUpdatingLocation]; 使用下面代码停止请求: [locationManager stopUpdatingLocation]; CLLocationManagerDelegate委托 这个委托中有:locationManager:didUpdateToLocation:fromLocation方法,用于获取经纬度。 可以使用下面代码从CLLocation 实例中获取经纬度 CLLocationDegrees latitude = theLocation.coordinate.latitude; CLLocationDegrees longitude = theLocation.coordinate.longitude; 使用下面代码获取你的海拔: CLLocationDistance altitude = theLocation.altitude; 使用下面代码获取你的位移: CLLocationDistance distance = [fromLocation distanceFromLocation:toLocation]; 总结:本文主要是讲解了如何在iOS设备google地图上展示自己的当前位置。 本文转自麒麟博客园博客,原文链接:http://www.cnblogs.com/zhuqil/archive/2011/07/13/2105013.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android开发实践:实战演练隐式Intent的用法

任务:假设我们已经实现了一个视频播放器(PlayerActivity),我们希望能把它注册到系统中,当用户点击本地视频或者在线视频时,能启动这个视频播放器。 (假设该类的全路径为:com.jhuster.videoplayer.PlayerActivity) [注]:本文完整的示例代码请到我的Github下载,地址:VideoPlayer 1. 什么是隐式Intent? Intent是Android中比较重要的组件,常用来启动一个新的Activity或者Service、广播某个事件,以及在Android组件之间传递数据。通过Intent来启动新的Activity或者Service通常有两种方法,一种是显示启动,另一种是隐式启动。 显示启动就是在明确指出要启动的Activity或者Service的类或者包名。例如: 1 2 3 4 5 6 7 8 9 10 Intentintent=newIntent( this ,PlayerActivity. class ); startActivity(intent); Intentintent= new Intent(); intent.setClass( this ,PlayerActivity. class ); startActivity(intent); Intentintent= new Intent(); intent.setClassName(“com.jhuster.videoplayer”,“com.jhuster.videoplayer.PlayerActivity”); startActivity(intent); 隐式启动则是不明确指定启动哪个Activity或者Service,而是通过设置Action、Data、Category,让系统来筛选出合适的目标。 例如拨打电话: 1 2 Intentintent= new Intent(Intent.ACTION_DIAL,Uri.parse(“tel: 021 - 80961111 ”)); startActivity(intent); 系统接收到隐式启动请求后,会根据系统中各个Activity在AndroidManifest.xml文件中声明的<intent-filter>来比较和判断是否匹配当前的Intent请求的。 因此,如果我们希望PlayerActivity能够被系统隐式启动,则首先需要在AndroidManifest.xml文件中为该Activity添加<intent-filter>. 2. 为PlayerActivity添加<intent-filter> <intent-filter>的标签有很多,这里只介绍和添加最基本且最常用的三个标签,分别是<action>,<category>和<data>。 2.1 添加<action> 这个标签是必须添加的,可以自己定义,也可以使用系统预定义的变量,Android系统默认定义了很多action,具体可以查看SDK文档,或者Google一下“android.intent.action.”。 这里,因为我们的类是用来“播放视频”的,因此可以使用系统预定义的:android.intent.action.VIEW,它表示需要启动某个Activity显示指定的数据(包括图片、视频、文档等)。 添加了<action>后的<activity>如下所示: 1 2 3 4 5 <activityandroid:name= "com.jhuster.videoplayer.PlayerActivity" > <intent-filter> <actionandroid:name= "android.intent.action.VIEW" /> </intent-filter> </activity> 2.2 添加<category> category代表类别,定义了Activity的类别,Activity可以设置一个或者多个category标签。常用的一般有3个:DEFAULT,HOME,LAUNCHER 1 2 3 DEFAULT默认动作 HOME设置为本地桌面应用 LAUNCHER本APP的启动Activity 本应用中我们使用DEFAULT类别即可,DEFAULT也是category最常用的选项。 添加了category后的<activity>如下所示: 1 2 3 4 5 6 <activityandroid:name= "com.jhuster.videoplayer.PlayerActivity" > <intent-filter> <actionandroid:name= "android.intent.action.VIEW" /> <categoryandroid:name= "android.intent.category.DEFAULT" /> </intent-filter> </activity> 2.3 添加<data> data 代表数据源,是<intent-filter>中最复杂的标签,因为不同的Activity支持的数据来源和类型多种多样,所以需要通过详细的data标签信息来指明。 data 标签有很多属性,包括: 1 2 3 4 5 android:host:指定主机名,例如:google.com android:port:制定主机端口,例如:80 android:path:指定URL的有效路径值,例如:/index/examples android:mimeType:指定组件可以执行的数据类型,例如:image/jpeg,video/* android:scheme:指定特定的模式,例如:content,http 这里,假设我们的视频播放器支持多种数据来源,包括:本地视频文件,本地媒体URL,网络视频流(HTTP、RTMP、RTSP协议),另外,假设我们的视频播放器只支持mp4和3gpp两种文件格式。 那么,下面我们来添加两种最常用的<data>标签,scheme和mimeType,并且解释每条标签对应的是怎样的一种数据来源或者数据格式。 (1) <data android:scheme="xxx"/> 这里的xxx可以是:file,content,网络协议(HTTP,RTMP、RTSP等) 本应用中我们给PlayerActivity的<Intent-filter>中添加: 1 2 3 4 < data android:scheme = "file" /> < data android:scheme = "content" /> < data android:scheme = "http" /> < data android:scheme = "rtsp" /> 添加了这样几条data标签项之后,如果隐式Intent中的数据来源URL是以“file://”、“content://”、“http://”、“rtsp://”开头的URL资源,都会隐式地启动我们的PlayerActivity。 例如,其他的Activity可以通过下面的方法来隐式启动我们的PlayerActivity. 1 2 3 Intentintent= new Intent(Intent.ACTION_VIEW); intent.setData(Uri.fromFile( new File( "/sdcard/test.3gp" ))); startActivity(intent); Uri.fromFile这条语句会把指定的文件位置转换为以“file://”开头的Uri对象,如上述例子最终得到的URL为:“file:///sdcard/test.3gp” 同理,可以通过Uri.parse来转换我们常见的网络地址字符串为Uri对象,例如: 1 2 3 Intentintent= new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse( "http://ticktick.blog.51cto.com/test.mp4" )); startActivity(intent); (2) <data android:mimeType="xxx"/> mimeType用来设置数据类型,例如图像数据(image/png或者image/*),视频数据(video/mp4或者video/*),如果使用*代表匹配所有的子类型。 MIME TYPE是互联网的一种标记数据类型的标准,现在已经支持非常多的类型了,这里我不一一列举,大家可以在Google上搜索一下。 本应用中我们假设需要支持的是mp4和3gpp两种类型,那么,我们可以添加这样两条 mimeType : 1 2 <dataandroid:mimeType= "video/3gpp" /> <dataandroid:mimeType= "video/mp4" /> 那么,其他的Activity就可以通过下面的方法来隐式启动我们的PlayerActivity. 注意,当<Intent-filter>已经添加了mimeType之后,隐式Intent必须设置Type参数才能匹配到该Activity,所以建议使用setDataAndType方法,而不是单一的setData方法。 1 2 3 Intentintent= new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile( new File( "/sdcard/test.3gp" )), "video/3gpp" ); startActivity(intent); 当然,这里的"video/3gpp"也可以写成:"video/*",但这样可能会匹配到一些不支持3gpp的播放器。 (3) 小结 添加了<data>标签后的<intent-filter>如下所示: 1 2 3 4 5 6 7 8 9 10 11 12 13 < activity android:name = "com.jhuster.videoplayer.PlayerActivity" > < intent-filter > < action android:name = "android.intent.action.VIEW" /> < category android:name = "android.intent.category.DEFAULT" /> < data android:scheme = "file" /> < data android:scheme = "content" /> < data android:scheme = "http" /> < data android:scheme = "rtsp" /> < data android:scheme = "rtmp" /> < data android:mimeType = "video/3gpp" /> < data android:mimeType = "video/mp4" /> </ intent-filter > </ activity > 3. 在PlayerActivity中获取参数 通过上面的介绍,我们已经知道了怎样添加<intent-filter>以及怎样通过隐式Intent来调用我们的PlayerActivity,那么,下面我们还要了解如何在PlayerActivity中解析来自隐式Intent的参数。 其实,Intent提供了很多方法可以Get相关的参数信息,例如: 1 2 3 4 public StringgetAction(); public UrigetData(); public StringgetScheme(); public StringgetType(); 上述方法分别可以获取Intent的Action,Data Uri,Scheme和MimeType值。 对于“file://”开头的Uri对象,我们可以通过Uri.getPath方法得到去除了“file://”前缀的具体文件地址。例如: “file:///sdcard/test.mp4”则可以转换为实际的“/sdcard/test.mp4”。 对于网络码流,例如:“http://”、“rtsp://”等开头的Uri,则可以直接通过toString()方法转换为实际地址的字符串。 而对于“content://”开头的URI对象,一般是从系统的媒体数据库中检索出来的结果,因此需要反向查找得到实际的文件地址,这里提供一个函数进行转换。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public static StringgetVideoPath(Contextcontext,Uriuri){ UrivideopathURI=uri; if (uri.getScheme().toString().compareTo( "content" )== 0 ){ Cursorcursor=context.getContentResolver().query(uri, null , null , null , null ); if (cursor.moveToFirst()){ int column_index=cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); videopathURI=Uri.parse(cursor.getString(column_index)); return videopathURI.getPath(); } } else if (uri.getScheme().compareTo( "file" )== 0 ){ return videopathURI.getPath(); } return videopathURI.toString(); } 本文转自 Jhuster 51CTO博客,原文链接:http://blog.51cto.com/ticktick/1621957,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册