Android ======= Port Redirection ---------------- adb forward or from the control console (telnet 5554): redir add tcp:5000:5001 * Grab an automated port redirector (python) here: http://codtech.com/downloads/android/android-redir.py Reset the Emulator ------------------ emulator -wipe-data Manifest.permission ------------------- ACCESS_ASSISTED_GPS ACCESS_CELL_ID ACCESS_GPS ACCESS_LOCATION ACCESS_SURFACE_FLINGER ADD_SYSTEM_SERVICE BROADCAST_PACKAGE_REMOVED BROADCAST_STICKY CALL_PHONE CHANGE_COMPONENT_ENABLED_STATE DELETE_PACKAGES DUMP FOTA_UPDATE GET_TASKS INSTALL_PACKAGES INTERNAL_SYSTEM_WINDOW RAISED_THREAD_PRIORITY READ_CONTACTS READ_FRAME_BUFFER RECEIVE_BOOT_COMPLETED RECEIVE_SMS RECEIVE_WAP_PUSH RUN_INSTRUMENTATION SET_ACTIVITY_WATCHER SET_PREFERRED_APPLICATIONS SIGNAL_PERSISTENT_PROCESSES SYSTEM_ALERT_WINDOW WRITE_CONTACTS WRITE_SETTINGS Progress Bar ------------ Header Progress Bar ------------------- requestWindowFeature(Window.FEATURE_PROGRESS); setContentView(16973836); // Have to set a content view before working with GUI elements setProgress(5000); setProgressBarVisibility(true); Dialog Progress Bar ------------------- ProgressDialog.show(this, null, "Please wait while loading...", true, true); Dumping DEX Files ------------------ dexdump -d -f -h -C system@app@Contacts.apk@classes.dex >> Contacts.apk.dump Pulling Files From the Emulator ------------------------------- adb pull /data/dalvik-cache/Contacts.apk.dump ~/android Injecting Key Strokes --------------------- import android.view.IWindowManager; import android.view.KeyEvent; import android.os.ServiceManager; import android.os.DeadObjectException; public void sendKeySync(KeyEvent event) throws DeadObjectException { android.view.IWindowManager windowManager = android.view.IWindowManager.Stub.asInterface(ServiceManager.getService("window")); windowManager.injectKeyEvent(event.isDown(), event.getKeyCode(), event.getRepeatCount(), event.getDownTime(), event.getEventTime(), true); } Alternative Way to Place a Call ------------------------------- android.os.IServiceManager sm = android.os.ServiceManagerNative.getDefault(); IPhone phoneService = IPhone.Stub.asInterface((IBinder) sm.getService("phone")); phoneService.call("01197211223445") Listing System Services ----------------------- android.os.IServiceManager sm = android.os.ServiceManagerNative.getDefault(); try { String[] services = sm.listServices(); for (int i = 0; i < services.length; i++) { Log.i("Services", i + " : " + services[i]); } } catch (DeadObjectException e) { Log.i("Services", e.getMessage(), e); } Call Monitoring classes ----------------------- PhoneStateIntentReceiver com.google.android.phone.InCallScreen Phone Number Formating classes ------------------------------ TelephoneNumberUtil PhoneNumberUtils Menu classes ------------ MenuBuilder (extends Menu) Animation classes ----------------- android.view.animation ScaleAnimation EaseInOutInterpolator Logging ------- adb logcat Configuring a Proxy ------------------- adb shell sqlite3 /data/data/com.google.android.providers.settings/databases/settings.db "\"INSERT INTO system VALUES(99,'http_proxy','[HOST]:[PORT]');\"" Returning Activity Result ------------------------- // In the caller: // private int INPUT_DLG_ID = 1243; // Random number @Override protected void onActivityResult(int requestCode, int resultCode, String data, Bundle extras) { super.onActivityResult(requestCode, resultCode, data, extras); // If the result was received from the user input dialog, call the next item menu if (requestCode == INPUT_DLG_ID) { callItemMenu((int) getSelectionRowID(), data); } } // In the callee: // ... setResult(SUCCESS, input.getText().toString()); finish(); ... Dialogs ------- Android Manifest Structure -------------------------- Register Your Intent as a Dialer -------------------------------- Phone Details -------------- Nothing is easier to be done, if you know where to search for it Smile The SystemProperties provide a bunch of data of the current Phone-'Properties', like: * the operator-Name (i.e.: "T-Mobile" or "AT&T") * the ISO-Country-Name (i.e.: "us" or "de") * and of course your Phone-Number Exclamation This is how to get these Strings into your Java-Code: Java: String phoneNumber = android.os.SystemProperties.get( android.telephony.TelephonyProperties.PROPERTY_LINE1_NUMBER); String operatorISOCountry = android.os.SystemProperties.get( android.telephony.TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY); String operatorName =android.os.SystemProperties.get( android.telephony.TelephonyProperties.PROPERTY_OPERATOR_ALPHA);; On the emulator this will return: "15555218135", "us" and "Android". Simulating an Incoming Call --------------------------- 1. The emulator has to be running. 2. Open the Ttelnet-Client of your choice. 3. type to it: "o localhost 5554" // The port could also be 5555... have a try. I. "o" stands for "Open", "localhost" is the 'IP' and "5554" is the port the telnet-server is listening to. 4. Connection should establish in a few seconds. 5. type: "gsm call 123456" to simulate an incoming call. 6. See the emulator ringing. Services -------- Basically, the best way to send/receive data between a local service and an activity is to use the transact() method. You can call it on the IBinder object, which is given to you in the onServiceConnected() method of your ServiceConnection object (confused yet?). The parameters to pass to it are mentioned in the docs. Note, however, that bindService() is asynchronous - it gets called 'sometime', and execution of your code (including transact(), if it's after a bindService() call) continues whether or not the service has been bound yet. So the best way to do transact() calls that I've found is to put them in a separate (i.e., serviceTransaction()) method, which is called from the onServiceConnected method of the ServiceConnection object - that way you don't get a NullPointerException when you try to call transact() on an IBinder that doesn't exist, because the service hasn't yet been bound. All that's well and good, but there's one more critical piece to this: To get a service to properly return something (via the reply Parcel you gave it in the original transact() call), you need to go into the Service's class and fill out the onTransact() method in your overridden IBinder object (in the demos it's something like mBinder), so that it updates that reply parcel with results before returning it. Bundles and String Arrays - m5 work around ------------------------------------------ private Bundle bundleFromStringArray(String[] vec) { Bundle bundle = new Bundle(); bundle.putInt("length", vec.length); for (int i = 0; i < vec.length; ++i) { bundle.putString(String.valueOf(i), vec[i]); } return bundle; } private String[] stringArrayFromBundle(Bundle bundle) { int elements = bundle.getInt("length"); String[] vec = new String[elements]; for (int i = 0; i < elements; ++i) { vec[i] = bundle.getString(String.valueOf(i)); } return vec; } Find Contact By Phone Number ---------------------------- Cursor c = mContext.getContentResolver().query(Phones.CONTENT_URI, new String[] {Phones.PERSON_ID}, Phones.NUMBER + " = '" + pPhoneNumber + "' OR " + Phones.NUMBER_KEY + " = '" + pPhoneNumber + "'", null, null); Getting The Number Of The Phone ------------------------------- String phoneNumber = android.os.SystemProperties.get( android.telephony.TelephonyProperties.PROPERTY_LINE1_NUMBER); String operatorISOCountry = android.os.SystemProperties.get( android.telephony.TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY); String operatorName =android.os.SystemProperties.get( android.telephony.TelephonyProperties.PROPERTY_OPERATOR_ALPHA);; Injecting Key Strokes --------------------- IWindowManager wManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window")); KeyEvent kd = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SOFT_LEFT); KeyEvent ku = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SOFT_LEFT); ... wManager.injectKeyEvent(kd.isDown(), kd.getKeyCode(), kd.getRepeatCount(), kd.getDownTime(), kd.getEventTime(), true); ... DTMF ---- PhoneFactory::MakeDefaultPhones(Context) Phone phone = PhoneFactory::GetDefaultPhone phone.sendTdmf(char); Special Characters ------------------ android.telephony.PhoneNumberUtils.PAUSE - (,)