精华内容
下载资源
问答
  • provider

    2010-04-28 23:52:00
    In file ../../src/Pegasus/Provider/CIMProvider.h: class PEGASUS_PROVIDER_LINKAGE CIMProviderParent class for all provider interfaces.DocumentationParent class for all provider in

    In file ../../src/Pegasus/Provider/CIMProvider.h:

    class PEGASUS_PROVIDER_LINKAGE CIMProvider

    Parent class for all provider interfaces.

    Documentation

    Parent class for all provider interfaces.

    The CIMProvider is the parent class for all provider interface types. The currently supported interfaces are:

    • CIMInstanceProvider - supports manipulation of CIM instances and their properties
    • CIMMethodProvider - supports invocation of methods defined on CIM instances
    • CIMAssociationProvider - supports query of CIM Associaitons and their properties. This provider interfaces provides both reference and associatior query operations in accordance with the DMTF Cim Operation specifications

    A provider may inherit from any of these interface classes or all of them. A provider MUST implement every function in the chosen interface(s). However, it is not required that all operations be supported. If an operation is not supported, then a minimal implementation of the corresponding function must throw a {@link NotSupported NotSupported} exception.

    Certain parameters are passed in several of the functions in the provider interfaces. These are also described in their own sections, and include:

    • OperationContext - contains information about the client's context, including the User ID. The provider must determine whether the specified user should be permitted to perform the operation. If the operation should not be permitted, the provider must throw an AccessDenied exception.

    • CIMObjectPath - specifies the CIM object on which the operation is to be performed. This parameter specifies the hostname, namespace, classname, and key values that uniquely identify an instance of a CIM object.

      hostname - specifies the name of the system on which the object resides. This does not need to be the system that the CIM server is running on, but it generally will be the same system.

      namespace - this CIMNamespaceName object specifies the namespace on the aforementioned host in which the object resides.

      classname - specifies the class on which the requested operation is to be performed.

      keybindings - thisCIMKeyBinging object specifies the set of key properties for the aforementioned class. The set of keys uniquely identifies a CIM instance in the host and namespace. It is permissible for clients to specify, and providers should accept, empty strings for key values when this would not be ambiguous. If the specification is ambiguous, or if a key name is invalid or missing, the provider should throw an InvalidParameter exception.

    • CIMInstance - contains a representation of an instance of a CIM object to be used by the requested operation. This parameter should contain all of the key properties, as well as all properties necessary to perform the requested operation.

    • CIMPropertyList - specifies the properties on which this operation should be performed. The exact use of this parameter depends on the specific operation, and is described in the respective section.

    • ResponseHandler - a callback handle used to return results to the CIM Server for subsequent return to the client.

    Certain exceptions can be thrown by several of the functions in the provider interfaces. These are described in their own sections, and include:

    The CIMProvider interface contains two functions that are inherited by all provider interfaces:

    • initialize - Called before the first call to any client-requested operation; the provider should perform any processing that may be required before normal operation can begin.
    • terminate - Called prior to the provider being stopped; the provider should perform any final processing that may be required.

    Providers must implement these functions. A minimal implementation may simply return to the caller.


    Inheritance:


    Public Methods

    [more] CIMProvider (void)
    Creates a CIMProvider instance with null values (default constructor) [more]virtual ~CIMProvider (void)
    CIMProvider destructor [more]virtual void initialize (CIMOMHandle & cimom)
    Performs any setup required before normal operation of the provider. [more]virtual void terminate (void)
    Performs any cleanup required before termination. [more]virtual Boolean tryTerminate (void)
    Allows a provider to decline a terminate call. o CIMProvider(void) Creates a CIMProvider instance with null values (default constructor)

    ovirtual ~CIMProvider(void) CIMProvider destructor

    ovirtual void initialize(CIMOMHandle & cimom) = 0 Performs any setup required before normal operation of the provider.

    The initialize() function allows the provider to conduct the necessary preparations to handle requests. The initialize function is called only once during the lifetime of the provider. Note, however, that with the Pegasus automatic unload function enabled, a provider many be unloaded and loaded many times during one cycle of the CIMOM. This function must complete before the CIM server invokes any other function of the provider, other than terminate.

    Parameters:
    cimom - Reserved for future use.

    ovirtual void terminate(void) = 0 Performs any cleanup required before termination.

    The terminate function allows the provider to conduct the necessary preparations for termination. This function may be called by the CIM Server at any time, including initialization. Once invoked, no other provider functions are invoked until after a call to initialize.

    The provider may, for example, do the following in the terminate function:

    • close files or I/O streams
    • release resources such as shared memory
    • inform concurrently executing requests to complete immediately (this may be done by setting a global flag)
    • kill subprocesses
    • and others

    If the provider instance was created on the heap with new in PegasusCreateProvider, then it must be deleted in terminate:

    void MyProvider::terminate()
        {
        ...
        delete this;
        ...
        return;
        }

    ovirtual Boolean tryTerminate(void) Allows a provider to decline a terminate call. If the provider is unable to terminate, it should return false. Otherwise, it calls its terminate() function and then returns true, as in the default implementation.
    Returns:
    False If the provider is unable to terminate; Otherwise, return true.

    展开全文
  • 最近在测试FileProvider相关功能的时候,在从自定义相册选择图片通过FileProvider来获取content uri的时候程序突然崩溃了,报出了 Failed to find configured root that contains xxxx 的错误,一开始以为是自己...

    转载:https://www.jianshu.com/p/ac5fe346a5b7

     

    最近在测试FileProvider相关功能的时候,在从自定义相册选择图片通过FileProvider来获取content uri的时候程序突然崩溃了,报出了

    Failed to find configured root that contains xxxx
    

    的错误,一开始以为是自己的配置出错了,但是参照官方文档改来改去仍然没有任何作用,通过绞尽脑汁地排查,终于发现了错误原因,并找到了正确的解决方案,在了解最终的解决方案之前我们先对FileProvider做个简单的了解和回顾。


    FileProvider简介

    很久之前就知道FileProvider了,然而之前做过的实际项目中却很少用到,一方面自己的项目没有涉及到相关的场景,一方面也是自己对文件安全没有太在意,虽然看官方文档的时候多次读过,却从来没想到去使用它。

    但随着Android 7.0的到来,为了进一步提高私有文件的安全性,Android不再由开发者放宽私有文件的访问权限,之前我们一直使用"file:///"绝对路径来传递文件地址的方式,在接收方访问时很容易触发SecurityException的异常。

    因此,为了更好的适配Android 7.0,例如相机拍照这类涉及到文件地址传递的地方就用上了FileProvider,FileProvider也更好地进入了大家的视野。

    其实FileProvider是ContentProvider的一个特殊子类,本质上还是基于ContentProvider的实现,FileProvider会把"file:///"的路径转换为特定的"content://"形式的content uri,接收方通过这个uri再使用ContentResolver去媒体库查询解析。


    FileProvider使用方法:

    1. 在AndroidManifest.xml里声明Provider
    
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.myapp"> 
          <application        
              ...>  
              <provider     
                  android:name="android.support.v4.content.FileProvider" //指向v4包里的FileProviderandroid:authorities="com.example.myapp.fileprovider" //对应你的content uri的基础域名,生成的uri将以content://com.example.myapp.fileprovider作为开头
                  android:grantUriPermissions="true" //设置允许获取访问uri的临时权限
                  android:exported="false"//设置不允许导出,我们的FileProvider应该是私有的
              >            
              <meta-data
                  android:name="android.support.FILE_PROVIDER_PATHS" 
                  android:resource="@xml/filepaths" //用于设置FileProvider的文件访问路径
               />        
              </provider>        
              ...    
          </application>
    </manifest>
    

    2.配置FileProvider文件共享的路径

    接下来在我们的res目录下创建一个xml目录,在xml目录下新建一个filepaths.xml,这个xml的名字可以根据项目的具体情况来取,对应第一步中mainifest配置里的FileProvider路径的配置中指定的文件

    
    <paths xmlns:android="http://schemas.android.com/apk/res/android"> 
        <files-path name="my_images" path="images/"/> 
        ...
    </paths>
    

    在<paths>标签中我们必须配置至少一个或多个path子元素,
    path子元素则用来定义content uri所对应的路径目录。
    这里以<files-path>为例:

    • name属性:指明了FileProvider在content uri中需要添加的部分,这里的name为my_images,所以对应的content uri为
    
    content://com.example.myapp.fileprovider/my_images
    
    • path属性:<files-path>标签对应的路径地址为Context.getFilesDir()]()返回的路径地址,而path属性的值则是该路径的子路径,这里的path值为"images/",那组合起来的路径如下所示:
    Content.getFilesDir() + "/images/"
    
    • name属性跟path属性一一对应,根据上面的配置,当访问到文件
    
    content://com.example.myapp.fileprovider/my_images/xxx.jpg
    

    就会找到这里配置的path路径

    Content.getFilesDir() + "/images/"
    

    并查找xxx.jpg文件

    对应路径的配置,官方文档列出了如下配置项:

    <files-path name="*name*" path="*path*" />
    

    对应 Context.getFilesDir() 的路径地址

    <cache-path name="*name*" path="*path*" />
    

    对应 getCacheDir() 获取的路径

    <external-path name="*name*" path="*path*" />
    

    对应 Environment.getExternalStorageDirectory()的路径地址

    <external-files-path name="*name*" path="*path*" />
    

    对应Context#getExternalFilesDir(String) Context.getExternalFilesDir(null) 返回的路径地址

    <external-cache-path name="*name*" path="*path*" />
    

    对应 Context.getExternalCacheDir() 返回的地址
    .
    以此类推,我们可以根据自己所需共享的目录来配置不同的path路径.

    3.配置完共享地址后,获取content uri的值,这个uri即提供给第三方进行访问的uri地址

    
    File imagePath = new File(Context.getFilesDir(), "images");
    File newFile = new File(imagePath, "default_image.jpg");
    Uri contentUri = getUriForFile(getContext(), "com.mydomain.fileprovider", newFile);
    

    4.授予一个uri的临时权限,并将值传给接收方app
    我们假设接收方app使用startActivityForResult来请求app的图片资源,
    则请求方获取请求后根据上面的代码获取

    
    Intent intent = new Intent()
    intent.setDataAndType(fileUri,getContentResolver().getType(fileUri));
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    setResult(intent);
    
    
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    

    用来授予接收方对于文件操作的临时权限,可以设置为 FLAG_GRANT_READ_URI_PERMISSION
    FLAG_GRANT_WRITE_URI_PERMISSION
    或者两者都允许

    5.接收方在onActivityResult里根据获取的content uri来查询数据

    
    Uri returnUri = returnIntent.getData();    
    Cursor returnCursor =  getContentResolver().query(returnUri, null, null, null, null);    
    int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);   
    int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
    returnCursor.moveToFirst();    
    TextView nameView = (TextView) findViewById(R.id.filename_text); 
    TextView sizeView = (TextView) findViewById(R.id.filesize_text); 
    nameView.setText(returnCursor.getString(nameIndex)); 
    sizeView.setText(Long.toString(returnCursor.getLong(sizeIndex)));
    

    这下我们FileProvider的整个使用流程就完整了


    FileProvider的坑(Failed to find configured root that contains)

    failed to find configured root that contains
    

    经过对FileProvider的进一步了解和巩固,终于到了揭开错误原因的时候了

    原来手上这台红米手机的相册选择了存储位置在外置SD卡上,因此部分相册照片的存放地址实际上是在外置sd卡上的。
    下面是我的path配置

    <paths xmlns:android="http://schemas.android.com/apk/res/android>
        <external-path name="external_files" path="."/>
    </paths>
    

    乍一看貌似没什么问题,path设置的是external的根路径,对应Environment.getExternalStorageDirectory()
    然而这个方法所获取的只是内置SD卡的路径,所以当选择的相册中的图片是外置SD卡的时候,就查找不到图片地址了,因此便抛出了failed to find configured root that contains的错误。

    那怎么解决呢,官方文档给出的配置项并没有能够对应外部地址的,那我们只有从FileProvider的源码入手看看有没有什么办法了.

    因为FileProvider是通过path的配置来限制路径范围的,因此我们可以通过path的解析作为入口点来进行分析,
    于是乎便找到了parsePathStrategy()这个方法,
    它就是专门用来解析我们的path路径的xml文件的.

    
    private static final String TAG_ROOT_PATH = "root-path";
    private static final String TAG_FILES_PATH = "files-path";
    private static final String TAG_CACHE_PATH = "cache-path";
    private static final String TAG_EXTERNAL = "external-path";
    
    private static final File DEVICE_ROOT = new File("/");
    
    private static PathStrategy parsePathStrategy(Context context, String authority)        
              throws IOException, XmlPullParserException {    
           ...
          while ((type = in.next()) != END_DOCUMENT) {        
              if (type == START_TAG) {            
                  //<external-path>等根标签
                  final String tag = in.getName();
                  //标签中的name属性
                  final String name = in.getAttributeValue(null, ATTR_NAME);
                  //标签中的path属性  
                  String path = in.getAttributeValue(null, ATTR_PATH);            
                  File target = null;            
                  //标签对比
                  if (TAG_ROOT_PATH.equals(tag)) {                
                      target = buildPath(DEVICE_ROOT, path);            
                  } else if (TAG_FILES_PATH.equals(tag)) {
                      target = buildPath(context.getFilesDir(), path);            
                  } else if (TAG_CACHE_PATH.equals(tag)) {                
                      target = buildPath(context.getCacheDir(), path);            
                  } else if (TAG_EXTERNAL.equals(tag)) {                
                      target = buildPath(Environment.getExternalStorageDirectory(), path);            
                }            
              if (target != null) {                
                  strat.addRoot(name, target);            
              }        
        }    
    }   
     return strat;
    }
    
    
    private static File buildPath(File base, String... segments) {    
        File cur = base;    //根文件
        for (String segment : segments) {        
            if (segment != null) {            
                //创建以cur为根文件,segment为子目录的文件
                cur = new File(cur, segment);       
            }    
        }    
        return cur;
    }
    

    这里我把一些关键代码摘抄了出来,通过这些关键代码我们可以看到,
    在xml解析到对应的标签后,会执行 buildPath() 方法来将根标签(<files-path><external-path>等)对应的路径作为文件根路径,
    同时将标签中的path属性所指定的路径作为子路径创建对应的File对象,最终生成了一个cur文件对象来作为目标文件,从而限制FileProvider的文件访问路径位于cur的path路径下。

    其中一段代码让我发现了一丝异样

     if (TAG_ROOT_PATH.equals(tag)) {                
            target = buildPath(DEVICE_ROOT, path);            
     }
    

    TAG_ROOT_PATH对应了常量"root-path",
    而DEVICE_ROOT则对应了new File("/");
    没错,虽然官方文档没有写出来,但是代码里竟然留了个<root-path>的根标签,而它的路径对应的是DEVICE_ROOT指向的整个存储的根路径。

    于是根据代码的逻辑,将我们的路径的配置文件做了调整,
    改成了

    <paths xmlns:android="http://schemas.android.com/apk/res/android>
          <root-path name="name" path="" />
    </paths>
    

    这时运行程序,会发现FileProvider已经不会报错了,因为文件的搜索路径已经变成了我们客户端的整个根路径,就这样,我们的问题终于得到了顺利地解决!

    通过对FileProvider的源码分析,正如开头所说的,FileProvider继承自ContentProvider,因此还有一种方法就是继承ContentProvider然后自定义Provider来处理,不过FileProvider本身的代码写得已经很完善了,所以一般没有这个必要,这里我给出了一段简易代码仅做参考:
    同样在AndroidManifest里配置我们的provider

    
    <provider    
          android:name="org.test.img.MyProvider"//指向自定义的Provider
          android:authorities="com.test.img" 
    />
    

    然后自定义一个MyProvider

    
    public class MyProvider extends ContentProvider {    
    
      private String mAuthority;
    
      @Override
      public void attachInfo(Context context, ProviderInfo info) {    super.attachInfo(context, info);    // Sanity check our security    
          if (info.exported) {        
              throw new SecurityException("Provider must not be exported");    
          }    
          if (!info.grantUriPermissions) {        
              throw new SecurityException("Provider must grant uri permissions");    
          }    
          mAuthority = info.authority;
      }
    
      @Override    
      public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {        
            File file = new File(uri.getPath());        
            ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file,ParcelFileDescriptor.MODE_READ_ONLY);       
             return parcel;    
      }    
    
      @Override    
      public boolean onCreate() {        
            return true;    
      }   
     
      @Override    
      public int delete(Uri uri, String s, String[] as) {        
          throw new UnsupportedOperationException("Not supported by this provider");   
       }  
      
      @Override    
      public String getType(Uri uri) {        
          throw new UnsupportedOperationException("Not supported by this provider");    
      }
        
      @Override    
      public Uri insert(Uri uri, ContentValues contentvalues) {        
          throw new UnsupportedOperationException("Not supported by this provider");    
      }    
    
      @Override    
      public Cursor query(Uri uri, String[] as, String s, String[] as1, String s1) {        throw new UnsupportedOperationException("Not supported by this provider");   
       }    
    
      @Override    
      public int update(Uri uri, ContentValues contentvalues, String s, String[] as) {        
          throw new UnsupportedOperationException("Not supported by this provider");    
      }
    
      public static Uri getUriForFile(File file) {    
        return new Uri.Builder().scheme("content").authority(mAuthority).encodedPath(file.getPath).build();
      }
    }
    

    这样我们的代码就可以通过自定义的getUriForFile来获取content uri了

    展开全文
  • FileProvider

    千次阅读 2018-06-26 22:39:11
    FileProvider 我对FileProvider的理解 如下: android7.0开始,不再允许在app之间,使用file://的方式传递File,否则会抛出FileUriExposedException异常 1,可以使用FileProvider,content://解决这...

    FileProvider


    我对FileProvider的理解
    如下:

    android7.0开始,不再允许在app之间,使用file://的方式传递File,否则会抛出FileUriExposedException异常

    1,可以使用FileProvider,content://解决这个问题
    2,也可以把targetSdkVersion小于24(<7.0),但我相信不会有人这样做

    FileProvider是ContentProvider的子类,所以需要在 AndroidManifest.xml中配置,使用ContentProvider可以向其他的app分享数据
    FileProvider可将这些数据转换成File文件

    1,AndroidManifest.xml中配置FileProvider(可配置多个)
    这里写图片描述

    name:配置的是FileProvider实现类,这里使用的系统的是v4包下( name就是指定FileProvider
    对于一个 App Module 而言,如果只是自己使用,可以直接使用 v4 包下的 FileProvider ,但是如果是作为一个 Lib Module 来供其他项目使用,最好还是重新空继承一个 FileProvider ,这里填写我们的继承类即可。)
    authorities:配置一个 FileProvider 的名字,它在当前系统内需要是唯一值(一般使用包名)。
    exported:表示 FileProvider 是否需要公开出去
    granUriPermissions:表示是否授权文件的临时访问权限

    meta-data指定FileProvider提供出去的路径
    name:固定写法
    resource指定了一个xml文件夹下的的filepaths文件,文件里面配置了路径(这里是在res下面新建了一个xml文件夹,并且xml中新建一个filepaths.xml)
    这里写图片描述

    filepaths的xml文件
    如下:
    这里写图片描述
    paths必须最少都要配置一个XXXXXX-path标签,而这个标签其实表示的是一个路径

    在FileProvider的类中可以看到
    标签的类型如下:

    private static final String TAG_ROOT_PATH = “root-path”;
    private static final String TAG_FILES_PATH = “files-path”;
    private static final String TAG_CACHE_PATH = “cache-path”;
    private static final String TAG_EXTERNAL = “external-path”;
    private static final String TAG_EXTERNAL_FILES = “external-files-path”;
    private static final String TAG_EXTERNAL_CACHE = “external-cache-path”;

    在parsePathStrategy就可以看到所代表的路径

      private static PathStrategy parsePathStrategy(Context context, String authority)
                throws IOException, XmlPullParserException {
            final SimplePathStrategy strat = new SimplePathStrategy(authority);
    
            final ProviderInfo info = context.getPackageManager()
                    .resolveContentProvider(authority, PackageManager.GET_META_DATA);
            final XmlResourceParser in = info.loadXmlMetaData(
                    context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
            if (in == null) {
                throw new IllegalArgumentException(
                        "Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
            }
    
            int type;
            while ((type = in.next()) != END_DOCUMENT) {
                if (type == START_TAG) {
                    final String tag = in.getName();
    
                    final String name = in.getAttributeValue(null, ATTR_NAME);
                    String path = in.getAttributeValue(null, ATTR_PATH);
    
                    File target = null;
                    if (TAG_ROOT_PATH.equals(tag)) {
                        target = DEVICE_ROOT;
                    } else if (TAG_FILES_PATH.equals(tag)) {
                        target = context.getFilesDir();
                    } else if (TAG_CACHE_PATH.equals(tag)) {
                        target = context.getCacheDir();
                    } else if (TAG_EXTERNAL.equals(tag)) {
                        target = Environment.getExternalStorageDirectory();
                    } else if (TAG_EXTERNAL_FILES.equals(tag)) {
                        File[] externalFilesDirs = ContextCompat.getExternalFilesDirs(context, null);
                        if (externalFilesDirs.length > 0) {
                            target = externalFilesDirs[0];
                        }
                    } else if (TAG_EXTERNAL_CACHE.equals(tag)) {
                        File[] externalCacheDirs = ContextCompat.getExternalCacheDirs(context);
                        if (externalCacheDirs.length > 0) {
                            target = externalCacheDirs[0];
                        }
                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                            && TAG_EXTERNAL_MEDIA.equals(tag)) {
                        File[] externalMediaDirs = context.getExternalMediaDirs();
                        if (externalMediaDirs.length > 0) {
                            target = externalMediaDirs[0];
                        }
                    }
    
                    if (target != null) {
                        strat.addRoot(name, buildPath(target, path));
                    }
                }
            }
    
            return strat;
        }
    

    明显,我的path标签如下:表示的是外部存储

    if (TAG_EXTERNAL.equals(tag)) {
                  target = Environment.getExternalStorageDirectory();
    }
    

    好这里都配置好了,那就开始使用了喔,使用getUriForFile获取需要使用的Uri,参数就是一个context,authorities(配置一个 FileProvider 的名字,它在当前系统内需要是唯一值),然后需要一个文件

    public static Uri getUriForFile(Context context, String authority, File file) {
            final PathStrategy strategy = getPathStrategy(context, authority);
            return strategy.getUriForFile(file);
     }
    

    调用此方法,会自动得到一个 file:// 转换成 content:// 的 一个 Uri 对象,可以供我们直接使用。
    配置 provider 标签的时候,有一个属性 android:grantUriPermissions=“true” ,它表示允许它授予 Uri 临时的权限。

    当我们生成出一个 content:// 的 Uri 对象之后,其实也无法对其直接使用,还需要对这个 Uri 接收的 App 赋予对应的权限才可以。

    这个授权的动作,提供了两种方式来授权
    使用 Context.grantUriPermission() 为其他 App 授予 Uri 对象的访问权限

    toPackage :表示授予权限的 App 的包名。

    uri:授予权限的 content:// 的 Uri。

    modeFlags:前面提到的读写权限。

    这种情况下,授权的有效期限,从授权一刻开始,截止于设备重启或者手动调用 Context.revokeUriPermission() 方法,才会收回对此 Uri 的授权

    配合 Intent.addFlags() 授权。
    既然这是一个 Intent 的 Flag,Intent 也提供了另外一种比较方便的授权方式,那就是使用 Intent.setFlags() 或者 Intent.addFlag 的方式
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

    Intent.addFlags() 的方式,一旦授权将无法主动回收

    拥有了授权权限的 content:// 的 Uri 之后,就可以通过 startXxx 或者 setResult() 的方式,将 Uri 传递给其他的 App

    简单例子:

    String path = Environment.getExternalStorageDirectory().getAbsolutePath()
                    + File.separator +“ImageDir / img.png”
            File imgFile = new File(path);
            if (!imgFile.getParentFile().exists())
                imgFile.getParentFile().mkdirs();
            if (null != imgFile) {
                Uri photoUri;
                Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                takePhotoIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    
                if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
                    photoUri = Uri.fromFile(imgFile);
                } else {
                    /**
                     * 7.0 调用系统相机拍照不再允许使用Uri方式,应该替换为FileProvider
                     * 并且这样可以解决MIUI系统上拍照返回size为0的情况
                     */
                    photoUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", imgFile);
                }
                takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
                context.startActivityForResult(takePhotoIntent, REQUESTCODE);
            }
    
    <paths>
      <external-path path="images/imghead/" name="photos" />
    </paths>
    

    external-path中的name表示什么呢?

    <provider
                android:name="android.support.v4.content.FileProvider"
                android:authorities="${applicationid}.fileprovider"
                android:grantUriPermissions="true"
                android:exported="false">
                <meta-data
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/filepaths" />
            </provider>
    

    如果:
    Environment.getExternalStorageDirectory() 等于 “/storage/emulated/0”

    android系统 会把/storage/emulated/0/images/imghead/
    映射到content://(authorities字段的值)/name/

    假如:
    (authorities字段的值) = “com.android.www”
    name = photos
    拼接起来:content://com.android.www/photos/

    如果发现有错,望告知!!!!

    展开全文
  • 自定义Credential Provider

    热门讨论 2012-04-29 13:11:23
    Credential Provider : 自定义windows登录 修改Register.reg中CredentialProvider dll的文件路径,双击注册. 实现了标准的Credential Provider的登录机制. 安装此Provider,会自动屏蔽windows原有的登录入口, 如果...
  • AngularJs Provider

    2016-09-21 15:54:48
    provider, value, constant, service, factory他们都是provider! eg: $http AngularJs框架提供的provider 1. 为应用提供通用的服务,形式可以是常量或对象 2. 便于模块化 3. 便于单元测试 function provider...

    provider, value, constant, service, factory他们都是provider!

    eg: $http AngularJs框架提供的provider


    function provider(name, provider_) {
        if (isFunction(provider_)) {
            provider_ = providerInjector.instantiate(provider_);
        }
        if (!provider_.$get) {
            throw Error('Provider ' + name + ' must define $get factory method.');
        }
        return providerCache[name + providerSuffix] = provider_;
    }
    
    function factory(name, factoryFn) { return provider(name, { $get: factoryFn }); }
    
    function service(name, constructor) {
        return factory(name, ['$injector', function($injector) {
            return $injector.instantiate(constructor);
        }]);
    }
    
    function value(name, value) { return factory(name, valueFn(value)); }
    
    function constant(name, value) {
        providerCache[name] = value;
        instanceCache[name] = value;
    }
    
    function decorator(serviceName, decorFn) {
        var origProvider = providerInjector.get(serviceName + providerSuffix),
            orig$get = origProvider.$get;
    
        origProvider.$get = function() {
            var origInstance = instanceInjector.invoke(orig$get, origProvider);
            return instanceInjector.invoke(decorFn, null, {$delegate: origInstance});
        };
    }


    展开全文
  • ActionProvider

    2017-07-15 16:42:09
    ActionProviderAndroid Customer ActionProvider使用ActionProvider可以实现option menu的功能,类似微信右上角的图标点击后的效果,这篇文章有详细的描述自定义ActionProvider ToolBar 自定义Menu小红点可以实现...
  • 我这个是android7.0拍照,因为更换头像是自己条用系统的拍照,为了解决Android7.0权限,所以自己在xml中配置了provider,然后项目中有上传多张图片的功能,我是使用的是第三方框架com.lzy.widget:imagepicker,这个...
  • sunjce_provider.jar

    千次下载 热门讨论 2013-02-19 01:26:13
    new com.sun.crypto.provider.SunJCE()
  • Service Provider

    2016-11-01 15:43:20
    转自:http://help.sap.com/saphelp_utilities472/helpdata/en/f1/5dcd3ba9567d78e10000000a11402f/content.htm...Service Provider  Definition The service provider has two main functions in IDE:  1. It
  • 题记 —— 执剑天涯,从你的点滴积累开始,所及之处,必精益求精。 Flutter是谷歌推出的最新的移动开发框架。...Provider ( 就是本文了) ValueNotifier 点击查看详情 Stream 流(StreamController ) EventBus 正在
  • Duplicate provider configs: <dubbo:provider
  • Content Provider

    2016-09-09 00:44:30
    为什么使用Content Provider? 1、Content Provider 可以把自己的app数据库、文件等内容暴露出来(即是可以做增、删、查、改的动作,例如用别的app管理手机联系人一样),而不会让自己代码逻辑暴露出去。 2、可以让...
  • Provider Pattern

    2015-08-18 10:27:36
    原文地址:http://www.codeproject.com/Articles/18222/Provider-Pattern ...Provider pattern is one of the most interesting features that Microsoft introduced in .NET 2. A lot of features inclu
  • java.lang.IllegalStateException: Failed to check the status of the service com.pinyougou.sellergoods.service.SellerService. No provider available for the service ...
  • Attribute provider#android.support.v4.content.FileProvider@authorities value=(com.example.xd.videotest) from AndroidManifest.xml:47:13-59 is also present at [:ringtonelib-release:] AndroidM...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 138,360
精华内容 55,344
关键字:

provider