Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android手机中自动发送彩信或短信截图?2._Android - Fatal编程技术网

如何在android手机中自动发送彩信或短信截图?2.

如何在android手机中自动发送彩信或短信截图?2.,android,Android,我已经创建了自己的相机应用程序。当我点击按钮时,它会拍摄照片并将其保存在多媒体资料中。我想做的是拍照并自动发送彩信。现在我使用文件目录发送彩信,但它并没有重放照片,只是显示普通文本。请帮我从这个代码发送照片 private File getOutputMediaFile(int type) { // To be safe, you should check that the SDCard is mounted // using Environment.getExt

我已经创建了自己的相机应用程序。当我点击按钮时,它会拍摄照片并将其保存在多媒体资料中。我想做的是拍照并自动发送彩信。现在我使用文件目录发送彩信,但它并没有重放照片,只是显示普通文本。请帮我从这个代码发送照片

private File getOutputMediaFile(int type) {
        // To be safe, you should check that the SDCard is mounted
        // using Environment.getExternalStorageState() before doing this.

        File mediaStorageDir = new File(
                Environment
                        .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                "MyCameraApp");

        // This location works best if you want the created images to be shared
        // between applications and persist after your app has been uninstalled.

        // Create the storage directory if it does not exist

        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                return null;
            }
        }

        // Create a media file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
                .format(new Date());
        File mediaFile;
        if (type == MEDIA_TYPE_IMAGE) {
            mediaFile = new File(mediaStorageDir.getPath() + File.separator
                    + "IMG_" + timeStamp + ".jpg");
        } else {
            return null;
        }

//      Intent sendIntent = new Intent(Intent.ACTION_SEND); 
//      sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
//      sendIntent.putExtra("sms_body", "5556"); 
//      sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(timeStamp));
//      sendIntent.setType("image/png");
//      startActivity(sendIntent); 

//        Intent smsIntent = new Intent(Intent.ACTION_VIEW);
//        smsIntent.setData(Uri.parse("smsto:"));
//        smsIntent.setType("vnd.android-dir/mms-sms");
//        smsIntent.putExtra("5556"  , "5556");
//        startActivity(smsIntent);
//        finish();
//      
        Intent sendIntent = new Intent(Intent.ACTION_SEND); 
        sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
        sendIntent.putExtra("sms_body", number); 
        sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mediaFile));
        sendIntent.setType("image/*");
        startActivity(sendIntent); 


        return mediaFile;
    }

我通过jersey rest web服务实现了这一点

以下是我的Web服务:

@POST
    @Path("/post/images")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response imageUpload(@FormDataParam("image") InputStream hereIsImage, @FormDataParam("image") FormDataContentDisposition hereIsName) {
        String path = System.getenv("HOME")+"/tmp/";
        if(hereIsName.getSize()==0) {
            return Response.status(500).entity("image parameter is missing").build();
        }
        String name = hereIsName.getFileName();
        path += name;

        try {
            OutputStream out = new FileOutputStream(new File(name));
            int read;

            byte[] bytes = new byte[1024];
            while ((read = hereIsImage.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            out.flush();
            out.close();
        } catch (IOException e) {
            return Response.status(500).entity(name + " was not uploaded\n"+e.getMessage()).build();
        }
        return Response.status(200).entity(name + " was uploaded").build();
    }
在安卓系统中,您可以执行以下操作:

public void makeImagePost(byte[] image, String resource, String url) {
        try {
            httpClient = new DefaultHttpClient();
            HttpPost postRequest = new HttpPost(resource);
            ByteArrayBody bab = new ByteArrayBody(image, url+".jpg");
            MultipartEntity reqEntity = new MultipartEntity(
                    HttpMultipartMode.BROWSER_COMPATIBLE);
            reqEntity.addPart("image", bab);
            postRequest.setEntity(reqEntity);
            HttpResponse response = httpClient.execute(postRequest);
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    response.getEntity().getContent(), "UTF-8"));
            String sResponse;
            StringBuilder s = new StringBuilder();
            while ((sResponse = reader.readLine()) != null) {
                s = s.append(sResponse);
            }
            System.out.println("Response: " + s);
        } catch (Exception e) {
            // handle exception here
            e.printStackTrace();
        }
    }

如果图像很大,您不必担心,jersey会将块分开并将文件分块发送

你打算如何发送照片?网络服务?我想发送带有图像的彩信或短信。。。Uri.fromfile是否正常??很多地方都有Uri.parse,请帮助我。我的目录所有内容都在这里..此用户已重复并询问了此内容。bro此主题不适用于我需要帮助请您为我的代码中的图像提供字符串路径??如果它存储在库中,则它位于/sdcard/DCIM/Camera内。或者类似的东西,这取决于你有什么智能手机我不会从这个代码中找到这个路径。。。mediaFile=newfilemediastoragedir.getPath+File.separator+IMG\uu+timeStamp+.jpg;你可能可以这样做,但你需要确保你的智能手机用这种逻辑保存图像。如果成功了,它可以工作