gpt4 book ai didi

android - 有没有办法在 AndroidTestCase 中打开和关闭连接?

转载 作者:行者123 更新时间:2023-11-30 04:45:38 25 4
gpt4 key购买 nike

我打算开始编写一些 android 测试用例,我想知道是否有一种方法可以在模拟器中以编程方式打开和关闭连接。

// 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

Android 测试用例的新手,如果答案很明显,我们深表歉意。

最佳答案

要删除连接,您应该根据以下定义删除 APN:http://www.mail-archive.com/android-developers@googlegroups.com/msg62089.html

这个存储库应该有你需要的一切:http://code.google.com/p/apndroid/

无论如何,下面是我发现的一些 fragment ......

读取当前 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());

要添加 APN,请执行以下操作:

//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);

我在这里找到了这个:https://groups.google.com/forum/#!topic/android-developers/fYwf_mhEX3Y

通过 ContentResolver,您可能还可以删除它们。

然后您可以删除 APN,然后恢复它,这样就可以达到您想要的效果。

关于android - 有没有办法在 AndroidTestCase 中打开和关闭连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5044708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com