Develop Android Apps, How to Code Share Text
Next Tutorial
Coding a Share Intent for Images

Prev Page
View All Tutorials


Coding a Share Intent for Text

If you are just arriving at this page; and you are not familiar with creating Android Apps, we suggest you begin with our tutorials: Coding Android App Pages and How To Create a Simple App in Android

From there follow along with each tutorial lesson.


This is the App - ShareActionSend
It can share the 'text' from the screen view.
You can share the text to your social sites or other apps on your device

Share Text App

Where - How To Use Intents to Share Text

There are many methods you can code to share text in your android apps; in this app we have coded one such method. It is a simple way to share text from an app page (screen view) in your app.

Choose The Share Text...destination App
When the app page loads, the 'Share...chooser' prompts you to choose where to send the text. Depending on what apps you have installed on your device, it could be your social sites like Facebook, Twitter, or apps like DroidEdit(text and editing), or perhaps your cloud storage like OneDrive(microsofts' free storage in the cloud).
To send the text, just click the destination app icon, and text is sent to that app.
Share Prompt Loads on App Page Load
This method is ideal if you want the 'Share...prompt' to display when the app page is first opened. It will only show the one time; which is when the app page is first loaded into the screen view.
Add To Any App Page
You can add a Share Text like this one to just one page in your app or to any number of app pages. This Share Intent for text method can be used for a variety of reasons in an android app.

One example might be if you had a learning website; like say math; and you wanted to give your users the math problems and answers so they could access them offline; or maybe even print them.

Creating - Naming Your App Using AIDE

When creating your app,(from left menu) choose:
Create New Project;
Then, choose
New Android App(gradle, android Java/xml)
or
Hello World App Java/xml
if your using the original version of AIDE

Name your app, use;

ShareActionSend for the App Name and,
for the package name(next line) use:
com.aac.shareactionsendexample.

Where Code is Coded - The Coded Pages

ShareActionSend

For this app you will use these coded pages:

1 layout file, main.xml; located at res/layout/main.xml.

1 java page, MainActivity.java; where we define our layout with:

setContentView(R.layout.main);
and, we add our text to be used in the Share Intent; add the text at the code;
'shareContent'.

Just copy paste the code from Example Code section this page into the file MainActivity.java; to replace code that's there and save the file. And, do the same for the main.xml page.

1 strings.xml page where you define the app name(already done when we created our template app); and we define our text for the app also; for this app the string name is: string name="sharesendtext".

Just copy and paste the strings code from this tutorial into the strings.xml file to replace code that's there, then save it.

FYI:

The AndroidManifest xml page, Since we are not adding any new activities to our app; we don't need to define any new java pages in the manifest file; so we can leave this page code as it is.


Since this tutorial app - ShareActionSend, has no images; we don't have to add any to our drawable-hdpi folder.

The folder src/res/drawable-hdpi also has our ic_launcher.png image;(little green android icon) but we don't need to add it because it was added automatically when we created our android template app.

EXAMPLE CODE - Code For This Tutorial

JUSTcopy the code for this tutorial App Name is 'ShareActionSend - located at AppProjects/ShareActionSend in AIDE, open the AIDE app, then open App Projects, THEN select the 'ShareActionSend', app from your files hierachy(left menu); then click on any file from the app, like strings.xml.

Make sure at top of page, the app name 'ShareActionSend' is there next to AppProjects like so: AppProjects/ShareActionSend, then you know you have the proper App.

Once a file is in the editor, you can edit, save it, then RUN Build your APP, Install, and Open your app.


Make sure you SAVED EACH PAGE,(or choose automatic saving in AIDE settings) before you RUN your code. SAVE, RUN, INSTALL, OPEN, your App. Once it has been installed on your tablet, you can open it Simply by Clicking on the Android little green App Icon,with the wording 'ShareActionSend' on your tablet. It will be with your other installed apps.

If you make further changes to this App, you need to SAVE, RUN, UPDATE, INSTALL, OPEN the app again.

Example Code App - ShareActionSend :
Use Mouse To Copy Paste the Code


This free script provided by
JavaScript Kit

Share This Page


AIDE for creating Android Apps on your tablet or cell phone(android).
Free and Paid.
GoTo Aide

ANDROID STUDIO - for creating Android Apps on your desktop computer.
Free to Install and Use
Learn more - Android Studio


The Java XML files we code(example codes) and the Android Apps we create in our Free Tutorials are compatible with Android Studio and AIDE. Just choose Java XML as your Programming Language.



AndroidAppCoding.com, All Rights Reserved