Next Tutorial
Coding a Media Player For Audio
Prev Page
View All Tutorials
Coding a Share Intent for Images
This is the App - Share Images
It can share the 'image' from the screen view.
You can share the image to your social sites or other apps on your device
This shows the app screen view with the Share Image Button on the Action Bar.
This shows the Share Prompt that loads once the button
'Share This Views Image' has been clicked.
Where - How To Use Intents to Share Images
There are many methods you can code to share images in your android apps; in this app we have coded one such method.
This Share Image Method includes a 'Share Image Button' which is added to the Action Bar at the top of the view. It will send the 'defined image' to an app of your choice from the populated
prompt. The prompt will contain Apps from your device, as well as your social apps like Facebook and Twitter.
As in our previous tutorial for Sharing Text; the image to be shared must be declared in the java coded page - MainActivity.java You can add the Share Image code to any page in your android
app that has images.
This Share Image code also sends the selected image to your tablets's file storage.
So, for example, if you selected to share the view's image to Twitter; you click on the Share This Image
Button, then click on the Twitter icon; the image is sent to Twitter,(if your already logged in to twitter it will post automatically), and the same image will be sent to the file storage on your tablet as well.
You can name the file storage folder anything you want. To do so, just code the name in your MainActivity.java file.
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
You can name your app whatever you like; if your using the name as shown in our example code use;
Share Images for the App Name and,
for the package name(next line) use:
com.aac.shareimagesexample.
The Coded Pages
Code for the app - Share Images
For this app you will use these coded pages:
1 layout file, main.xml,(already created, just copy paste this tutorial app code into it and save); located at res/layout/.
1 java page, MainActivity.java,(already created) where we define our layout:
setContentView(R.layout.main).
Just copy paste the code from this tutorial, into the file MainActivity.java; to replace code that's there and save the file.
This tutorial app - Share Images has 1 image; you can download it from our Example Code section; then add it to your drawable-hdpi folder.
Use your tablets File Manager to copy paste the image into the AppProjects/ShareImages/app/src/main/res/drawable-hdpi/ folder.
FYI:
The manifest xml page, (already created)where we define our app's name and activity java page(and other things). 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.
The folder /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 'Share Images - located at AppProjects/ShareImages in AIDE, open the AIDE app, then open App Projects, THEN select the 'Share Images',
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 'Share Images' is there next to
AppProjects like so: AppProjects/Share Images, then you know you have the proper App. Once a file is in the editor, you can edit, save it, then RUN 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 'Share Images' 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.
This free script provided by
JavaScript
Kit