我正在尝试使用share intent从我的应用程序共享到Hyves。如果我安装了hyves应用程序并从图库共享它,请切换到hyves应用程序,并将图像正确上传到hyves,因此它应该可以工作。
问题是,我找不到关于hyves的正确意图的文档,但我假设gallery只上传图像,所以我有以下内容:
Bitmap image = BitmapFactory.decodeFile(MyGlobals.INSTANCE.activeSetting.f_image_path);
这是我在应用程序中拉取“活动”或“选定”图像的代码行。在这一点上,图像被保存到SD卡,所以我可能会读取uri而不是解码文件,但我希望以这种方式对hyves和facebook具有相同的方法。
然后我会调用:
Intent hyvesIntent = new Intent(Intent.ACTION_SEND);
hyvesIntent.setPackage("com.hyves.android.application");
hyvesIntent.setType("image/jpeg");
hyvesIntent.putExtra("image", image);
startActivityForResult(hyvesIntent, 666);
首先,我不确定是否可以在这里使用setPackage,但我正在检查此包是否存在以启用/禁用共享,这是可见的包名称。
我需要活动结果,然后通知图像是否共享。
这里发生了什么它启动了Hyves应用程序,但我得到了全白屏幕,然后Hyves应用程序超时。
那么,我可以在intent中使用位图吗,是否可以使用setPackage,还是应该使用setClass?
Tnx
发布于 2012-11-02 12:28:56
也许你不能直接把位图放在意图中。首先将位图转换为字节数组,然后发送另一面并转换为位图
//convert bitmap to bytearray
public static byte[] getBitmapAsByteArray(Bitmap bitmap, boolean type) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
if (type) {
bitmap.compress(CompressFormat.PNG, 0, outputStream);
} else {
bitmap.compress(CompressFormat.JPEG, 0, outputStream);
}
return outputStream.toByteArray();
}
//convert bitmap to bytearray
public static Bitmap getBitmap(byte[] imgByte){
Bitmap bm = BitmapFactory.decodeByteArray(imgByte, 0, imgByte.length);
return bm;
}
//than intent
Intent hyvesIntent = new Intent(Intent.ACTION_SEND);
hyvesIntent.setPackage("com.hyves.android.application");
hyvesIntent.setType("image/jpeg");
hyvesIntent.putExtra("image", getBitmapAsByteArray(image,true));
startActivityForResult(hyvesIntent, 666);
我希望这是正确的形象表达方式。
https://stackoverflow.com/questions/13194619
复制