0
我需要一個字符串來共享我的代碼,下面隨機生成一個句子,不能共享或複製並粘貼所選短語。對不起我的英語我需要共享一個隨機生成的短語
public class MainActivity extends ActionBarActivity {
private TextView textViewNewId;
private Button buttonNewId;
private String[] frases = {
"First phrase", "second phrase", "third phrase"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
textViewNewId = (TextView) findViewById(R.id.textViewNewId);
buttonNewId = (Button) findViewById(R.id.buttonNewId);
buttonNewId.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Random randomico = new Random();
int numeroAleatorio = randomico.nextInt(frases.length);
textViewNewId.setText(frases[ numeroAleatorio ]);
}
});
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View vivew) {
fab();
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
// .setAction("Action", null).show();
}
});
}
private void fab() { //sharing implementation here
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "AndroidSolved");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Now Learn Android with AndroidSolved clicke here to visit ");
startActivity(Intent.createChooser(sharingIntent, "Share via"));
}