Android Share Whatsapp onActivityForResult

时间:2017-07-24 06:20:03

标签: android whatsapp

当我与Whatsapp共享文本时,我如何知道共享是成功还是取消?

喜欢OnActivityForResult。我想要方便分享的地位。

1 个答案:

答案 0 :(得分:1)

我为您提供了解决方案,在onActivityResult的帮助下,您可以在WhatsApp上共享任何内容后获得回调。请使用以下 步骤1.开始尝试从其他应用程序接收结果

  Intent sendIntent = new Intent();
  sendIntent.setAction(Intent.ACTION_SEND);
  sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
  sendIntent.setType("text/plain");
  startActivityForResult(sendIntent,1); //1 is request code

步骤2.在活动中取消onActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Toast.makeText(MainActivity.this.getApplicationContext(),"onActivityResult..:",Toast.LENGTH_SHORT).show();
    if(resultCode==RESULT_OK) {
        if (requestCode == 1) {
            Toast.makeText(MainActivity.this.getApplicationContext(), "Got Callback yeppeee...:", Toast.LENGTH_SHORT).show();
        }
    }
}