0

I want to use a floating action button for opening a new message from my android phone. I have used startActivityForResult() method for successfully opening settings. But when I use the same for opening messages, this method doesn't seem to work. I have also attached my code to be more clear.

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               startActivityForResult(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS),0);
                /*Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();*/
            }
        });
4

2 回答 2

1

您可以发送此意图:

Intent intent = new Intent(Intent.ACTION_VIEW);         
intent.setData(Uri.parse("sms:"));
startActivity(intent);

请注意,在这种情况下startActivityForResult没有必要,因为第二个活动不应该向第一个活动返回值。

于 2016-05-16T06:03:00.903 回答
0

尝试这样的事情:

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              Intent sendIntent = new Intent(Intent.ACTION_VIEW);         
              sendIntent.setData(Uri.parse("sms:"));
              startActivityForResult(sendIntent , 0);

            }
        });
于 2016-05-16T06:01:30.727 回答