当前位置: 首页>>代码示例>>Java>>正文


Java MediaScannerConnection.scanFile方法代码示例

本文整理汇总了Java中android.media.MediaScannerConnection.scanFile方法的典型用法代码示例。如果您正苦于以下问题:Java MediaScannerConnection.scanFile方法的具体用法?Java MediaScannerConnection.scanFile怎么用?Java MediaScannerConnection.scanFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaScannerConnection的用法示例。


在下文中一共展示了MediaScannerConnection.scanFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fileScan

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
/**
 * 扫描指定文件夹Android4.4中,则会抛出异常MediaScannerConnection.scanFile可以解决
 */
public static void fileScan(Context context) {
    try {
        if (Build.VERSION.SDK_INT < 19) {
            context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
                    + Environment.getExternalStorageDirectory())));
        } else {
            context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
                    + Environment.getExternalStorageDirectory())));
            MediaScannerConnection.scanFile(context, new String[]{new File(Environment.getExternalStorageDirectory().toString()).getAbsolutePath()}, null, new MediaScannerConnection.OnScanCompletedListener() {
                @Override
                public void onScanCompleted(String path, Uri uri) {

                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:wangzhaosheng,项目名称:publicProject,代码行数:23,代码来源:FileUtils.java

示例2: onActivityResult

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
/**
 * Check if the captured image is stored successfully
 * Then reload data
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == Constants.REQUEST_CODE_CAPTURE) {
        if (resultCode == RESULT_OK && currentImagePath != null) {
            Uri imageUri = Uri.parse(currentImagePath);
            if (imageUri != null) {
                MediaScannerConnection.scanFile(this,
                        new String[]{imageUri.getPath()}, null,
                        new MediaScannerConnection.OnScanCompletedListener() {
                            @Override
                            public void onScanCompleted(String path, Uri uri) {
                                Log.v(TAG, "File " + path + " was scanned successfully: " + uri);
                                getDataWithPermission();
                            }
                        });
            }
        }
    }
}
 
开发者ID:sega4revenge,项目名称:Sega,代码行数:25,代码来源:ImagePickerActivity.java

示例3: scanVideo

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
public static void scanVideo(Context context, String videoPath) {
    File file = new File(videoPath);
    if (file.exists() && context != null) {
        MediaScannerConnection.scanFile(context, new String[]{videoPath}, new String[]{"video/mp4"},
                new MediaScannerConnection.MediaScannerConnectionClient() {
                    @Override
                    public void onMediaScannerConnected() {
                        L.e("call: onMediaScannerConnected([])-> ");
                    }

                    @Override
                    public void onScanCompleted(String path, Uri uri) {
                        L.e("call: onScanCompleted([path, uri])-> " + path + " ->" + uri);
                    }
                });
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:18,代码来源:RUtils.java

示例4: saveFile

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
@SuppressWarnings("ResultOfMethodCallIgnored")
private boolean saveFile(String fileName) {
    try {
        File path = getExternalStoragePublicDirectory(getString(R.string.storage_dir));
        path.mkdir();
        File file = new File(path, fileName);

        FileOutputStream stream = new FileOutputStream(file);
        stream.write(getXML().getBytes());
        stream.flush();
        stream.close();

        MediaScannerConnection.scanFile(this, new String[] {file.toString()}, null, null);

        return true;
    } catch (IOException e) {
        return false;
    }
}
 
开发者ID:joshschriever,项目名称:LiveNotes,代码行数:20,代码来源:LiveNotesActivity.java

示例5: saveToSDCard

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
public static String saveToSDCard(byte[] data,Context context,String path) throws IOException {
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        String filename = "IMG_" + format.format(date) + ".jpg";
        File fileFolder = new File(path);
        if (!fileFolder.exists()) {
            fileFolder.mkdirs();
        }
        File jpgFile = new File(fileFolder, filename);
        FileOutputStream outputStream = new FileOutputStream(jpgFile); //
        //刷新相册
        MediaScannerConnection.scanFile(context,
                new String[]{jpgFile.getAbsolutePath()}, null, null);

        outputStream.write(data);
        outputStream.close();
//        Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
//        Uri uri = Uri.fromFile(new File(Environment
//                .getExternalStorageDirectory() + "/DeepbayPicture/" + filename));
//        intent.setData(uri);
//        mContext.sendBroadcast(intent);
        return jpgFile.getAbsolutePath();
    }
 
开发者ID:lwd1815,项目名称:Selector,代码行数:24,代码来源:ImageCacheUtils.java

示例6: onPostExecute

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
@Override
protected void onPostExecute(Boolean b) {
    super.onPostExecute(b);
    if (b) {
        Toast.makeText(context, "Tag Edit Success", Toast.LENGTH_SHORT).show();
        mediaScannerConnection = new MediaScannerConnection(getContext(),
                new MediaScannerConnection.MediaScannerConnectionClient() {

                    public void onScanCompleted(String path, Uri uri) {
                        mediaScannerConnection.disconnect();
                    }

                    public void onMediaScannerConnected() {
                        mediaScannerConnection.scanFile(song.getmSongPath(), "audio/*");
                    }
                });
    } else {
        Toast.makeText(context, "Tag Edit Failed", Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:21,代码来源:TagEditorFragment.java

示例7: scanFile

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
/**
     * 扫描文件, 到系统相册/视频文件夹
     */
    public static void scanFile(Context context, String filePath) {
        File file = new File(filePath);
        if (file.exists() && context != null) {
            /*需要android.intent.action.MEDIA_MOUNTED系统权限,但是再Android 4.4系统以后,限制了只有系统应用才有使用广播通知系统扫描的权限,否则会抛出异常信息*/
//            Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
//            Uri uri = Uri.fromFile(file);
//            intent.setData(uri);
//            context.sendBroadcast(intent);

            MediaScannerConnection.scanFile(context.getApplicationContext(), new String[]{filePath}, null,
                    new MediaScannerConnection.MediaScannerConnectionClient() {
                        @Override
                        public void onMediaScannerConnected() {
                            L.e("call: onMediaScannerConnected([])-> ");
                        }

                        @Override
                        public void onScanCompleted(String path, Uri uri) {
                            L.e("call: onScanCompleted([path, uri])-> " + path + " ->" + uri);
                        }
                    });
        }
    }
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:27,代码来源:RUtils.java

示例8: handleUpdateMedia

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
public void handleUpdateMedia(final String path) {
	if (DEBUG) Log.d(TAG_THREAD, "handleUpdateMedia:path=" + path);
	final Context context = mWeakContext.get();
	if (context != null) {
		try {
			if (DEBUG) Log.i(TAG, "MediaScannerConnection#scanFile");
			MediaScannerConnection.scanFile(context, new String[]{ path }, null, null);
		} catch (final Exception e) {
			Log.e(TAG, "handleUpdateMedia:", e);
		}
	} else {
		Log.w(TAG, "MainActivity already destroyed");
		// give up to add this movice to MediaStore now.
		// Seeing this movie on Gallery app etc. will take a lot of time.
		handleRelease();
	}
}
 
开发者ID:jp1017,项目名称:UVCCameraZxing,代码行数:18,代码来源:CameraServer.java

示例9: indexFile

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
private void indexFile() {
    //Create a new ArrayList and add the newly created video file path to it
    ArrayList<String> toBeScanned = new ArrayList<>();
    toBeScanned.add(SAVEPATH);
    String[] toBeScannedStr = new String[toBeScanned.size()];
    toBeScannedStr = toBeScanned.toArray(toBeScannedStr);

    //Request MediaScannerConnection to scan the new file and index it
    MediaScannerConnection.scanFile(this, toBeScannedStr, null, new MediaScannerConnection.OnScanCompletedListener() {

        @Override
        public void onScanCompleted(String path, Uri uri) {
            Log.i(Const.TAG, "SCAN COMPLETED: " + path);
            //Show toast on main thread
            Message message = mHandler.obtainMessage();
            message.sendToTarget();
            stopSelf();
        }
    });
}
 
开发者ID:vijai1996,项目名称:screenrecorder,代码行数:21,代码来源:RecorderService.java

示例10: callBroadCast

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
public void callBroadCast() {
  if (Build.VERSION.SDK_INT >= 14) {
    Log.e("-->", " >= 14");
    MediaScannerConnection.scanFile(mContext, new String[]{ Environment.getExternalStorageDirectory().toString()}, null, new MediaScannerConnection.OnScanCompletedListener() {
      /*
       *   (non-Javadoc)
       * @see android.media.MediaScannerConnection.OnScanCompletedListener#onScanCompleted(java.lang.String, android.net.Uri)
       */
      public void onScanCompleted(String path, Uri uri) {
        Log.e("ExternalStorage", "Scanned " + path + ":");
        Log.e("ExternalStorage", "-> uri=" + uri);
      }
    });
  } else {
    Log.e("-->", " < 14");
    mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
        Uri.parse("file://" + Environment.getExternalStorageDirectory())));
  }
}
 
开发者ID:rrishabhj,项目名称:InstaImageDownloader,代码行数:20,代码来源:ImageRecyclerAdaptor.java

示例11: sendVideo

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
public void sendVideo(View view) {
	if (TextUtils.isEmpty(localPath)) {
		EMLog.e("Recorder", "recorder fail please try again!");
		return;
	}

	msc = new MediaScannerConnection(this,
			new MediaScannerConnectionClient() {

				@Override
				public void onScanCompleted(String path, Uri uri) {
					Log.d("log scanner completed");
					msc.disconnect();
					setResult(RESULT_OK, getIntent().putExtra("uri", uri));
					finish();
				}

				@Override
				public void onMediaScannerConnected() {
					msc.scanFile(localPath, "video/*");
				}
			});
	msc.connect();

}
 
开发者ID:macyuan,项目名称:TAG,代码行数:26,代码来源:RecorderVideoActivity.java

示例12: indexPictureInGallery

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
private void indexPictureInGallery(View view, File picture) {
    Timber.d("Adding taken picture to media collection");
    MediaScannerConnection.scanFile(TakePictureActivity.this, new String[]{picture.getAbsolutePath()}, new String[]{"image/jpg"}, (s, uri) -> {
        Timber.d("Picture %s added to gallery under %s", s, uri);

        Snackbar snackbar = Snackbar.make(view, "" +
                "Picture saved", Snackbar.LENGTH_SHORT);

        Intent viewIntent = new Intent(Intent.ACTION_VIEW);
        viewIntent.setDataAndType(uri, "image/*");

        List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(viewIntent, PackageManager.MATCH_DEFAULT_ONLY);
        if (resolveInfos.size() > 0) {
            snackbar.setAction("Show", v -> {
                Timber.d("Opening picture in gallery");
                startActivity(viewIntent);
            });
        }
        snackbar.show();
    });
}
 
开发者ID:fzymek,项目名称:FunWithAndroid,代码行数:22,代码来源:TakePictureActivity.java

示例13: onClick

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.id_movie_refresh:
            MediaScannerConnection.scanFile(getActivity(), new String[]{Environment
                    .getExternalStorageDirectory().getAbsolutePath()}, null, null);
            if (movieList != null) {
                movieList.clear();
                nameList.clear();
            }
            movieList = MovieUtils.getAllMovies(getActivity());
            for (Movie movie : movieList) {
                nameList.add(movie.getTitle());
            }
            adapterMovie.notifyDataSetChanged();
            break;
        default:
            break;
    }
}
 
