List of usage examples for android.media MediaScannerConnection MediaScannerConnection
public MediaScannerConnection(Context context, MediaScannerConnectionClient client)
From source file:com.sentaroh.android.SMBExplorer.FileIo.java
public FileIo(GlobalParameters gp, int op_cd, ArrayList<FileIoLinkParm> alp, ThreadCtrl tc, NotifyEvent ne, Context cc, String lmp) { mGp = gp;//w ww. j a v a2 s . c o m fileioThreadCtrl = tc; file_op_cd = op_cd; fileioLinkParm = alp; notifyEvent = ne; mContext = cc; mSafCA = new SafCommonArea(); SafUtil.initWorkArea(cc, mSafCA, mGp.debugLevel > 0); mediaScanner = new MediaScannerConnection(mContext, new MediaScannerConnectionClient() { @Override public void onMediaScannerConnected() { sendDebugLogMsg(1, "I", "MediaScanner connected."); }; @Override public void onScanCompleted(String path, Uri uri) { sendDebugLogMsg(2, "I", "MediaScanner scan completed. fn=" + path + ", Uri=" + uri); }; }); mediaScanner.connect(); SMB_BUFF_SIZE = Integer.parseInt(mGp.jcifs_option_iobuff) * 65536; TimeZone tz = TimeZone.getDefault(); mTimeZoneDiff = tz.getRawOffset(); if (lmp != null && lmp.startsWith("/")) { if (isAppSpecificDirectoryExists(cc, lmp)) { sendDebugLogMsg(1, "I", "Local file last modified time was reset by application specific directory"); mGp.useSetLastModifiedByAppSpecificDir = true; if (lmp.contains("/Android/data/" + mAppPackageName + "/files")) mAppSpecificDirName = lmp; else mAppSpecificDirName = lmp + "/Android/data/" + mAppPackageName + "/files"; } else { if (!isSetLastModifiedFunctional(lmp)) { if (mGp.mSuCmdProcess != null) { sendDebugLogMsg(1, "I", "Local file last modified time was set by touch command"); mGp.useSetLastModifiedByTouchCommand = true; } else { sendDebugLogMsg(1, "I", "Local file last modified time was can not reset becuase su not granted"); } } else { sendDebugLogMsg(1, "I", "Local file last modified time was set by Java File#setLastModified() method"); } } } }
From source file:net.reichholf.dreamdroid.fragment.ScreenShotFragment.java
@Override public void onResume() { super.onResume(); mScannerConn = new MediaScannerConnection(getActionBarActivity(), new DummyMediaScannerConnectionClient()); mScannerConn.connect();/* w w w. j a v a2s.com*/ if (mRawImage.length == 0) { reload(); } else { onScreenshotAvailable(mRawImage); } }
From source file:com.BeatYourRecord.SubmitActivity.java
@Override public void onCreate(Bundle savedInstanceState) { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; }/* w w w . j av a 2 s . co m*/ if (haveConnectedWifi == false) { showDialog(11); } super.onCreate(savedInstanceState); // SharedPreferences pref = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode //Editor editor = pref.edit(); //auth = pref.getString("BYR_session", null); /*SharedPreferences pref6 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode Editor editor7 = pref6.edit(); //this.setContentView(R.layout.submit); String logoutme = pref6.getString("log", null); //log.v("log",logoutme); */ SharedPreferences pref1 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode Editor editor1 = pref1.edit(); tourid = pref1.getString("id", null); logout = pref1.getString("log", null); filepath = pref1.getString("filepath", null); //log.v("id",tourid); //log.v("log",logout); Log.v("reached here first", "reached here first"); File f = new File("/data/data/com.BeatYourRecord/shared_prefs/Tester15.xml"); if (f.exists() && logout.equals("yes") == false) { //log.v("yyy","yyy"); SharedPreferences pref = SubmitActivity.this.getSharedPreferences("Tester15", 0); // 0 - for private mode Editor editor = pref.edit(); this.setContentView(R.layout.submit); auth = pref.getString("BYR_session", null); } else { //log.v("yyy","yyy1"); this.setContentView(R.layout.submit1); showDialog(10); } // String checksession = pref.getString("BYR_session", null); // //log.v("checksession", checksession); ////log.v("Authhere",auth); this.authorizer = new ClientLoginAuthorizer.ClientLoginAuthorizerFactory().getAuthorizer(this, ClientLoginAuthorizer.YOUTUBE_AUTH_TOKEN_TYPE); dbHelper = new DbHelper(this); dbHelper = dbHelper.open(); Intent intent = this.getIntent(); this.videoUri = intent.getData(); SharedPreferences pref1223 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode Editor editor1223 = pref1223.edit(); filepath = pref1223.getString("filepath", null); // this.videoUri = // Uri path = Uri.parse(filepath); //File f1 = new File(filepath); //Uri imageUri = Uri.fromFile(f1); //this.videoUri = imageUri; //this.videoUri = path; Log.v("Reached here second", "Reached here secord"); //this.videoUri= Uri.fromFile(new File("/sdcard/Movies/com.BeatYourRecord/BYR_tournName_dateTim_20130724181901222.mp4")); //log.v("haha","haha"); MediaScannerConnectionClient mediaScannerClient = new MediaScannerConnectionClient() { private MediaScannerConnection msc = null; { msc = new MediaScannerConnection(getApplicationContext(), this); msc.connect(); } public void onMediaScannerConnected() { msc.scanFile(filepath, null); } public void onScanCompleted(String path, Uri uri) { //This is where you get your content uri Log.d("test3", uri.toString()); needed = uri; // videoUri=needed; msc.disconnect(); } }; String videoPath = ""; try { videoPath = getFilePathFromUri(this.videoUri); filepath1 = videoPath; Log.v("videoPath", videoPath); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } File videoFile = new File(videoPath); this.ytdDomain = intent.getExtras().getString(DbHelper.YTD_DOMAIN); this.assignmentId = intent.getExtras().getString(DbHelper.ASSIGNMENT_ID); this.domainHeader = (TextView) this.findViewById(R.id.domainHeader); domainHeader.setText(SettingActivity.getYtdDomains(this).get(this.ytdDomain)); this.preferences = this.getSharedPreferences(MainActivity.SHARED_PREF_NAME, Activity.MODE_PRIVATE); this.youTubeName = preferences.getString(DbHelper.YT_ACCOUNT, null); final Button submitButton = (Button) findViewById(R.id.submitButton); submitButton.setEnabled(false); submitButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showDialog(DIALOG_LEGAL); } }); addusertotournament(); Button cancelButton = (Button) findViewById(R.id.cancelButton); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //SharedPreferences pref1 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode //Editor editor = pref1.edit(); //editor.putString("filepath", permfilepath); //editor.commit(); Intent intent = new Intent(SubmitActivity.this, DetailsActivity.class); // intent.putExtra(DbHelper.YTD_DOMAIN, "TODO-appname.appspot.com"); //intent.setData(Uri.fromFile(file)); startActivity(intent); finish(); // setResult(RESULT_CANCELED); //finish(); } }); Button forgotButton = (Button) findViewById(R.id.forgotButton); forgotButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //SharedPreferences pref1 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode //Editor editor = pref1.edit(); //editor.putString("filepath", permfilepath); //editor.commit(); SharedPreferences pref155 = getApplicationContext().getSharedPreferences("TourPref", 0); // 0 - for private mode Editor editor155 = pref155.edit(); editor155.putString("filepath", filepath1); editor155.commit(); Log.v("fielpathss", filepath1); Intent intent = new Intent(SubmitActivity.this, DetailsActivity.class); // intent.putExtra(DbHelper.YTD_DOMAIN, "TODO-appname.appspot.com"); //intent.setData(Uri.fromFile(file)); startActivity(intent); // finish(); // setResult(RESULT_CANCELED); //finish(); } }); EditText titleEdit = (EditText) findViewById(R.id.submitTitle); titleEdit.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { enableSubmitIfReady(); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); EditText descriptionEdit = (EditText) findViewById(R.id.submitDescription); descriptionEdit.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { enableSubmitIfReady(); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); Cursor cursor = this.managedQuery(this.videoUri, null, null, null, null); if (cursor.getCount() == 0) { Log.d(LOG_TAG, "not a valid video uri"); Toast.makeText(SubmitActivity.this, "not a valid video uri", Toast.LENGTH_LONG).show(); } else { getVideoLocation(); if (cursor.moveToFirst()) { long id = cursor.getLong(cursor.getColumnIndex(Video.VideoColumns._ID)); this.dateTaken = new Date(cursor.getLong(cursor.getColumnIndex(Video.VideoColumns.DATE_TAKEN))); Log.v("here", "here12"); SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm aaa"); Configuration userConfig = new Configuration(); Settings.System.getConfiguration(getContentResolver(), userConfig); /* Calendar cal = Calendar.getInstance(userConfig.locale); TimeZone tz = cal.getTimeZone();*/ Log.v("here", "here13"); // dateFormat.setTimeZone(tz); TextView dateTakenView = (TextView) findViewById(R.id.dateCaptured); dateTakenView.setText("Date captured: " + dateFormat.format(dateTaken)); ImageView thumbnail = (ImageView) findViewById(R.id.thumbnail); ContentResolver crThumb = getContentResolver(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 1; Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options); thumbnail.setImageBitmap(curThumb); } } }
From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java
/** * Starts the MediaScanner./*from w w w . j a v a 2 s . com*/ */ private void startScan() { if (mMediaScannerConnection != null) mMediaScannerConnection.disconnect(); mMediaScannerConnection = new MediaScannerConnection(this, this); mMediaScannerConnection.connect(); }
From source file:com.akop.bach.ImageCache.java
public File downloadImage(String imageUrl) { if (imageUrl == null || imageUrl.length() < 1) return null; File file = getImageFile(imageUrl); if (file == null) return null; // Fetch the image byte[] blob;//from w ww .j a v a 2 s . c o m int length; try { HttpClient client = new IgnorantHttpClient(); HttpResponse resp = client.execute(new HttpGet(imageUrl)); HttpEntity entity = resp.getEntity(); if (entity == null) return null; InputStream stream = entity.getContent(); if (stream == null) return null; try { if ((length = (int) entity.getContentLength()) <= 0) return null; blob = new byte[length]; // Read the stream until nothing more to read for (int r = 0; r < length; r += stream.read(blob, r, length - r)) ; } finally { stream.close(); entity.consumeContent(); } } catch (IOException e) { if (App.getConfig().logToConsole()) e.printStackTrace(); return null; } // if (file.canWrite()) { FileOutputStream fos = null; try { fos = new FileOutputStream(file); fos.write(blob); if (App.getConfig().logToConsole()) App.logv("Wrote to cache: " + file.getName()); } catch (IOException e) { if (App.getConfig().logToConsole()) e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { } } } } final String filename = file + ""; MediaScannerConnectionClient mscc = new MediaScannerConnectionClient() { public void onMediaScannerConnected() { mMsc.scanFile(filename, null); } public void onScanCompleted(String path, Uri uri) { if (path.equals(filename)) mMsc.disconnect(); } }; try { mMsc = new MediaScannerConnection(mContext, mscc); mMsc.connect(); } catch (Exception ex) { if (App.getConfig().logToConsole()) ex.printStackTrace(); } return file; }
From source file:edu.mit.mobile.android.locast.data.MediaSync.java
/** * Enqueues a media item to be scanned. onScanComplete() will be called once * the item has been scanned successfully. * * @param castMediaUri/*w w w . j a v a2 s .c o m*/ * @param filePath * @param contentType */ public void scanMediaItem(Uri castMediaUri, String filePath, String contentType) { scanMap.put(filePath, new ScanQueueItem(castMediaUri, contentType)); if (msc == null) { toScan.add(filePath); this.msc = new MediaScannerConnection(this, this); this.msc.connect(); } else if (msc.isConnected()) { msc.scanFile(filePath, contentType); // if we're not connected yet, we need to remember what we want // scanned, // so that we can queue it up once connected. } else { toScan.add(filePath); } }
From source file:edu.mit.mobile.android.locast.sync.AbsMediaSync.java
/** * Enqueues a media item to be scanned. onScanComplete() will be called once the item has been * scanned successfully.//from www . j av a2s. c o m * * @param castMediaUri * @param filePath * @param contentType */ public void scanMediaItem(Uri castMediaUri, String filePath, String contentType) { mScanMap.put(filePath, new ScanQueueItem(castMediaUri, contentType)); if (mMsc == null) { mToScan.add(filePath); this.mMsc = new MediaScannerConnection(this, this); this.mMsc.connect(); } else if (mMsc.isConnected()) { mMsc.scanFile(filePath, contentType); // if we're not connected yet, we need to remember what we want // scanned, // so that we can queue it up once connected. } else { mToScan.add(filePath); } }
From source file:com.MustacheMonitor.MustacheMonitor.StacheCam.java
private void scanForGallery(Uri newImage) { this.scanMe = newImage; if (this.conn != null) { this.conn.disconnect(); }/*from w w w . j a v a 2 s .c o m*/ this.conn = new MediaScannerConnection(this.ctx.getActivity().getApplicationContext(), this); conn.connect(); }
From source file:com.logilite.vision.camera.CameraLauncher.java
private void scanForGallery(Uri newImage) { this.scanMe = newImage; if (this.conn != null) { this.conn.disconnect(); }/*www . j a v a 2 s. com*/ this.conn = new MediaScannerConnection(this.cordova.getActivity().getApplicationContext(), this); conn.connect(); }