与Intent to Whats App共享图像和文本

时间:2019-01-24 01:56:39

标签: android share

我正在尝试将@ECHO ON SET Loc1Dir=C:\Users\*****\Desktop\temp SET Loc2Dir=S:\shared\*****\*****\Input\Run\Working_Folder CD /D "%Loc1Dir%" FOR /R %%F IN ("*.STMT*") DO CALL :CopyFile %%~F FOR /R %%I IN ("*.CARD*") DO CALL :CopyFile2 %%~I :CopyFile SET copyfname=%~1 SET fname=driver ECHO F | XCOPY /Y /F "%copyfname%" "%Loc2Dir%\%fname%" :::CALL :CopyFile2 :::GOTO :EOF :CopyFile2 SET copyfname2=%~1 SET fname2=card ECHO F | XCOPY /Y /F "%copyfname2%" "%Loc2Dir%\%fname2%" 中带有文字标题的图像共享给whatsApp,但是我在网上找到的解决方案似乎对我不起作用。

imageview

1 个答案:

答案 0 :(得分:2)

  • 这是在whatsapp中共享图像和文本的代码。

    View screenView = rootView.getRootView();
    screenView.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
    screenView.setDrawingCacheEnabled(false);
    
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(this.getContentResolver(), bitmap, "Title", null);
    
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType("image/*");
    
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
    intent.putExtra(android.content.Intent.EXTRA_TEXT, "Your message");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
    try {
        startActivity(Intent.createChooser(intent, "Share Screenshot"));
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, "No App Available", Toast.LENGTH_SHORT).show();
    }