0
我試圖將資產文件夾中的圖像附加到電子郵件。但我沒有得到在相當大的成功,而我已經能夠從資產與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);
請建議。
在此先感謝。
查看我答案的Edit1。 –