通过intent发送位图图像和ImageView



我正在开发一个应用程序,我想在其中像whats应用程序一样发送地图位置。在我的应用程序中,我正在拍摄需要共享到whats应用程序的地图快照。我可以拍摄快照并通过将其与图像视图设置为测试进行测试。但是我无法将其共享到whats应用程序,我也创建了uri。但是它不起作用,请帮助我进行

@Override
    public void onClick(View view) {
        // TODO Auto-generated method stub
        switch (view.getId()) {
        case R.id.watsapp_button:
            takeSnapshot();
            Uri imgUri=Uri.parse("android.resource://com.koteswara.wise.plaeces/"+R.id.screenimage);
            //address = _gettext.getText().toString();
            //String uri = Uri.Builder().scheme("geo").appendPath(latitude +","+ longitude).appendQueryParameter("q", result).build();
            //String uri = "http://maps.google.com/maps?saddr=" +latitude+","+longitude;
            /*String uri = "geo:" + latitude + ","
                    +longitude + "?q=" + latitude
                    + "," + longitude;*/
            //Uri imgUri=Uri.parse("android.resource://my.package.name/"+R.drawable.image);
            String uri = 
            "http://maps.google.com/maps?q=" + latitude + "," + latitude + "&iwloc=A";
            Uri myUri = Uri.parse(uri);
                    Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND);
                    //Target whatsapp:
                    shareIntent.setPackage("com.whatsapp");
                    //Add text and then Image URI
                    shareIntent.putExtra(Intent.EXTRA_TEXT, result);
                    System.out.println(result);
                    System.out.println(uri);
                    shareIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
                    shareIntent.setType("image/*");
                    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    try {
                        startActivity(shareIntent);
                    } catch (android.content.ActivityNotFoundException ex) {
                        //ToastHelper.MakeShortText("Whatsapp have not been installed.");
                    }
            break;

下面的代码显示了拍摄快照

private void takeSnapshot() {
            if (googleMap == null) {
                return;
            }

            final SnapshotReadyCallback callback = new SnapshotReadyCallback() {
                @Override
                public void onSnapshotReady(Bitmap snapshot) {
                    // Callback is called from the main thread, so we can modify the ImageView safely.
                    _snapshot=snapshot;
                    snapshotHolder.setImageBitmap(snapshot);
                    System.out.println(snapshotHolder+"snap shot ");
                }
            };
googleMap.snapshot(callback);

     }
below is the image view
snapshotHolder=(ImageView)rootview.findViewById(R.id.screenimage);



 Uri imgUri=Uri.parse("android.resource://com.koteswara.wise.plaeces/"+R.id.screenimage);
in the above uri the R.id.screenimage is the id of the imageview i am setting the snap shot of the map-view

任何人请帮我发送我通过意图与whats应用程序共享的地图快照,我们将提前感谢

您可以尝试将图像转换为字节格式,然后通过Intent的putExtra()方法进行传递。

 Bitmap snapshot;
 ByteArrayOutputStream stream=new ByteArrayOutputStream();
 snapshot.compress(Bitmap.CompressFormat.JPEG, 90, stream);
 byte[] temp_photo=stream.toByteArray();
 Intent shareIntent=new Intent();
 shareIntent.putExtra("Image_Key",temp_photo);

最新更新