2015-06-26 61 views
0

在以下我成功將屏幕截圖保存在內部存儲器中。但Gmail和許多其他應用程序表示他們不能共享除了whatsapp和藍牙之外的空文件。我知道內部存儲器不允許在應用程序之間共享。我使用了Environment.getExternalDirectory。 我的目標是將其提供給Gmail。 我已閱讀所有以前的問題,我無法找到解決方案。 我該如何分享和錯誤?我在這裏錯過了什麼? getExternalStorageDirectory()給出sdcard0的路徑,以防萬一我的內部存儲器和我的sdcard是sdcard1。如何從內部存儲器共享圖像到Gmail?

public void captureScreen() 
{ 


    GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback() 
    { 

     @Override 
     public void onSnapshotReady(Bitmap snapshot) 
     { 


      try 
      { 

       FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/MapScreenshot"+System.currentTimeMillis()+".png"); 
       snapshot.compress(Bitmap.CompressFormat.PNG, 90, out); 

       Toast.makeText(Map.this, "Path Captured as Image, saved in" + path,Toast.LENGTH_LONG).show(); 

      } 
      catch (Exception e) 
      { 
       Log.e("Image not saved", ""); 
       e.printStackTrace(); 
      } 

     } 




    }; 

    googleMap.snapshot(callback); 
    AlertDialog.Builder builder=new AlertDialog.Builder(this); 
    builder.setMessage(R.string.dialog_share_text).setPositiveButton(R.string.share_button, new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int id) { 
      //user shared 
      Intent sharingIntent=new Intent(Intent.ACTION_SEND); 
      sharingIntent.setType("image/png"); 
      sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path)); 
      startActivity(Intent.createChooser(sharingIntent, "Share Image Using")); 
     } 
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int id) { 
      //user cancelled 
     } 
    }).show(); 
} 

回答

0

試試這個代碼共享Screenshotgmail左右

String path = Images.Media.insertImage(getContentResolver(), yourBitmap, 
       "title", null); 
     Uri screenshotUri = Uri.parse(path); 
     final Intent emailIntent1 = new Intent(
       android.content.Intent.ACTION_SEND); 
     emailIntent1.setType("text/plain"); 
     emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     emailIntent1.putExtra(Intent.EXTRA_STREAM, screenshotUri); 
     emailIntent1.setType("image/png"); 
     startActivity(Intent 
       .createChooser(emailIntent1, "Send email using")); 

通過thanks..but我如何使用位圖使用快照的方法和MapView的類在insert.image()

+0

位圖不推薦使用..getDrawingCache不能使用..不能想象.. –

+0

你正在做什麼?你想要實現什麼? –

+0

即時通訊建立一個本地導航應用程序..它存儲在陣列中的用戶的動態位置..並使折線,並在最後使用戶可以保存該路徑或地圖作爲圖像供以後使用..所以它可以與gmail分享..我是一個新手android。後生病要加卡路里計算器等等等等等等等等等等等等等等等等等等等等等等等。 –

相關問題