Sending mms in android 4.4

╄→гoц情女王★ 提交于 2019-11-28 10:43:50

问题


Im trying to send mms from my app only. I made it default messaging app with help of android developers tutorial (http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html).

My manifest:
BroadcastReceiver that listens for incoming SMS messages:

   <receiver android:name="com.test.SmsReceiver"
        android:permission="android.permission.BROADCAST_SMS">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_DELIVER" />
        </intent-filter>
    </receiver>

BroadcastReceiver that listens for incoming MMS messages

 <receiver android:name="com.test.MmsReceiver"
        android:permission="android.permission.BROADCAST_WAP_PUSH">
        <intent-filter>
            <action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
            <data android:mimeType="application/vnd.wap.mms-message" />
        </intent-filter>
    </receiver>

Service that delivers messages from the phone quick response

<service android:name="com.test.HeadlessSmsSendService"
        android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
        android:exported="true" >
        <intent-filter>
            <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="sms" />
            <data android:scheme="smsto" />
            <data android:scheme="mms" />
            <data android:scheme="mmsto" />
        </intent-filter>
    </service>

NewMmsActivity Activity that allows the user to send new SMS/MMS messages:

 <activity android:name="com.test.NewMmsActivity"
        android:configChanges="keyboard|keyboardHidden|locale|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <action android:name="android.intent.action.SENDTO" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="sms" />
            <data android:scheme="smsto" />
            <data android:scheme="mms" />
            <data android:scheme="mmsto" />
        </intent-filter>
    </activity>

But when i try in NewMmsActivity to send an mms it doesn't work and instead dialog is open like this:

CODE:

  Intent mmsIntent = new Intent(Intent.ACTION_SEND);
  mmsIntent.putExtra("sms_body", "text");
  mmsIntent.putExtra("address", "99999999");
  mmsIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fileString)));
  mmsIntent.setType("image/jpeg");
  startActivity(mmsIntent);

If i use Intent.ACTION_SENDTO nothing happens. Intent is started without no problems but nothing is happening.

What am i missing?? Any ideas would be appreciated!


回答1:


As the default app, yours is responsible for sending the MMS itself, not opening another app to do so, which is what your code is doing. Currently, Android does not have a simple API for MMS, as it does for SMS. Furthermore, it is a very poorly documented aspect of the framework, and the amount of code and explanation necessary to implement it is out of scope for Stack Overflow. You're welcome to inspect the source code of the native app for guidance, but keep in mind that it is no trivial task, as the default app is responsible for everything needed to handle MMS, including sending, receiving, and Content Provider transactions.




回答2:


I believe the issue is that you are trying to send both image and text data, but your type is set to image. Try switching this instead to:

mmsIntent.setType("*/*");



回答3:


Easiest way i found for sending mms is android-smsmms library found here: https://github.com/klinker41/android-smsmms

For gettings mmsc, proxy and port i used:

 final Cursor apnCursor = SqliteWrapper.query(mContext, this.mContext.getContentResolver(),
                Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"), APN_PROJECTION, null, null, null);
        String type = null;
        if (apnCursor.moveToFirst()) {
            do {
                type = apnCursor.getString(3);
                if(type.equals("default,supl,mms") ||
                        type.equals("mms")) {
                    mmsc = apnCursor.getString(0);
                    proxy = apnCursor.getString(1);
                    port = apnCursor.getString(2);
}while (apnCursor.moveToNext());

In if loop i am checking if APN has MMS data that i need otherwise go to next one.



来源:https://stackoverflow.com/questions/25997516/sending-mms-in-android-4-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!