【问题标题】:How to get sdcard path of image sync from google plus?如何从 google plus 获取图片同步的 sdcard 路径?
【发布时间】:2014-01-17 12:18:42
【问题描述】:

我能够获取本地图像的 sdcard 路径,但无法使用 google plus、dropbox 等获取非本地图像同步的路径。

我的代码如下:-

       @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    if(v == imgSelectPhoto){
                        Intent i = new Intent(Intent.ACTION_PICK,
                                android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                        startActivityForResult(i, 0);
                    }
                  }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub
            super.onActivityResult(requestCode, resultCode, data);
            switch (requestCode) {
            case 0:
                if(resultCode == RESULT_OK) {

                    try
                    {

                    DisplayImageOptions options;
                    options = new DisplayImageOptions.Builder()
                    .showStubImage(R.drawable.ic_stub)
                    .showImageForEmptyUri(R.drawable.ic_empty)
                    .showImageOnFail(R.drawable.ic_error).cacheInMemory()
                    .cacheOnDisc().bitmapConfig(Bitmap.Config.RGB_565).build();
                    imageLoader = ImageLoader.getInstance();
                    imageLoader.init(ImageLoaderConfiguration.createDefault(getApplicationContext()));
                    imageLoader.displayImage(data.getData().toString(), imgImagePreview, options);
                    //imgImagePreview.setImageURI(data.getData());
                    fileUrl = getRealPathFromURI(data.getData());
                    Log.w("TEST","ImageURI : "+ data.getData()+" Path : "+ fileUrl);
                    }
                    catch(Exception  e)
                    {

                    }
            objAdapter.InsertLocalImage(fieldNotes, displayName, fileLargerName, fileUrl)
                }
            }
        }

        public String getRealPathFromURI(Uri contentUri) {
            String[] proj = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(contentUri, proj, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        }

Logcat:-

01-17 17:50:58.242: W/TEST(11961): ImageURI : content://com.sec.android.gallery3d.provider/picasa/item/5955342059370063154 Path : https://lh4.googleusercontent.com/-vAwMltvVVdE/UqWgDNyyJTI/AAAAAAAABtc/IiAikNj0uwI/I/20131209_162222.jpg

如果有人有想法请回复。 提前谢谢...

【问题讨论】:

    标签: android image upload sync


    【解决方案1】:

    没有您必须访问的路径。永远不会有 content:// Uri ——您使用的代码将不可靠。

    使用ContentResolveropenInputStream()(或openOutputStream())使用content://Uri 引用的数据。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-19
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    • 2017-12-28
    • 2017-03-10
    • 2012-06-05
    相关资源
    最近更新 更多