当按下分享按钮时,“分享通过”菜单仅在4秒后出现

问题描述:

当我按下我的应用程序中的分享按钮时,4秒后出现“通过剃须”菜单。当我从Gallery应用程序或Whatsapp执行相同的操作时,它会在半秒钟内出现。我猜这与我的旧智能手机无关,因为在其他地方它运行速度非常快。我错过了什么?当按下分享按钮时,“分享通过”菜单仅在4秒后出现

这是代码:

 shareButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      mTracker.send(new HitBuilders.EventBuilder() 
        .setCategory("Action") 
        .setAction("Share photo") 
        .build()); 
      Uri bmpUri = getLocalBitmapUri(imageView); 
      if (bmpUri != null) { 
       ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
       ClipData clip = ClipData.newPlainText(EditView.getText(), EditView.getText()); 
       clipboard.setPrimaryClip(clip); 

       Intent shareIntent = new Intent(); 
       shareIntent.setAction(Intent.ACTION_SEND); 
       shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); 
       shareIntent.setType("image/*"); 
       startActivity(Intent.createChooser(shareIntent, "Share Image")); 
      }else{ 
       Toast.makeText(getApplicationContext(), "You need to upload a photo first", Toast.LENGTH_SHORT).show(); 
      } 
     } 
    }); 
+0

你试过在调试器中浏览代码以找出哪一行代码需要这么长时间? 你没有试过它没有getLocalBitmapUri() 你没有尝试过没有ClipboardManager或ClipData? – apmartin1991

+0

我试过没有ClipboardManager或ClipData但没有getLocalBitmapUri()。我现在用调试器检查它。谢谢! –

这里你的问题将是getLocalBitmapUri我在其他地方看到了这个功能,它做了很多工作,在主线程中,如加载图像,压缩图像然后将图像保存到手机存储中。取决于文件大小,这可能需要一些时间。

如果这是由设计,那么你可以显示ProgressDialog像这样

final ProgressDialog dialog = ProgressDialog.show(getActivity(), null, "Please wait whilst we load your image", true); 

然后用

dialog.dismiss(); 

关闭该对话框调用之前:

startActivity(Intent.createChooser(shareIntent, "Share Image")); 
+0

当我正在考虑这个问题时,我不确定为什么我真的需要“getLocalBitmapUri”。我想要的只是分享我的imageview到另一个应用程序。有没有“getLocalBitmapUri”共享ImageView的方法? –