How to create Android app that uses native mobile phone software such as camera, gallery, etc

Asked

Viewed 673 times

2

How do I use mobile resources ? For example: I create an app, that when the user clicks on "Such" button, open the camera of the mobile phone... or the gallery... or alarm clock. I wanted to learn that, but I don’t even know what to research.

  • 1

    What have you tried?

  • Nothing... but I wanted to know these resources. Example, I don’t even know what to research, or how to research to learn ? I wish they’d just give me a north here to begin with.

  • Search first how to create an android app, you can see the documentation too, at this link in English but easy to understand. Before learning resources, you must learn how to work with the tool, know the language, its functioning itself, in this link you have all this and more. In the most, tutorials on google has enough to start and to ask questions when venturing to create an app, Sopt will always be available :)

1 answer

2


What you want is solved using the Intent

One Intent is an abstract description of an operation to be executed. It can be used with startActivity to launch a Activity, the broadcastIntent to send to any component BroadcastReceiver and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with the service (Service) in the background.

Follows the documentation: http://developer.android.com/reference/android/content/Intent.html

First of all I recommend you to study Android and Java first, follow a good link to this:

Here are some examples of the use of Intent for study (not tested, for a while I do not work with Android):

Open the calculator:

// activity name and package for stock calculator
private static final String CALCULATOR_PACKAGE_NAME = "com.android.calculator2";
private static final String CALCULATOR_CLASS_NAME = "com.android.calculator2.Calculator";

public void launchCalculator() {

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
     intent.setComponent(new Component Name(CALCULATOR_PACKAGE_NAME,
             CALCULATOR_CLASS_NAME));
     try {
         this.start Activity(intent);
     } catch (ActivityNotFoundException noSuchActivity) {
         // handle exception where calculator intent filter is not registered
     }
 }

Selects an audio:

public void launchMusicPlayer(View view) {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_GET_CONTENT);
    intent.setDataAndType(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            AUDIO_MIME_TYPE);
    startActivityForResult(intent, FIND_SONG_INTENT);
}

Text editor:

public void launchTextEditor() {
    try {
        Intent intent = new Intent(Intent.ACTION_EDIT);
        Uri uri = Uri.parse("file:///sdcard/somefile.txt");
        intent.setDataAndType(uri, "text/plain");
        start Activity(intent);
    } catch (ActivityNotFoundException e) {
        Toast toast = Toast.makeText(this, "No editor on this device",
                Toast.LENGTH_SHORT);
         toast.show();
     }
 }

View PDF:

public void launchPDFViewer() {
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.parse("file:///sdcard/Download/somefile.pdf");
        intent.setDataAndType(uri, "application/pdf");
        start Activity(intent);
    } catch (ActivityNotFoundException e) {
        Toast toast = Toast.makeText(this, "No viewer on this device",
                Toast.LENGTH_SHORT);
         toast.show();
     }
 }

Source: http://www.intertech.com/Blog/android-intents-for-app-integration-call-a-calculator-play-video-open-an-editor/

  • By his reply in the comments, apparently he does not even know how to program in java for android, or if you know, It was not very clear by the question and nor by the answer in the comments.

  • @Diegofelipe Thanks, edited reply.

  • Man, thank you so much, that’s exactly what I wanted... Great explanation!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.