11package com .jph .takephoto .uitl ;
22
3+ import android .app .Activity ;
34import android .content .ContentResolver ;
45import android .content .Context ;
56import android .graphics .Bitmap ;
@@ -91,7 +92,7 @@ public static void inputStreamToFile(InputStream is, File file) throws TExceptio
9192 * @param photoUri
9293 * @return
9394 */
94- public static File getTempFile (Context context , Uri photoUri )throws TException {
95+ public static File getTempFile (Activity context , Uri photoUri )throws TException {
9596 String minType =getMimeType (context , photoUri );
9697 if (!checkMimeType (context ,minType ))throw new TException (TExceptionType .TYPE_NOT_IMAGE );
9798 File filesDir =context .getExternalFilesDir (Environment .DIRECTORY_PICTURES );
@@ -115,7 +116,7 @@ public static boolean checkMimeType(Context context,String minType) {
115116 * To find out the extension of required object in given uri
116117 * Solution by http://stackoverflow.com/a/36514823/1171484
117118 */
118- public static String getMimeType (Context context , Uri uri ) {
119+ public static String getMimeType (Activity context , Uri uri ) {
119120 String extension ;
120121 //Check uri format to avoid null
121122 if (ContentResolver .SCHEME_CONTENT .equals (uri .getScheme ())) {
@@ -128,6 +129,12 @@ public static String getMimeType(Context context, Uri uri) {
128129 extension = MimeTypeMap .getFileExtensionFromUrl (Uri .fromFile (new File (uri .getPath ())).toString ());
129130 if (TextUtils .isEmpty (extension ))extension =MimeTypeMap .getSingleton ().getExtensionFromMimeType (context .getContentResolver ().getType (uri ));
130131 }
132+ if (TextUtils .isEmpty (extension )){
133+ extension =getMimeTypeByFileName (TUriParse .getFileWithUri (uri ,context ).getName ());
134+ }
131135 return extension ;
132136 }
137+ public static String getMimeTypeByFileName (String fileName ){
138+ return fileName .substring (fileName .lastIndexOf ("." ),fileName .length ());
139+ }
133140 }
0 commit comments