无法将文件附加到Android资产文件夹中的电子邮件应用程序
问题描述:
我试图将资产文件夹中的图像附加到电子邮件。但我没有得到在相当大的成功,而我已经能够从资产与ContentProvider的帮助无法将文件附加到Android资产文件夹中的电子邮件应用程序
公共类AssetProvider扩展ContentProvider的{
@Override
public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException
{
Log.v("HERREEE", "AssetsGetter: Open asset file");
AssetManager am = getContext().getAssets();
String file_name = uri.getLastPathSegment();
if(file_name == null)
throw new FileNotFoundException();
AssetFileDescriptor afd = null;
try
{
afd = am.openFd(file_name);
}
catch(IOException e)
{
e.printStackTrace();
}
return afd;//super.openAssetFile(uri, mode);
}
@Override
public String getType(Uri p1)
{
// TODO: Implement this method
return null;
}
@Override
public int delete(Uri p1, String p2, String[] p3)
{
// TODO: Implement this method
return 0;
}
@Override
public Cursor query(Uri p1, String[] p2, String p3, String[] p4, String p5)
{
// TODO: Implement this method
return null;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal)
{
// TODO: Implement this method
return super.query(uri, projection, selection, selectionArgs, sortOrder, cancellationSignal);
}
@Override
public Uri insert(Uri p1, ContentValues p2)
{
// TODO: Implement this method
return null;
}
@Override
public boolean onCreate()
{
return false;
}
@Override
public int update(Uri p1, ContentValues p2, String p3, String[] p4)
{
// TODO: Implement this method
return 0;
}
}
代码张贴鸣叫的图像从资产文件夹图像叽叽喳喳:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT,"Test tweet");
intent.setType("*/*");
final PackageManager pm = mContext.getPackageManager();
final List<?> activityList = pm.queryIntentActivities(intent, 0);
int len = activityList.size();
boolean isFound = false;
for (int i = 0; i < len; i++) {
final ResolveInfo app = (ResolveInfo) activityList.get(i);
if(app.activityInfo.packageName.contains("com.twitter.android")){
isFound = true;
final ActivityInfo activity=app.activityInfo;
final ComponentName name=new ComponentName(activity.applicationInfo.packageName, activity.name);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.setComponent(name);
Uri uri = Uri.parse("content://com.authority/file:///android_asset/image.png");
intent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
mContext.startActivity(intent);
break;
}
}
但是,尽管电子邮件做同样的,它提供了消息“无法附加空文件”
电子邮件:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_SUBJECT, "Checkout MY Application");
intent.putExtra(Intent.EXTRA_TEXT, "Test mail");
Uri uri = Uri.parse("content://com.authority/file:///android_asset/image.png"));
intent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
mContext.startActivity(intent);
请建议。
在此先感谢。
答
最新Facebook应用版本不允许您使用意图共享文本。您必须使用Facebook SDK共享/发布帖子,或者您只能分享图片或网址。
请参考post,它表示Facebook设计团队故意关闭了预先填写的信息,因为它违反了他们的政策。
欲了解更多信息,您可以参考这些堆栈溢出问题:
- Share Text on Facebook from Android App via ACTION_SEND
- Android: How to share image with text on facebook via intent?
编辑1:有一个变通参照此SO Answer。
查看我答案的Edit1。 –