2012-03-29 4 views
14

私のアプリケーションから特定の番号にMMSを送信したいと思います。私はこのコードを検索して見つけましたが、このコードが必要かどうかわかりません。 私の質問は:アンドロイドのMyアプリケーションからMMSを送信

誰でもこのコードを私に説明できます。私はMMSの初心者です。

- また、このコードは、ユーザーが自分のアプリケーションからMMSをネイティブメッセージ受信トレイに移動することなくMMSを送信できるようにしたと思っています(これが私の望むものです)。

-また、私は問題がある、私は私のプロジェクトにこのコードを置くことができないのか分からない。

これは私が見つけたものです

MMSは単なるhttp-post要求です。あなたは、余分なネットワーク機能を使用して要求を実行する必要があります。

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

あなたはPhone.APN_REQUEST_STARTED値で結果を取り戻す場合は、あなたが適切な状態を待たなければなりません。 BroadCastReciverを登録しPhone.APN_ALREADY_ACTIVEが表示されるまで待つ:

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

バックグラウンド接続の準備ができている場合は、コンテンツを構築し、要求を実行。あなたはアンドロイドの内部コードを使用することを行いたい場合は、これを使用してください:

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-のAPNからURL、
  • MMSProxy:MMS-のAPNからプロキシ、
  • ポートを:ポートからMMS-APN

一部のクラスは内部パッケージからのものであることに注意してください。アンドロイドgitからのダウンロードが必要です。 要求は、ユーザーのAPN空間コードからURLを実行する必要があります:

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; 
     } 

あなたはAndroidのシステム機能を使用していない理由を私に

+0

私はここに似た何かをやっています! http://stackoverflow.com/questions/14452808/sending-and-receiving-mms-in-android – toobsco42

+0

私の答えはこちらを参照してくださいhttp://stackoverflow.com/a/20611335/2422453 – Defuera

+0

叫んでも答えは得られません答え :/ –

答えて

0

を助けてください:

を見てください。

https://developer.android.com/guide/components/intents-common.html

public void composeMmsMessage(String message, Uri attachment) { 
     Intent intent = new Intent(Intent.ACTION_SEND); 
     intent.setData(Uri.parse("smsto:")); // This ensures only SMS apps respond 
     intent.putExtra("sms_body", message); 
     intent.putExtra(Intent.EXTRA_STREAM, attachment); 
     if (intent.resolveActivity(getPackageManager()) != null) { 
      startActivity(intent); } 
} 
上の

乾杯

トム

関連する問題