2012-11-02 24 views
0

我試圖使用共享意圖從我的應用程序分享給Hyves。如果我安裝了hyves應用程序並從庫中共享,它將切換到hyves應用程序,並將圖像正確地上傳到hyves,所以它應該可以工作。Android分享特定應用程序和位圖資源的意圖

問題是,我無法找到它記錄了Hyves的正確意圖應該是如何工作的,但我只能假設,畫廊上傳圖片,所以我有這樣的:

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應用程序超時。

所以,我可以在意圖使用位圖,並可以setPackage或我應該setClass?

Tnx

回答

1

也許你不能把位圖直接放在意圖中。 首先轉換成位圖的字節數組不是發送另一邊,並轉換成位圖

//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); 

我希望是把圖像

+0

出於某種原因,這並沒有幫助正確的方式,所以我裝來自SD卡的圖像,工作正常。 – Balkyto

+0

好吧,這也是正確的方式 – urveshpatel50

相關問題