0

電子メールと mms 経由で画像を共有するには、最初のステップで画像を SD カードに保存する必要がありますが、保存された画像が開かれず、代わりに「無効なファイル」エラーが発生しました。拡張フォーマットですべてが正しいことを確認しましたが、場所がわかりません私は間違っています。

以下はJavaコードです。

public class Share extends CordovaPlugin {

    public static final String ACTION_POSITION = "ShareImage";

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
            throws JSONException {
        if (ACTION_POSITION.equals(action)) {
            try {
                JSONObject arg_object = args.getJSONObject(0);
                Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
                sendIntent.setType("image/jpg");
                sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, arg_object.getString("image"));
                String name = arg_object.getString("image");
                String defType = "drawable";
                String defPackage = "com.picsswipe";
                int drawableId = this.cordova.getActivity().getResources().getIdentifier( name , defType, defPackage );

              //  Bitmap bbicon = BitmapFactory.decodeFile( arg_object.getString("image") );
                Bitmap bbicon = BitmapFactory.decodeResource( this.cordova.getActivity().getResources(),drawableId  );

                 String extStorageDirectory = Environment.getExternalStorageDirectory().toString();         
                OutputStream outStream = null;              

                 File f = new File(extStorageDirectory + "/Download/",
                         "jj.jpg" );
                 try {
                        outStream = new FileOutputStream(f); 
                         bbicon.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
                        outStream.flush();
                        outStream.close();              
                    } catch (Exception e) {
                    }                       

                File r1 = new File(Environment.getExternalStorageDirectory()
                        .getAbsolutePath() + "/Download/", "jj.jpg");

               //RETRIEVING IMAGES FROM SDCARD                         

                Uri uri1 = Uri.fromFile(r1);    
                sendIntent.putExtra(Intent.EXTRA_STREAM, uri1);      
                sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(r1));                                 
                 Uri uris = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "jj.jpg"));                            
                this.cordova.getActivity().startActivity(sendIntent);
            } catch (Exception e) {
                System.err.println("Exception: " + e.getMessage());
                callbackContext.error(e.getMessage());
                return false;
            }
        }
        return true;
    }
}
4

1 に答える 1