Home > Mobile >  All PDF files within about through MediaStore access to mobile phones
All PDF files within about through MediaStore access to mobile phones

Time:09-26

Like me by the following code to the mobile phone in the PDF file, but I tried it on, such as the first time in the search to mobile phones has 10 PDF file, I quit, and then let the WeChat friend send me a PDF, I open the PDF, I confirm that the PDF has been stored in the phone, then open the search PDF Activity, then there should be 11 PDF file, but still only 10 PDF files, this how to solve? In the search on the net, is not add files to the MediaStore inside, but should be how to operate? Had better have the code, thank you

/* ** all captured by the MediaStore PDF 
*/
Private void getAllPdf () {
ContentResolver cr=getActivity (). GetContentResolver ();
Uri Uri=MediaStore. Files. GetContentUri (" external ");
String [] the projection=null;
String selection.=MediaStore Files. FileColumns. MEDIA_TYPE + "="
+ MediaStore. Files. FileColumns. MEDIA_TYPE_NONE;
String [] selectionArgs=null;//there is no? In the selection so null here
String sortOrder=null;//unordered
Cursor allNonMediaFiles=cr. Query (uri, the projection, selection, selectionArgs, sortOrder);
//only PDF
String selectionMimeType=MediaStore. Files. FileColumns. MIME_TYPE + "=?" ;
String mimeType=MimeTypeMap. GetSingleton (.) getMimeTypeFromExtension (" PDF ");
String [] selectionArgsPdf=new String [] {mimeType};
Cursor Cursor=cr. Query (uri, the projection, selectionMimeType selectionArgsPdf, sortOrder);
While (cursor. MoveToNext ()) {
Int column_index=cursor. GetColumnIndexOrThrow (MediaStore. Images. Media. The DATA).
String filePath=cursor. Get String (column_index);//all PDF file path
The String fileName=getFileNameWithSuffix (filePath);//all file name
}
}

CodePudding user response:

You confirm WeChat receives the PDF is stored in the content://external? Terminals can find way to confirm receive the PDF file storage path,
Then print up the filePath above, a look, compare,

CodePudding user response:

If you confirm the storage to the content://external, namely external storage medium, you directly using the File class list to find can also,
System when scanning the external media for storage time not too clear,

CodePudding user response:

refer to the second floor jzp12 response:
if you confirm the storage to the content://external, namely external storage medium, you directly using the File class list to find can also,
System when scanning the external media for storage time not too clear,
WeChat store path is this: the String wechatPath=externalStorageDirectory. GetAbsolutePath () + File. The separator + "tencent" + File. The separator + "MicroMsg" + File. The separator + "Download";//WeChat file storage path
Print out is:/storage/emulated/0/tencent/MicroMsg/Download, I tried it on, WeChat after sending, Download your path is this

CodePudding user response:

That should be the media scanner did not begin to scan, you can trigger a scan by oneself, see if I can add new file scanning to:
 
/* *
* Sends a broadcast and the media scanner scan a file
*
* @ param path
* the file to scan
*/
Private void scanMedia (String path) {
The File File=new File (path);
Uri Uri=Uri. FromFile (file);
Intent scanFileIntent=new Intent (
Intent. ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
SendBroadcast (scanFileIntent);
}

CodePudding user response:

Jzp12
reference 4 floor response:
that should be the media scanner did not begin to scan, you can trigger a scan by oneself, see if I can add new file scanning to:
 
/* *
* Sends a broadcast and the media scanner scan a file
*
* @ param path
* the file to scan
*/
Private void scanMedia (String path) {
The File File=new File (path);
Uri Uri=Uri. FromFile (file);
Intent scanFileIntent=new Intent (
Intent. ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
SendBroadcast (scanFileIntent);
}
according to your this kind of writing, that is, as long as open the scan PDF page will call you this packaging function, the path will preach WeChat that path?

CodePudding user response:

refer to fifth floor 丿 roybill response:
Quote: refer to 4th floor jzp12 response:

That should be the media scanner did not begin to scan, you can trigger a scan by oneself, see if I can add new file scanning to:
 
/* *
* Sends a broadcast and the media scanner scan a file
*
* @ param path
* the file to scan
*/
Private void scanMedia (String path) {
The File File=new File (path);
Uri Uri=Uri. FromFile (file);
Intent scanFileIntent=new Intent (
Intent. ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
SendBroadcast (scanFileIntent);
}
according to your this kind of writing, that is, as long as open the scan PDF page will call you this packaging function, the path will preach WeChat that path?


Yes, give it a try.

CodePudding user response:

refer to 6th floor jzp12 response:
Quote: refer to fifth floor 丿 roybill response:

Quote: refer to 4th floor jzp12 response:

That should be the media scanner did not begin to scan, you can trigger a scan by oneself, see if I can add new file scanning to:
 
/* *
* Sends a broadcast and the media scanner scan a file
*
* @ param path
* the file to scan
*/
Private void scanMedia (String path) {
The File File=new File (path);
Uri Uri=Uri. FromFile (file);
Intent scanFileIntent=new Intent (
Intent. ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
SendBroadcast (scanFileIntent);
}
according to your this kind of writing, that is, as long as open the scan PDF page will call you this packaging function, the path will preach WeChat that path?


null
  • Related