SORU
4 HAZİRAN 2010, Cuma


Nasıl Android MMS ile resim göndermek için?

Multimedya bir uygulama üzerinde çalışıyorum. Kamera ile bir görüntü yakalama ve ben başka bir numaraya bir mesaj ile resim göndermek istiyorum. Ama MMS ile resim göndermek için nasıl almıyorum.

CEVAP
4 HAZİRAN 2010, Cuma


MMS htttp-post sadece bir istektir. İsteği ile yapmalıdırek ağ özelliği:

final ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
final int result = connMgr.startUsingNetworkFeature( ConnectivityManager.TYPE_MOBILE, Phone.FEATURE_ENABLE_MMS);

Telefon ile sonuç alırsanız.APN_REQUEST_STARTED değer, uygun bir devlet için beklemek zorunda. BroadCastReciver kayıt Telefon kadar bekleyin.APN_ALREADY_ACTİVE görünür:

final IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
context.registerReceiver(reciver, filter);

Eğer bağlantı arka plan hazır, içerik oluşturmak ve isteği gerçekleştirmek. Eğer android kullanan dahili kodu yapmak istiyorsan, lütfen bunu kullanın:

final SendReq sendRequest = new SendReq();
    final EncodedStringValue[] sub = EncodedStringValue.extract(subject);
    if (sub != null && sub.length > 0) {
        sendRequest.setSubject(sub[0]);
    }
    final EncodedStringValue[] phoneNumbers = EncodedStringValue
            .extract(recipient);
    if (phoneNumbers != null && phoneNumbers.length > 0) {
        sendRequest.addTo(phoneNumbers[0]);
    }

    final PduBody pduBody = new PduBody();

    if (parts != null) {
        for (MMSPart part : parts) {
            final PduPart partPdu = new PduPart();
            partPdu.setName(part.Name.getBytes());
            partPdu.setContentType(part.MimeType.getBytes());
            partPdu.setData(part.Data);
            pduBody.addPart(partPdu);
        }
    }

    sendRequest.setBody(pduBody);

    final PduComposer composer = new PduComposer(this.context, sendRequest);
    final byte[] bytesToSend = composer.make();

    HttpUtils.httpConnection(context, 4444L, MMSCenterUrl,
            bytesToSendFromPDU, HttpUtils.HTTP_POST_METHOD, !TextUtils
                    .isEmpty(MMSProxy), MMSProxy, port);

MMSCenterUrl: MMS-APNs, MMSProxy url: MMS-APNs, port proxy: MMS-APNs bağlantı noktası

Bazı sınıflar iç paketlerden unutmayın. Android git indir gereklidir.

İstek kullanıcı apn-uzaydan url...kod..: yapılmalıdır

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>(); 
            if ( apnCursor.moveToFirst() ) {
        do {
            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);
            }
        } while ( apnCursor.moveToNext() ); 
             }              
        apnCursor.close();
        return results;
    }
}

private Context context;

}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • AutoHotkey Tutorials

    AutoHotkey T

    29 Mayıs 2010
  • martin shervington

    martin sherv

    7 EKİM 2011
  • Michelle Phan

    Michelle Pha

    18 Temmuz 2006