2012-03-20 9 views
0

こんにちは私はあなたがサムネイルをクリックすると、イメージビューでイメージを表示する私のアプリでギャラリーがあります。私は壁紙と共有するための2つのボタンを1つ持っている警告ダイアログのための長いクリックリスナーを設定しています。私は共有の意図を持っており、描画キャッシュはいくらか働いています。私の携帯電話ではなく、エミュレータで動作します。私はこのサイトで多くの例を使ってこれを行ってきましたが、それはまったく動作しません。それは強制的に私の携帯電話でアプリケーションを閉じて保持します。どんな助けもありがとう。ImageView Share Intent

   alertDialog.setButton2("Share", 
        new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, 
           int which) { 
          imgView.setDrawingCacheEnabled(true); 
          Bitmap b = imgView.getDrawingCache(); 
          File sdCard = Environment.getExternalStorageDirectory(); 
          File file = new File(sdCard, "image.jpg"); 
          FileOutputStream fos; 
          try { 
           fos = new FileOutputStream(file); 
           b.compress(CompressFormat.JPEG, 95,fos); 
           } catch (FileNotFoundException e) { 
           // TODO Auto-generated catch block 
           e.printStackTrace(); 
           } 

          Log.d("Save Example", "Image saved."); 

          Intent intent = new Intent(Intent.ACTION_SEND); 
          intent.setType("image/jpeg"); 
          intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/image.jpg")); 

          startActivity(Intent.createChooser(intent, "Share Picture Via..")); 
         } 

      }); 

      alertDialog.show(); 
      return true; 

更新:NULLポインタを言い続け

b.compress(CompressFormat.JPEG, 95, fos); 

に問題があるようです。

nullポインタは実際にはread_onlyエラーです。実際にファイルを書き込んでいないので、ioexception読み取り専用ファイルシステムを取得します。なぜこれをやっているのですか?

答えて

0
imgView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); imgView.layout(0, 0, imgView.getMeasuredWidth(), imgView.getMeasuredHeight()); 

これは

Bitmap b = imgView.getDrawingCache(); 

前に助けている場合、これは Android drawing cache

に役立ちますかどうかを確認も参照してください。