2012-05-16 38 views
0

我想用android 2.2發送消息(短信/彩信)。首先,我做的意圖選擇器與ACTION_SEND來選擇使用哪一個:如何發送消息在android 2.2?

Intent intent = new Intent(Intent.ACTION_SEND); 

intent.setType("text/plain"); 
intent.putExtra(Intent.EXTRA_SUBJECT, Resources.getString("InvitationSubject", getBaseContext())); 
String body = Resources.getString("InvitationBody", getBaseContext()) + Local.User.FirstName; 
intent.putExtra(Intent.EXTRA_TEXT, body); 

startActivity(Intent.createChooser(intent, "Invite friends")); 

但在這種情況下,選擇節目「藍牙消息,Google +和Gmail的」。我只想顯示消息或其他消息應用程序。

我在sdk文檔中看到有一個新的CATEGORY_APP_MESSAGING要使用,但它只能在API級別15中使用。我必須保持API級別8.有沒有辦法做到這一點?

回答

1

試試這個代碼

String body = Resources.getString("InvitationBody", getBaseContext()) + Local.User.FirstName; 
Intent sendIntent = new Intent(Intent.ACTION_VIEW); 
sendIntent.putExtra("sms_body", smsBody); 
sendIntent.setType("vnd.android-dir/mms-sms"); 
startActivity(sendIntent); 

不要忘了在你的清單中添加這個<uses-permission android:name="android.permission.SEND_SMS" />

0

您可以使用彩信類短信,像這樣

intent.setType("vnd.android-dir/mms-sms"); 
0

使用下面的代碼來發送消息

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
shareIntent.setType("text/plain"); 
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "message subject"); 
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text"); 
startActivity(Intent.createChooser(shareIntent, "Pick a Share method")); 

,帶出以下不需要

<uses-permission android:name="android.permission.SEND_SMS" /> 
+1

SEND_SMS無須許可。 – Tarun