2013-11-23 48 views
-1

我試圖按照上的AndroidQuery應用程序的步驟「分享和發送圖片」發送和分享圖片

enter image description here 我都認真關注的代碼,並取得了一定的一切是完全一樣的,因爲它是在那裏,但我得到的錯誤。

我收到的「水性」,指出「含水不能得到解決」,並在「SEND_REQUEST」指出「SEND_REQUEST不能被解析爲一個變量」

會有人能夠幫助我這個錯誤,我不知道爲什麼我得到這些錯誤。

case R.id.ShareWallpaper: 



     String url = "http://i.telegraph.co.uk/multimedia/archive/02370/12C_Spider_4_2370457b.jpg"; 
     File file = aq.makeSharedFile(url, "car.png"); 

     if(file != null) { 


      Intent intent = new Intent(Intent.ACTION_SEND); 
      intent.setType("Image/jpeg"); 
      intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); 
      startActivityForResult(Intent.createChooser(intent, "Share via"), SEND_REQUEST); 

     } 


     break; 

    } 
    return super.onOptionsItemSelected(item); 
} 
+0

什麼是水性? ?? ..... – Piyush

+0

我不確定,他們顯然沒有顯示示例中的所有代碼 – Jack

+0

@kalyanpvs您無法從應用程序複製和粘貼,我從應用程序編寫代碼並嘗試理解它儘可能多 如我所能。 – Jack

回答

1

如果你想分享圖像使用本:

 Bitmap bm; 

     BitmapDrawable drawable = (BitmapDrawable) yourimageview.getDrawable(); 
     bm = drawable.getBitmap(); 
     Intent i = new Intent(android.content.Intent.ACTION_SEND); 
     i.setType("image/jpeg"); 
     ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
     bm.compress(Bitmap.CompressFormat.JPEG, 100, bytes); 
     File f = new File(Environment.getExternalStorageDirectory() 
       + File.separator + "temporary_file.jpg"); 
     try { 
      f.createNewFile(); 
      FileOutputStream fo = new FileOutputStream(f); 
      fo.write(bytes.toByteArray()); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     i.putExtra(Intent.EXTRA_STREAM, 
       Uri.parse("file:///sdcard/temporary_file.jpg")); 
     startActivity(Intent.createChooser(i, "Share via")); 

SEND_REQUEST是一個整型變量,所以你必須聲明它作爲一個全球性,如:

public final static int SEND_REQUEST =0;