赞
踩
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nico.apn" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".TestApn" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".ApnReceiver"> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> </application> <uses-permission android:name="android.permission.WRITE_APN_SETTINGS"></uses-permission> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission></manifest>
public class ApnReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE")) { //apn状态切换. } }}
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ApnReceiver r = new ApnReceiver(); this.registerReceiver(r, new IntentFilter( "android.net.conn.CONNECTIVITY_CHANGE")); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。