MohamadReza Sedaghat
MohamadReza Sedaghat

Reputation: 47

Opening phone apps through button

I have about 12 buttons that each button opens phone apps by it's name. Now i can open messages and phone call but for other ones i don't know what should i put. This is my code for phone call:

        phone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent phonecall = new Intent(Intent.ACTION_VIEW);
            phonecall.setData(Uri.parse("tel:"));
            startActivity(phonecall);
        }
    });

"tel:" will open phone call, now i want to know what should i put in "tel:" for other apps, Here's my other buttons need to open: Camera, Contacts, Browser, File Manager, Settings, Gallery, Clock, Telegram application, Instagram application, Whatsapp application.

Upvotes: 0

Views: 732

Answers (1)

nimi0112
nimi0112

Reputation: 2133

This is a part of Implicit Intent.

If you want the Android system to handle the intent for a particular task, you can use this.

        Intent callIntent = new Intent(Intent.ACTION_DIAL);
        callIntent.setData(Uri.parse("tel:" + Constants.CALL_CENTER_NUMBER));
        startActivity(callIntent);

Example: You can fire an Intent.ACTION_DIAL or Intent.ACTION_CALL without specifying any particular package name to handle this and Android system will handle this intent.

If you want your intent to be handled by a particular application then you can specify the package name of the application.

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.whatsapp");
startActivity( launchIntent );

Upvotes: 1

Related Questions