使用操作共享文件\u发送不适用于共享android
使用操作共享文件\u发送不适用于共享android 我正在尝试使用共享图像使用操作共享文件\u发送不适用于共享android,android,android-intent,Android,Android Intent,使用操作共享文件\u发送不适用于共享android 我正在尝试使用共享图像 String path = newString; Uri uri = Uri.parse(path); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("image/jpeg"); intent.putExtra(I
String path = newString;
Uri uri = Uri.parse(path);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share Image"));
但是,我收到错误不支持发送此内容类型
是否有一种工具或实用工具可以使共享变得容易
我正在寻找的是意图的替代方案。行动发送
在youtube、FB、共享、邮件或其他社交媒体或其他平台上发送文件
我不想使用wifi direct作为替代方案这很有效
try {
String path = newString;
File myFile = new File(path);
Intent sharingIntent = new Intent("android.intent.action.SEND");
sharingIntent.setType(getMimeType(myFile.getPath()));
sharingIntent.putExtra("android.intent.extra.STREAM",Uri.fromFile(myFile));
startActivity(Intent.createChooser(sharingIntent,"Share using"));
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
public String getMimeType(String filePath) {
String type = null;
String extension = getFileExtensionFromUrl(filePath);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
}
public String getFileExtensionFromUrl(String url) {
int dotPos = url.lastIndexOf('.');
if (0 <= dotPos) {
return (url.substring(dotPos + 1)).toLowerCase();
}
return "";
}
试试看{
字符串路径=新闻字符串;
File myFile=新文件(路径);
Intent sharingcontent=newintent(“android.Intent.action.SEND”);
sharingIntent.setType(getMimeType(myFile.getPath());
sharingint.putExtra(“android.intent.extra.STREAM”,Uri.fromFile(myFile));
startActivity(Intent.createChooser(共享内容,“共享使用”);
}捕获(例外e){
Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
}
公共字符串getMimeType(字符串文件路径){
字符串类型=null;
字符串扩展名=getFileExtensionFromUrl(文件路径);
if(扩展名!=null){
MimeTypeMap mime=MimeTypeMap.getSingleton();
type=mime.getMimeTypeFromExtension(扩展名);
}
返回类型;
}
公共字符串getFileExtensionFromUrl(字符串url){
int dotPos=url.lastIndexOf('.');
如果(0这起作用
try {
String path = newString;
File myFile = new File(path);
Intent sharingIntent = new Intent("android.intent.action.SEND");
sharingIntent.setType(getMimeType(myFile.getPath()));
sharingIntent.putExtra("android.intent.extra.STREAM",Uri.fromFile(myFile));
startActivity(Intent.createChooser(sharingIntent,"Share using"));
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
public String getMimeType(String filePath) {
String type = null;
String extension = getFileExtensionFromUrl(filePath);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
}
public String getFileExtensionFromUrl(String url) {
int dotPos = url.lastIndexOf('.');
if (0 <= dotPos) {
return (url.substring(dotPos + 1)).toLowerCase();
}
return "";
}
试试看{
字符串路径=新闻字符串;
File myFile=新文件(路径);
Intent sharingcontent=newintent(“android.Intent.action.SEND”);
sharingIntent.setType(getMimeType(myFile.getPath());
sharingint.putExtra(“android.intent.extra.STREAM”,Uri.fromFile(myFile));
startActivity(Intent.createChooser(共享内容,“共享使用”);
}捕获(例外e){
Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
}
公共字符串getMimeType(字符串文件路径){
字符串类型=null;
字符串扩展名=getFileExtensionFromUrl(文件路径);
if(扩展名!=null){
MimeTypeMap mime=MimeTypeMap.getSingleton();
type=mime.getMimeTypeFromExtension(扩展名);
}
返回类型;
}
公共字符串getFileExtensionFromUrl(字符串url){
int dotPos=url.lastIndexOf('.');
如果(0