Showing posts from July, 2010

Uninstalling installed applications using Intent in Android

To uninstall the install application using Intent, the code snippet is

Intent intent = new Intent(Intent.ACTION_DELETE); intent.setData(Uri.parse("")); startActivity(intent);

The screenshot is,

Getting List of Installed Applications in Android

We can get the list of android applications that is installed in the android device through PacketManager and using the API queryIntentActivities(). To get the list of installed applications in the device,

The complete code snippet is,

public class AppList extends Activity {
private ListView lView;
private ArrayList results = new ArrayList();

public void onCreate(Bundle savedInstanceState) {
lView = (ListView) findViewById(;
PackageManager pm = this.getPackageManager();

Intent intent = new Intent(Intent.ACTION_MAIN, null);

List list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
Log.w("Installed Applications", rInfo.activityInfo.applicationInfo

Listening to Phone calls using PhoneStateListener

When an incoming call is coming to your mobile, you can get the number of the incoming call, through the interface phoneStateListener. Then we can also get the state the mobile phone throught the same phoneStateListener. Here, I used two emulators to show the scenario.

For this, first install the application in two emulators.

The complete code is,

public class CaptureCall extends Activity {

TelephonyManager tm;

public void onCreate(Bundle savedInstanceState) {

tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);

private PhoneStateListener mPhoneListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
try {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Toast.makeText(CaptureCall.this, "CALL_STATE_RINGING", Toast.LENGTH_SHORT).show();
case TelephonyManager.CALL_STATE_OFFH…

Read Package information from Manifest in Android

We can get the package name, version number, version code, permissions, META-DATA like what ever we faced placed in the manifest file can be retrieved using PackageManager.

The code snippet is,

public class ReadPackage extends Activity {

public void onCreate(Bundle savedInstanceState) {
// Read package name and version number from manifest
try {
PackageManager manager = this.getPackageManager();
PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
"PackageName = " + info.packageName + "\nVersionCode = "
+ info.versionCode + "\nVersionName = "
+ info.versionName + "\nPermissions = "+info.permissions, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
System.out.println(" Exception in onCreate() : e = " + e);