user3112051
user3112051

Reputation: 11

Share intent Android

I have created an application in android that generates a random text from an array list. Now i want to share the text that java code has generated... cau u please help me? this is my code:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sorella);


         Resources res = getResources();    
         myString = res.getStringArray(R.array.myArray); 

            String q = myString[rgenerator.nextInt(myString.length)];

            TextView tv = (TextView) findViewById(R.id.text1);
            tv.setText(q);

            Button home=(Button)findViewById(R.id.bottone);    
            home.setOnClickListener(new OnClickListener(){    


                        public void onClick(View arg0) {  

                            Intent shareIntent = new Intent(Intent.ACTION_SEND);
                            shareIntent.setType("text/plain");
                            shareIntent.putExtra(Intent.EXTRA_TEXT, "HERE GENERATE TEXT FROM ARRAY LIST");
                            startActivity(Intent.createChooser(shareIntent, "Condividi con...")); 
                        }    
            }); 

    }

}

Upvotes: 1

Views: 2828

Answers (1)

rachit
rachit

Reputation: 1996

try this

    super.onCreate(savedInstanceState);
    setContentView(R.layout.sorella);


     Resources res = getResources();    
     myString = res.getStringArray(R.array.myArray); 

        final String q = myString[rgenerator.nextInt(myString.length)];

        TextView tv = (TextView) findViewById(R.id.text1);
        tv.setText(q);

        Button home=(Button)findViewById(R.id.bottone);    
        home.setOnClickListener(new OnClickListener(){    


                    public void onClick(View arg0) {  

                        Intent shareIntent = new Intent(Intent.ACTION_SEND);
                        shareIntent.setType("text/plain");
                        shareIntent.putExtra(Intent.EXTRA_TEXT, q);
                        startActivity(Intent.createChooser(shareIntent, "Condividi con...")); 
                    }    
        }); 

Upvotes: 5

Related Questions