android4.4 的单双卡判断

public static void initIsDoubleTelephone(Context context){
boolean isDouble = true;
Method method = null;
Object result_0 = null;
Object result_1 = null;
 Class<?> tm = null;  
// TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
tm=Class.forName("com.mediatek.telephony.TelephonyManagerEx");
Method method1 = tm.getMethod("getDefault");
method = tm.getMethod("getSimState",new Class[] { int.class });
result_0 = method.invoke(method1.invoke(tm), new Object[] { new Integer(0) });
result_1 = method.invoke(method1.invoke(tm), new Object[] { new Integer(1) });
Log.i("mylog", "result_0"+result_0);
} catch (SecurityException e) {
isDouble = false;
e.printStackTrace();
} catch (NoSuchMethodException e) {
isDouble = false;
e.printStackTrace();
} catch (IllegalArgumentException e) {
isDouble = false;
e.printStackTrace();
} catch (IllegalAccessException e) {
isDouble = false;
e.printStackTrace();
} catch (InvocationTargetException e) {
isDouble = false;
e.printStackTrace();
} catch (Exception e){
isDouble = false;
e.printStackTrace();
}
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
Editor editor = sp.edit();
String ISDOUBLE="double";
String SIMCARD="simcard";
if(isDouble){
editor.putBoolean(ISDOUBLE, true);
String SIMCARD_1="sim1";
String SIMCARD_2="sim2";
if(result_0.toString().equals("5") && result_1.toString().equals("5")){
if(!sp.getString(SIMCARD, "2").equals("0") && !sp.getString(SIMCARD, "2").equals("1")){
editor.putString(SIMCARD, "0");
}
editor.putBoolean(SIMCARD_1, true);
editor.putBoolean(SIMCARD_2, true);
} else if(!result_0.toString().equals("5") && result_1.toString().equals("5")){
if(!sp.getString(SIMCARD, "2").equals("0") && !sp.getString(SIMCARD, "2").equals("1")){
editor.putString(SIMCARD, "1");
}
editor.putBoolean(SIMCARD_1, false);
editor.putBoolean(SIMCARD_2, true);
} else if(result_0.toString().equals("5") && !result_1.toString().equals("5")){
if(!sp.getString(SIMCARD, "2").equals("0") && !sp.getString(SIMCARD, "2").equals("1")){
editor.putString(SIMCARD, "0");
}
editor.putBoolean(SIMCARD_1, true);
editor.putBoolean(SIMCARD_2, false);
} else {
editor.putBoolean(SIMCARD_1, false);
editor.putBoolean(SIMCARD_2, false);
}
}else{
editor.putString(SIMCARD, "0");
editor.putBoolean(ISDOUBLE, false);
}
editor.commit();
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
你可以通过在 TableLayout 中的每个 TableRow 中设置不同的背景来实现双行不同的背景效果。具体步骤如下: 1. 在 res/drawable 目录下创建两个 XML 文件,分别命名为 odd_bg.xml 和 even_bg.xml。这两个文件分别代表了奇数行和偶数行的背景。 2. 在 odd_bg.xml 中添加以下内容: ```xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/odd_color" /> </shape> ``` 其中,@color/odd_color 代表了奇数行的背景颜色。 3. 在 even_bg.xml 中添加以下内容: ```xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/even_color" /> </shape> ``` 其中,@color/even_color 代表了偶数行的背景颜色。 4. 在 TableLayout 中添加每个 TableRow 的时候,判断当前行是奇数行还是偶数行,然后设置不同的背景。 ```java for (int i = 0; i < rowCount; i++) { TableRow tableRow = new TableRow(this); // 判断当前行是奇数行还是偶数行 if (i % 2 == 0) { tableRow.setBackgroundResource(R.drawable.even_bg); } else { tableRow.setBackgroundResource(R.drawable.odd_bg); } // 添加其他控件到 TableRow 中 ... tableLayout.addView(tableRow); } ``` 其中,R.drawable.even_bg 和 R.drawable.odd_bg 分别对应了上面创建的两个 XML 文件。 这样就可以实现双行不同的背景效果了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安卓学习乐园

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值