use of android.webkit.MimeTypeMap in project iNaturalistAndroid by inaturalist.
the class ObservationEditor method getExtension.
public static String getExtension(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;
}
use of android.webkit.MimeTypeMap in project android-classyshark by google.
the class MainActivity method onStart.
@Override
public void onStart() {
super.onStart();
final ArrayList<AppListNode> apps = new ArrayList<>();
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
for (Object object : pkgAppsList) {
ResolveInfo info = (ResolveInfo) object;
File file = new File(info.activityInfo.applicationInfo.publicSourceDir);
AppListNode aln = new AppListNode();
aln.name = info.activityInfo.applicationInfo.processName.toString();
aln.file = file;
apps.add(aln);
}
Collections.sort(apps);
final StableArrayAdapter adapter = new StableArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, convert(apps));
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
MimeTypeMap myMime = MimeTypeMap.getSingleton();
Intent newIntent = new Intent(MainActivity.this, ClassesListActivity.class);
String mimeType = myMime.getMimeTypeFromExtension("apk");
newIntent.setDataAndType(Uri.fromFile(apps.get(position).file), mimeType);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newIntent.putExtra(APP_NAME, apps.get(position).name);
try {
startActivity(newIntent);
} catch (ActivityNotFoundException e) {
}
}
});
}
use of android.webkit.MimeTypeMap in project HL4A by HL4A.
the class AVFile method getMimeType.
/**
* @param url
* @return
* @deprecated replaced by {@link AVUtils#getMimeTypeFromLocalFile(String)} or
* {@link AVUtils#getMimeTypeFromUrl(String)}
*/
public static String getMimeType(String url) {
String type = DEFAULTMIMETYPE;
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
if (type == null) {
type = DEFAULTMIMETYPE;
}
return type;
}
use of android.webkit.MimeTypeMap in project android-aosp-mms by slvn.
the class UriImage method initFromFile.
private void initFromFile(Context context, Uri uri) {
mPath = uri.getPath();
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String extension = MimeTypeMap.getFileExtensionFromUrl(mPath);
if (TextUtils.isEmpty(extension)) {
// getMimeTypeFromExtension() doesn't handle spaces in filenames nor can it handle
// urlEncoded strings. Let's try one last time at finding the extension.
int dotPos = mPath.lastIndexOf('.');
if (0 <= dotPos) {
extension = mPath.substring(dotPos + 1);
}
}
mContentType = mimeTypeMap.getMimeTypeFromExtension(extension);
// It's ok if mContentType is null. Eventually we'll show a toast telling the
// user the picture couldn't be attached.
buildSrcFromPath();
}
use of android.webkit.MimeTypeMap in project FileDownloaderManager by arlyxiao.
the class DownloadLib method get_mime_type.
// protected void open_file() {
// String full_file_path = Environment.getExternalStorageDirectory().getAbsolutePath()
// + save_file_path;
// Log.i("要打开的文件 ", full_file_path);
// File file = new File(full_file_path);
//
// try {
// Intent intent = new Intent(Intent.ACTION_VIEW);
// // intent.setAction(Intent.ACTION_VIEW);
// intent.setDataAndType(Uri.fromFile(file), get_mime_type(file.getAbsolutePath()));
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(intent);
// } catch (Exception e) {
// Log.i("文件打开错误 ", e.getMessage());
// }
// }
private String get_mime_type(String url) {
String[] parts = url.split("\\.");
String extension = parts[parts.length - 1];
String type = null;
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
}
Aggregations