欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

通过mms传图片

程序员文章站 2022-04-04 12:14:04
...

final ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
final int result = connMgr.startUsingNetworkFeature( ConnectivityManager.TYPE_MOBILE, Phone.FEATURE_ENABLE_MMS);
final IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
context.registerReceiver(reciver, filter);
public class APNHelper {

public class APN {
    public String MMSCenterUrl = "";
    public String MMSPort = "";
    public String MMSProxy = ""; 
}

public APNHelper(final Context context) {
    this.context = context;
}   

public List<APN> getMMSApns() {     
    final Cursor apnCursor = this.context.getContentResolver().query(Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"), null, null, null, null);
    if ( apnCursor == null ) {
        return Collections.EMPTY_LIST;
    } else {
        final List<APN> results = new ArrayList<APN>();         
        while ( apnCursor.moveToNext() ) {
            final String type = apnCursor.getString(apnCursor.getColumnIndex(Telephony.Carriers.TYPE));
            if ( !TextUtils.isEmpty(type) && ( type.equalsIgnoreCase(Phone.APN_TYPE_ALL) || type.equalsIgnoreCase(Phone.APN_TYPE_MMS) ) ) {
                final String mmsc = apnCursor.getString(apnCursor.getColumnIndex(Telephony.Carriers.MMSC));
                final String mmsProxy = apnCursor.getString(apnCursor.getColumnIndex(Telephony.Carriers.MMSPROXY));
                final String port = apnCursor.getString(apnCursor.getColumnIndex(Telephony.Carriers.MMSPORT));                  
                final APN apn = new APN();
                apn.MMSCenterUrl = mmsc;
                apn.MMSProxy = mmsProxy;
                apn.MMSPort = port;
                results.add(apn);
            }
        }                   
        apnCursor.close();
        return results;
    }
}

private Context context;
 
相关标签: Mobile