开发者ID:lucky-code,项目名称:Practice,代码行数:21,代码来源:MovieFragment.java

示例14: indexFile

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
private void indexFile(String SAVEPATH) {
    //Create a new ArrayList and add the newly created video file path to it
    ArrayList<String> toBeScanned = new ArrayList<>();
    toBeScanned.add(SAVEPATH);
    String[] toBeScannedStr = new String[toBeScanned.size()];
    toBeScannedStr = toBeScanned.toArray(toBeScannedStr);

    //Request MediaScannerConnection to scan the new file and index it
    MediaScannerConnection.scanFile(this, toBeScannedStr, null, new MediaScannerConnection.OnScanCompletedListener() {

        @Override
        public void onScanCompleted(String path, Uri uri) {
            Log.i(Const.TAG, "SCAN COMPLETED: " + path);
            saveprogress.cancel();
            setResult(Const.VIDEO_EDIT_RESULT_CODE);
            finish();
        }
    });
}
 
开发者ID:vijai1996,项目名称:screenrecorder,代码行数:20,代码来源:EditVideoActivity.java

示例15: onDestroy

import android.media.MediaScannerConnection; //导入方法依赖的package包/类
@Override
protected void onDestroy() {
  if (!isChangingConfigurations()) {
    if (testRoot.exists()) {
      delete(testRoot);
    }

    if (testZip.exists()) {
      testZip.delete();

      MediaScannerConnection.scanFile(
        this,
        new String[]{testZip.getAbsolutePath()},
        null,
        null);
    }
  }

  super.onDestroy();
}
 
开发者ID:commonsguy,项目名称:cwac-cam2,代码行数:21,代码来源:MainActivity.java


注:本文中的android.media.MediaScannerConnection.scanFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。