跳至主要内容

博文

目前显示的是标签为“open”的博文

android open file provider type

add a FileProvider tag in AndroidManifest.xml under tag. <? xml version = "1.0" encoding = "utf-8" ?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" ... <application ... <provider android:name = "android.support.v4.content.FileProvider" android:authorities = "${applicationId}.provider" android:exported = "false" android:grantUriPermissions = "true" > <meta-data android:name = "android.support.FILE_PROVIDER_PATHS" android:resource = "@xml/provider_paths" /> </provider> </application> </manifest> then create a provider_paths.xml file in xml folder under res folder. Folder may be needed to create if it doesn't exist. The content of the file is shown below. It describes that we would like to ...

android file chooser

private void showFileChooser (){ Intent intent= new Intent(Intent. ACTION_GET_CONTENT ) ; intent.setType( "*/*" ) ; intent.addCategory(Intent. CATEGORY_OPENABLE ) ; try { startActivityForResult(Intent. createChooser (intent , "Select a File to share" ) , 0 ) ; } catch (android.content.ActivityNotFoundException ex){ Toast. makeText ( this, "Please install a File Manager" , Toast. LENGTH_SHORT ).show() ; } } @Override protected void onActivityResult ( int requestCode , int resultCode , Intent data) { switch (requestCode){ case 0 : if (resultCode== RESULT_OK ){ Uri uri=data.getData() ; Log. d ( "spy" , "##FileSharer: uri=" +uri.toString()) ; try { String path= getPath ( this, uri) ; Log. d ( "spy" , "## File path=" +path) ; } catch (URISyntaxException e) ...