gpt4 book ai didi

android - 无法使用 Gmail 共享 Assets 中的图像

转载 作者:太空狗 更新时间:2023-10-29 14:44:05 25 4
gpt4 key购买 nike

我尝试分享来自 Assets 的图像。 Gmail 显示 toast “无法附加空文件”。当我尝试另一个电子邮件客户端时,应用程序会显示附件预览,当我按下发送按钮时,电子邮件应用程序会崩溃或关闭,我不确定。共享适用于 Skype。我还尝试与 VK 分享图像。它加载并成功显示缩略图,但加载后它在图像上显示错误标签。我不知道它是如何工作的,因为我没有提供任何缩略图。

这是我的内容提供者:

public class AssetsContentProvider extends ContentProvider {
public static final String TAG = AssetsContentProvider.class.getSimpleName();

@Override
public boolean onCreate() {
return true;
}

@Nullable
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
return null;
}

@Nullable
@Override
public String getType(Uri uri) {
return null;
}

@Nullable
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}

@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
return 0;
}

@Override
public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
Context context = getContext();
if (context == null) {
throw new RuntimeException("content == null");
}

AssetManager assetManager = context.getAssets();
String filePath = uri.getPath();

if (filePath != null) {
filePath = Strings.removeFromStart(filePath, "/");
}
if(Strings.isEmpty(filePath)) {
Log.e(TAG, "filePath is empty, invalid uri");
throw new FileNotFoundException("filePath is empty, invalid uri");
}

AssetFileDescriptor fileDescriptor = null;
try {
fileDescriptor = assetManager.openFd(filePath);
} catch (IOException e) {
Log.e(TAG, "assetManager.openFd failed", e);
}
return fileDescriptor;
}
}

assetManager.openFd(filePath); 运行成功。

这是我分享图片的方式:

public static void shareImage(Context context, Uri uri) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
context.startActivity(intent);
}
private String getImagePathInAssets(String item) {
return bookInfo.bookFileName + "/" + item;
}

private void share(String item) {
Uri uri = Uri.parse("content://com.captainhappiness/" + getImagePathInAssets(item));
SocialUtils.shareImage(context, uri);
}

这是我在 gmail 日志中发现的:

W/Gmail: No itemId found for event forward
03-13 14:30:32.448 12507-12507/? W/Gmail: Error opening file to obtain size.
03-13 14:30:32.448 12507-12507/? W/Gmail: java.io.FileNotFoundException: Not a whole file
03-13 14:30:32.448 12507-12507/? W/Gmail: at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:820)
03-13 14:30:32.448 12507-12507/? W/Gmail: at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:758)
03-13 14:30:32.448 12507-12507/? W/Gmail: at dma.a(SourceFile:481)
03-13 14:30:32.448 12507-12507/? W/Gmail: at dma.a(SourceFile:441)
03-13 14:30:32.448 12507-12507/? W/Gmail: at cmk.a(SourceFile:3756)
03-13 14:30:32.448 12507-12507/? W/Gmail: at cmt.run(SourceFile:23709)
03-13 14:30:32.448 12507-12507/? W/Gmail: at cmk.a(SourceFile:23689)
03-13 14:30:32.448 12507-12507/? W/Gmail: at cmk.a(SourceFile:1405)
03-13 14:30:32.448 12507-12507/? W/Gmail: at cmk.K(SourceFile:1542)
03-13 14:30:32.448 12507-12507/? W/Gmail: at cmk.onCreate(SourceFile:31759)
03-13 14:30:32.448 12507-12507/? W/Gmail: at com.google.android.gm.ComposeActivityGmail.onCreate(SourceFile:225)
03-13 14:30:32.448 12507-12507/? W/Gmail: at android.app.Activity.performCreate(Activity.java:6093)
03-13 14:30:32.448 12507-12507/? W/Gmail: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1115)
03-13 14:30:32.448 12507-12507/? W/Gmail: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2566)
03-13 14:30:32.448 12507-12507/? W/Gmail: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2677)
03-13 14:30:32.448 12507-12507/? W/Gmail: at android.app.ActivityThread.access$800(ActivityThread.java:176)
03-13 14:30:32.448 12507-12507/? W/Gmail: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1529)
03-13 14:30:32.448 12507-12507/? W/Gmail: at android.os.Handler.dispatchMessage(Handler.java:111)
03-13 14:30:32.448 12507-12507/? W/Gmail: at android.os.Looper.loop(Looper.java:194)
03-13 14:30:32.448 12507-12507/? W/Gmail: at android.app.ActivityThread.main(ActivityThread.java:5747)
03-13 14:30:32.448 12507-12507/? W/Gmail: at java.lang.reflect.Method.invoke(Native Method)
03-13 14:30:32.448 12507-12507/? W/Gmail: at java.lang.reflect.Method.invoke(Method.java:372)
03-13 14:30:32.448 12507-12507/? W/Gmail: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1104)
03-13 14:30:32.448 12507-12507/? W/Gmail: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
03-13 14:30:32.450 12507-12507/? W/Gmail: Error adding attachment - empty attachment

最佳答案

你可以试试;

shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));

有关更多信息,请查看开发人员门户; https://developer.android.com/training/sharing/send.html

关于android - 无法使用 Gmail 共享 Assets 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42763356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com