Launching external application from my app

后端 未结 5 1368
春和景丽
春和景丽 2020-12-16 06:25

I would like to launch an app the user selects from within my application. However, I\'m not sure how I\'d go about doing this. I\'ve tried this:

Intent inte         


        
5条回答
  •  一整个雨季
    2020-12-16 07:15

    You need to pass extra information into the intent to tell Android what you want to show or create. Otherwise Android doesn't know what activity to start and (presumably in your case) throws an ActivityNotFoundException.

    For a contact, you use the generic Intent.ACTION_INSERT_OR_EDIT then use the MIME type of an individual contact (Contacts.People.CONTENT_ITEM_TYPE).

    For example:

    Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    intent.setType(People.CONTENT_ITEM_TYPE);
    intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");
    intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE, Contacts.PhonesColumns.TYPE_MOBILE);
    

    That will bring up the contacts app, prompting you to select an existing contact to add the phone number to, or to create a new contact.

    You don't need to add anything special to your manifest to start external activities. Only if you were to directly manipulate the contacts ContentProvider would you need to add the appropriate CONTACT permissions to your manifest.

提交回复
热议问题