【问题标题】:sending bitmap image and ImageView through intent通过 Intent 发送位图图像和 ImageView
【发布时间】:2015-12-27 09:29:14
【问题描述】:

我正在开发一个应用程序,我想在其中发送地图位置,例如什么应用程序。在我的应用程序中,我正在拍摄需要共享到什么应用程序的地图的快照。我可以拍摄快照并通过将图像视图设置为 test.bu 进行测试

@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应用解决方案分享的地图快照将提前感谢

【问题讨论】:

    标签: android google-maps android-intent bitmap uri


    【解决方案1】:

    你尝试将你的图片转换成字节格式,然后你可以通过 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);
    

    【讨论】:

    • 给出错误 byte[] cannot be cast to android.os.Parcelable.
    • 有没有办法使用位图图像创建 Uri 并将其作为 shareIntent.putExtra(Intent.EXTRA_STREAM, Uri);
    • 如何将位图图像存储到内部存储中并获取特定存储的图像并在功能结束后删除请给我任何示例代码如果有人有它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 2012-08-27
    • 2014-01-16
    • 2020-11-21
    相关资源
    最近更新 更多