首页>代码>android设置移动联通电信wap接入点>/SetApn/src/com/bon/setapn/MainActivity.java
package com.bon.setapn;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
/**
 * 设置  apn 为联通wap或者电信wap、移动wap
 * @author lei
 *
 */
public class MainActivity extends Activity {
    /** Called when the activity is first created. */
	private Button setDianXinApn,checkApn;
	 private TelephonyManager mTelephonyManager; 
	 SharedPreferences sharedPreferences;
	 SetApn setApn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initView();
        setApn = new SetApn(mTelephonyManager, getContentResolver(),  getSharedPreferences("setapnDemo", MODE_PRIVATE));
    }
    /**
     * 初始化控件
     */
    public void initView(){
    	mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);  
    	
    	setDianXinApn = (Button) findViewById(R.id.setDianXinApn);

    	checkApn = (Button) findViewById(R.id.checkApn);
    	setDianXinApn.setOnClickListener(new ViewEvent());
    	checkApn.setOnClickListener(new ViewEvent());
    }
    /**
     * 点击事件
     * @author lei
     *
     */
    class ViewEvent implements OnClickListener{

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			if(getSimState()!=TelephonyManager.SIM_STATE_ABSENT)   //判断是否有sim卡
			{
				switch (v.getId()) {
				case R.id.checkApn:   //查看apn
//					Intent intent = new Intent(android.content.Intent.ACTION_MAIN);
//				     intent.setClassName("com.android.settings", "com.android.settings.ApnSettings");
//				     startActivity(intent);
					try {
						 Intent intent = new Intent();
//		         			ComponentName comPonentName = new ComponentName("com.android.settings","com.android.settings.ApnSettings");
		         			ComponentName comPonentName = new ComponentName("com.android.settings","com.android.settings.CdmaApnSettings");
		         			intent.setComponent(comPonentName);
		         			startActivity(intent);
					} catch (Exception e) {
						// TODO: handle exception
					}
				    
					break;
				case R.id.setDianXinApn:   //设置电信wap
					setApn.setWapApn();
					break;
				}
			}else{
				Toast.makeText(MainActivity.this, "请检查是否有SIM卡", 3).show();
			}
		}
    	
    }
    public int getSimState(){  
        return mTelephonyManager.getSimState();  
    }  
}
最近下载更多
jnetzhou  LV1 2019年4月3日
zjrzhong  LV1 2018年1月12日
ly2009158  LV1 2016年3月10日
ahbruse  LV1 2016年1月14日
daniel_gjg  LV25 2015年10月19日
kmcc123  LV1 2015年8月27日
yls  LV1 2015年8月17日
leehove  LV17 2015年3月17日
shiyu001  LV2 2014年5月13日
YonggangYuan  LV1 2013年10月22日
最近浏览更多
杰6666 2022年6月17日
暂无贡献等级
eddie2260  LV2 2022年5月24日
氟西汀来救你  LV2 2022年4月26日
isfrand  LV4 2022年4月25日
a566566  LV9 2020年12月29日
waitingforyou  LV20 2020年7月8日
doremi  LV6 2020年6月18日
bawe11  LV1 2020年6月17日
weixiao  LV6 2020年5月27日
蜡炬成灰  LV6 2020年4月17日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友