How to start 'View Contact' Activity on android? - android

I want to create a tab which contains a tab for viewing contact detail. Here is what i did:
intent = new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, ""+contactId));
nativeInfo = tabHost.newTabSpec("native info").setIndicator("N Info").setContent(intent);
It throw security exception.
I appreciate your help.
Thanks.

You need to add that permission to your manifest file, so that the user gets notified your app will read contacts when the app is installed.
<uses-permission android:name="android.permission.READ_CONTACTS" />
Take a look at this:
http://developer.android.com/guide/topics/manifest/manifest-intro.html#perms

Related

phone link not working in the android APP

hello i have this link in my website <a href='tel: 123456789'>1234</a> and i am converting the website into android APP everything works fine but this tel link gives me webpage not available how can i make this to call the phone instead of treating this as a link in android app.
i have already added
<uses-permission android:name="android.permission.CALL_PHONE" />
i dont know how to fix this link issue should i use any javascript or something ??
With what I understand, you want to call the number when someone clicks it, you can use this code:
String uri = "tel:" + "NUMBER-GOES-HERE" ;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);
Don't forget to add permission before the <application /> tag:
<uses-permission android:name="android.permission.CALL_PHONE" />

Unable to create a shortcut for calling a number on Android N

This is an example of a code for creating a direct shortcut that calls a specific number and which works on Android M and below.
public void installShortcutGetId(){
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"MyCallShortcut");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_CALL, Uri.parse("tel:77777777")));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, android.R.drawable.sym_def_app_icon));
context.sendBroadcast(intent);
}
The same code doesn't work anymore on Android N, I can see in the logcat the following:
/com.android.launcher3 E/InstallShortcutReceiver: Ignoring malicious intent tel:77777777#Intent;action=android.intent.action.CALL;end
If I change ACTION_CALL to ACTION_DIAL, it works on Android N but that's not what I am looking for. I am looking for a way to make a direct call through the shortcut.
In terms of permissions, I have these 2 included and CALL_PHONE requested at run-time.
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.CALL_PHONE" />
Just because your app has the CALL_PHONE permission doesn't mean the launcher has that permission: that's why your shortcut cannot be created.
You could instead create a shortcut to an empty activity of your own and start the ACTION_CALL Intent from that activity.

Android Intent Calling

I tried to make a call when I click on Android Mobile field with this code
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+contactNo));
startActivity(callIntent);
And added these in AndroidManifest.xml
<uses-permission android:name="packagename.permission.C2D_MESSAGE"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
And finally I am getting **java.lang.SecurityException** exception.
Why it Happens? and What is the Correct Procedure to Make a Call when click on Contact field?
use Intent.ACTION_DIAL instead of Intent.ACTION_CALL
And action_dial does not need permission, and it will show dialed phone number to user on dialer and then it will be users wish to place a call or not. This will be better approach to give user a control of what they wants to do.
hope that will help you
In order to use Intent.ACTION_CALL you have to add a permission to your manifest.
Add this permission to your manifest and it should be ok
<uses-permission android:name="android.permission.CALL_PHONE"/>

Android : Remove all shortcuts associated with the app from code

I want to remove all the shortcuts on home screen of my app on a single event like button click.
Is there any way to do this ? or at least get the display-names of all the shortcuts placed on home screen from my app ?
( I cant have it in any shared-prefs / db while creation of shortcuts because user can even do a 'clear-data' )
Try this:
appShortcutIntent = new Intent();
appShortcutIntent.setClassName("com.pkg.pkgname", "MainActivity");
appShortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
appIcon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
Intent intentDeleteShortcut = new Intent();
intentDeleteShortcut.putExtra("android.intent.extra.shortcut.INTENT", appShortcutIntent);
intentDeleteShortcut.putExtra("android.intent.extra.shortcut.NAME", getResources().getString(R.string.app_name));
intentDeleteShortcut.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", appIcon);
intentDeleteShortcut.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
sendBroadcast(intentDeleteShortcut);
And add this permission in manifest file:
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
Hope this helps.
(P.S: This will require the device to be rooted as far as I know.)

Launching external application from my app

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 intent = new Intent();
intent.setAction(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
startActivity(intent);
But this seems to throw an error and force close my application. I also tried adding:
<action android:name="Contacts.Intents.SHOW_OR_CREATE_CONTACT"/>
in the AndroidManifest file, but to no avail.
A look at Logcat shows that it's an "IOexception - no such file or directory". A couple of questions arise from this. I read through the Android docs and noticed that the Contact.Intents class is deprecated. However, it's successor, ContactContracts is aimed at API level 5 whereas I'm targeting API level 3. Could this be the problem? Also, I've hardcoded this application into the code. Is there a way to retrieve the intents of any application the user selects so that they can be launched?
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.
I use this code for that purpose:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.Settings");
startActivity(intent);
This will launch the Settings app, you can use these also:
intent.setClassName("com.android.music", "com.android.music.MediaPlaybackActivityStarter");
intent.setClassName("com.android.contacts", "com.android.contacts.DialtactsContactsEntryActivity");
intent.setClassName("com.android.contacts", "com.android.contacts.DialtactsActivity");
The first starts the default music app, the second the contacts, and the third the dialer.
Hope this helps.
You need to pass in valid arguments to the apps you start. A lot of apps expect the data URI and / or certain extras to be valid.
Please try the following code:
Intent intent = new Intent(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
this.startActivity(intent);
(sorry if there is something wrong on the syntax, I dont have android in this computer)
And remove the action from the manifest. that is not needed.
The action method is used for something else.
For more info, please look at the android site: http://developer.android.com/reference/android/content/Intent.html
Daniel
The activity you are calling should appear not only in the Manifest for its own package, but in the Manifest for the CALLING package, too.

Categories

Resources