本文整理汇总了Java中android.webkit.MimeTypeMap.getExtensionFromMimeType方法的典型用法代码示例。如果您正苦于以下问题:Java MimeTypeMap.getExtensionFromMimeType方法的具体用法?Java MimeTypeMap.getExtensionFromMimeType怎么用?Java MimeTypeMap.getExtensionFromMimeType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.MimeTypeMap
的用法示例。
在下文中一共展示了MimeTypeMap.getExtensionFromMimeType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resultReturned
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
/**
* Callback method to get the result returned by the image picker activity
*
* @param requestCode a code identifying the request.
* @param resultCode a code specifying success or failure of the activity
* @param data the returned data, in this case an Intent whose data field
* contains the image's content URI.
*/
public void resultReturned(int requestCode, int resultCode, Intent data) {
if (requestCode == this.requestCode && resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
selectionURI = selectedImage.toString();
Log.i(LOG_TAG, "selectionURI = " + selectionURI);
// get the file type extension from the intent data Uri
ContentResolver cR = container.$context().getContentResolver();
MimeTypeMap mime = MimeTypeMap.getSingleton();
String extension = "." + mime.getExtensionFromMimeType(cR.getType(selectedImage));
Log.i(LOG_TAG, "extension = " + extension);
// save the image to a temp file in external storage, using a name
// that includes the extension
saveSelectedImageToExternalStorage(extension);
AfterPicking();
}
}
示例2: getMimeType
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
private static String getMimeType(Context context, Uri uri) {
String extension;
//Check uri format to avoid null
if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
//If scheme is a content
final MimeTypeMap mime = MimeTypeMap.getSingleton();
extension = mime.getExtensionFromMimeType(context.getContentResolver().getType(uri));
} else {
//If scheme is a File
//This will replace white spaces with %20 and also other special characters. This will avoid returning null values on file name with spaces and special characters.
extension = MimeTypeMap
.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());
}
return extension;
}
示例3: generateOutputFileName
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
private String generateOutputFileName(@NonNull String contentType, long timestamp) {
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String extension = mimeTypeMap.getExtensionFromMimeType(contentType);
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd-HHmmss");
String base = "signal-" + dateFormatter.format(timestamp);
if (extension == null) extension = "attach";
return base + "." + extension;
}
示例4: onCreate
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.transparent_activity);
String action = getIntent().getAction();
String type = getIntent().getType();
if (Intent.ACTION_SEND.equals(action)) {
getPermission();
uri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
Log.d("delf", "[DEBUG] shared date type is " + type);
ContentResolver cR = getContentResolver();
MimeTypeMap mime = MimeTypeMap.getSingleton();
String mimeType = mime.getExtensionFromMimeType(cR.getType(uri)); // get "file name extension"
Log.d("delf", "[DEBUG] shared date mime type is " + mimeType);
showUploadProgressNoti();
if (type.startsWith("image/")) {
Toast.makeText(getApplicationContext(), R.string.shareImage, Toast.LENGTH_SHORT).show();
bitmap = getBitmapByUri(uri);
new EndpointInBackGround()
.setSendBitmapImage(bitmap)
.execute(Message.UPLOAD, "image");
} else {
Toast.makeText(getApplicationContext(), R.string.shareFile, Toast.LENGTH_SHORT).show();
Log.d("delf", "[DEBUG] uri.getPath() = " + uri.getPath());
String filePath = getPathFromUri(uri);
Log.d("hee", "[DEBUG] filePath = " + filePath);
new EndpointInBackGround()
.setFilePath(filePath)
.execute(Message.UPLOAD, "file");
}
}
finish();
}
示例5: getFileExtension
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
private String getFileExtension(Uri uri){
ContentResolver contentResolver = getContentResolver();
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
return mimeTypeMap.getExtensionFromMimeType(contentResolver.getType(uri));
}
示例6: getFileExt
import android.webkit.MimeTypeMap; //导入方法依赖的package包/类
public String getFileExt(Uri uri1){
ContentResolver contentResolver = getContentResolver();
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
return mimeTypeMap.getExtensionFromMimeType(contentResolver.getType(uri1));
}