-->

How to program a sharing button in Sketchware

How to program a sharing button in Sketchware
To program an app that is able to text contents or URLs in Sketchware is possible using intent, but the data can only be shared using individual urls to emails, facebook, twitter, and other sites which provide a sharing option, individually. But in order to implement a share button for sharing content, some code is to be added in the project using add source directly block.
Take following the steps below to add a share button in Sketchware:-
1. Assuming you want to share the contents of field Edittext1 as title and of field Edittext2 as main content. For sharing the contents, first insert a button or an imageview with share icon.(design a normal layout Field with edittext 1 & 2 with a button {for perform the sharing action} )
2. In LOGIC area, in the onClick event for button, which is to be used as share button, add two string variables x and y.
3. Set string variable x to contents of
Edittext1 field, and variable y to contents of Edittext2 field.(block setString value= edittext1)
4. Create an intent and name it 'i' Add the following code in add source directly block:
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain"); i.putExtra(android.content.Intent.EXTRA_SUBJECT, x); i.putExtra(android.content.Intent.EXTRA_TEXT, y); startActivity(Intent.createChooser(i,"Share using"));
Note that in the code, i is name of intent, x is name of a string variable, and y is also name of a string variable.
4. Save and run the project.