gpt4 book ai didi

android - 无法使用 Apportable 在 Android 上打开邮件附件

转载 作者:行者123 更新时间:2023-11-29 17:52:11 26 4
gpt4 key购买 nike

我试过打开邮件附件。通过以下方法接收 url

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

但是无法从这个url获取数据

NSData *data = [NSData dataWithContentsOfFile:[url path]]
// data is nil

收到的网址

content://gmail-ls/mymail@gmail.com/messages/1/attachments/0.0/BEST/false

最佳答案

我已经使用 Android SDK 解决了这个问题。您可以查看如何将 java 与适当的 here 结合使用.

这是我的java代码

static private byte[] readBytes(InputStream inputStream) throws IOException {
// this dynamically extends to take the bytes you read
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();

// this is storage overwritten on each iteration with bytes
int bufferSize = 1048576;
byte[] buffer = new byte[bufferSize];

// we need to know how may bytes were read to write them to the byteBuffer
int len = 0;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}

// and then we can return your byte array.
return byteBuffer.toByteArray();
}

public byte[] dataFromUrl(String path, Activity activity) {
Uri uri = Uri.parse(path);

InputStream is = null;
byte[] data = null;

try {
is = activity.getContentResolver().openInputStream(uri);
data = readBytes(is);
} catch (Exception e) {
e.printStackTrace();
}

return data;
}

和 Objective-C 部分

+ (void)initializeJava
{
[super initializeJava];

// here your initialize code
...

[KeyboardBridge registerInstanceMethod:@"dataFromUrl"
selector:@selector(dataFromUrl:forActivity:)
returnValue:[NSData className]
arguments:[NSString className], [AndroidActivity className], nil];

}

- (NSData *)dataFromUrl:(NSString *)path {
return [self dataFromUrl:path forActivity:[AndroidActivity currentActivity]];
}

关于android - 无法使用 Apportable 在 Android 上打开邮件附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22094536/

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