Googleで画像付きMMSを送信できないメッセンジャーアプリ。一部の Android デバイスでは、この SMS アプリがデフォルトでインストールされますが、それを使用して MMS を送信するとIntent
機能しません。
問題は、ToNumber と MMS コンテンツは設定されているが、このアプリでは画像が添付されていないことです。
注記:私はすでにデバイスに MMS APN 設定を設定しており、Samsung s4、Motorola G4 Plus など、同じアプリを使用して複数のデバイスで確認済みです。
これは私が現在使用しているコードです。
String toNumbers = "comma seperated mobile numbers";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(getActivity());
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("address", toNumbers);
sendIntent.setPackage("com.android.mms");
//Uri uri = Uri.fromFile(new File(getContext().getExternalFilesDir(""), "image.png"));
File imagePath = new File(getFilesDir(), "images");
File newFile = new File(imagePath, "image.png");
Uri uri = getUriForFile(this, "packagename", newFile);
File file = new File(contentUri.getPath());
if (file.exists()) {
//Do something
Log.d("TAG","Exist");
}
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("image/png");
sendIntent.putExtra("sms_body", getString(R.string.sms_body, HostName));
if (defaultSmsPackageName != null)
{
sendIntent.setPackage(defaultSmsPackageName);
}
startActivityForResult(sendIntent, Constants.SEND_SMS_REQUEST);
}
else
{
Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
smsIntent.putExtra("address", toNumbers);
smsIntent.setPackage("com.android.mms");
Uri uri = Uri.fromFile(new File(getContext().getExternalFilesDir(""), "image.png"));
smsIntent.putExtra(Intent.EXTRA_STREAM, uri);
smsIntent.setType("image/png");
smsIntent.putExtra("sms_body", getString(R.string.sms_body, HostName));
startActivityForResult(smsIntent, Constants.SEND_SMS_REQUEST);
}
ファイルパス.xml
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path
name="files"
path="images/" />
</paths>
マニフェスト
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="packagename"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
ベストアンサー1
ファイルパス.xmlそしてマニフェスト.xmlコード内と同じです。
コンテンツURIを作成する:
File imagePath = new File(getFilesDir(), "images");
File newFile = new File(imagePath, "image.png");
Uri contentUri = FileProvider.getUriForFile(this, "packagename", newFile);
コンテンツ URI を確認します:
ImageView imageView = (ImageView) findViewById(R.id.imageview);
//Your image should be displayed
imageView.setImageURI(contentUri);
意図を作成する:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Text to send");
sendIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
sendIntent.setType("image/png");
ソリューションは以下でテスト済み:
a) Galaxy S4、Android 5.0、メッセンジャーバージョン: 1.9.036
b) エミュレーター: Nexus 5、Android 6.0、メッセージングバージョン: 1.0.001