Reputation: 5586
I am planning to start writing some android test cases and I would like to know if there is a way of switching connectivity on and off programmatically in the emulator.
// High level puesdo code
Test: is Message Pushed to Local Storage if Phone is Not Connected to Network:
Connectivity = off
Create message
try push message to webapp
assert message in local storage
Connectivity = on
New to test cases in android so apologies if answer is obvious.
Upvotes: 1
Views: 358
Reputation: 17613
To remove connectivity you should remove APNs defined, according to this: http://www.mail-archive.com/[email protected]/msg62089.html
This repository should have everything you need: http://code.google.com/p/apndroid/
Anyway, below are some snippets i've found...
To read the current APN:
Cursor cursor =
getContentResolver().(Uri.parse("content://telephony/
carriers"),
null, null,
null, null);
StringBuffer sb = new StringBuffer();
cursor.moveToFirst();
do{
sb.append("_id =").append(cursor.getString(0)).append(" , ");
sb.append("name=").append(cursor.getString(1)).append(" , ");
sb.append("numeric=").append(cursor.getString(2)).append(" , ");
sb.append("mcc=").append(cursor.getString(3)).append(" , ");
sb.append("mnc=").append(cursor.getString(4)).append(" , ");
sb.append("apn=").append(cursor.getString(5)).append(" , ");
sb.append("user=").append(cursor.getString(6)).append(" , ");
sb.append("server=").append(cursor.getString(7)).append(" , ");
sb.append("password=").append(cursor.getString(8)).append(" ,
");
sb.append("proxy=").append(cursor.getString(9)).append(" , ");
sb.append("port=").append(cursor.getString(10)).append(" , ");
sb.append("mmsproxy=").append(cursor.getString(11)).append(" ,
");
sb.append("mmsport=").append(cursor.getString(12)).append(" ,
");
sb.append("mmsc=").append(cursor.getString(13)).append(" , ");
sb.append("type=").append(cursor.getString(14)).append(" , ");
sb.append("current=").append(cursor.getString(15)).append(" ,
");
sb.append("\n--- BLOCK ---\n");
}while(cursor.moveToNext());
To add a APN this:
//Trying to Insert a Custom Setting to Telephony db
ContentValues values = new ContentValues();
values.put("_id","3");
values.put("name","Ramesh");
values.put("numeric","310995");
values.put("mcc","315");
values.put("mnc","995");
values.put("apn","email");
values.put("user","elkjop");
values.put("server","www.moota.com");
values.put("password","elkjop");
values.put("proxy","12");
values.put("port","12");
values.put("mmsproxy","12");
values.put("mmsport","12");
values.put("mmsc","12");
values.put("type","a");
values.put("current","a");
//Adding Values using the Content Resolver
getContentResolver().insert(Uri.parse("content://telephony/
carriers"), values);
I've found this here: https://groups.google.com/forum/#!topic/android-developers/fYwf_mhEX3Y
By that ContentResolver you can probably also delete them.
You would then delete the APN and then restaure it and that would do what you want.
Upvotes: 1