How to create an Android application that uses native mobile software such as camera, gallery, etc. [closed]

2

How do I use my phone features? For example: I create an app, that when the user clicks "Such" button, open the camera of the mobile ... or the gallery ... or alarm clock. I wanted to learn this, but I do not even know what to search for.

    
asked by anonymous 18.11.2015 / 21:52

1 answer

2

What you want is resolved using Intent

A Intent is an abstract description of an operation to execute. It can be used with startActivity to launch a < a href="http://developer.android.com/reference/android/app/Activity.html"> Activity , or broadcastIntent to send to any component BroadcastReceiver and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with the service ( Service ) no background .

Follow the documentation: link

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

Here are some examples of using Intent for study (I did not test, I have not worked with Android for some time):

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
     }
 }

Select 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: > link

    
18.11.2015 / 22:49