launch sms application with an intent

2019-01-01 03:45发布

I have a question about an intent... I try to launch the sms app...

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setType("vnd.android-dir/mms-sms");
int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP |
    Intent.FLAG_ACTIVITY_CLEAR_TOP;
intent.setFlags(flags);
intent.setData(Uri.parse("content://sms/inbox"));
context.startActivity(intent);

so, you can see that I put too much things in my intent, but that's because I don't know how I can do... Thank's

18条回答
孤独总比滥情好
2楼-- · 2019-01-01 03:58

on emulator this work for me

Intent i = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null));
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                i.putExtra("sms_body", remindingReason);

                startActivity(i);
查看更多
无与为乐者.
3楼-- · 2019-01-01 03:58
private void sendSMS() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // At least KitKat
        {
            String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(getActivity()); // Need to change the build to API 19
            Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
            sendIntent.setType("text/plain");
            //sendIntent.putExtra("address", add);
            sendIntent.setData(Uri.parse("smsto:" + add));
            sendIntent.putExtra("sms_body", getString(R.string.invitation_message));
            if (defaultSmsPackageName != null)// Can be null in case that there is no default, then the user would be able to choose
            // any app that support this intent.
            {
                sendIntent.setPackage(defaultSmsPackageName);
            }
            startActivity(sendIntent);

    } else // For early versions, do what worked for you before.
    {
        Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
        smsIntent.setType("vnd.android-dir/mms-sms");
        smsIntent.putExtra("address", add);
        smsIntent.putExtra("sms_body", "message");
        startActivity(smsIntent);
    }
}
查看更多
孤独总比滥情好
4楼-- · 2019-01-01 04:00

If android version is Kitkat or above, users can change default sms application. This method will get default sms app and start default sms app.

private void sendSMS() {    
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // At least KitKat
      {
         String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(this); // Need to change the build to API 19

         Intent sendIntent = new Intent(Intent.ACTION_SEND);
         sendIntent.setType("text/plain");
         sendIntent.putExtra(Intent.EXTRA_TEXT, "text");

         if (defaultSmsPackageName != null)// Can be null in case that there is no default, then the user would be able to choose
         // any app that support this intent.
         {
            sendIntent.setPackage(defaultSmsPackageName);
         }
         startActivity(sendIntent);

      }
      else // For early versions, do what worked for you before.
      {
         Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
         smsIntent.setType("vnd.android-dir/mms-sms");
         smsIntent.putExtra("address","phoneNumber");         
         smsIntent.putExtra("sms_body","message");
         startActivity(smsIntent);
      }
   }
查看更多
十年一品温如言
5楼-- · 2019-01-01 04:03

The below code works on android 6.0.
It will open the search activity in the default messaging application with the conversations related to specific string provided.

Intent smsIntent = new Intent(Intent.ACTION_MAIN);
        smsIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        smsIntent.setClassName("com.android.mms", "com.android.mms.ui.SearchActivity");
        smsIntent.putExtra("intent_extra_data_key", "string_to_search_for");
        startActivity(smsIntent);  

You can start the search activity with an intent. This will open the search activity of the default messaging application. Now, to show a list of specific conversations in the search activity, you can provide the search string as string extra with the key as

"intent_extra_data_key"

as is shown in the onCreate of this class

String searchStringParameter = getIntent().getStringExtra(SearchManager.QUERY);
    if (searchStringParameter == null) {
        searchStringParameter = getIntent().getStringExtra("intent_extra_data_key" /*SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA*/);
    }
    final String searchString = searchStringParameter != null ? searchStringParameter.trim() : searchStringParameter;

You can also pass the SENDER_ADDRESS of the sms as string extra, which will list out all the conversations with that specific sender address.

Check com.android.mms.ui.SearchActivity for more information

You can also check this answer

查看更多
骚的不知所云
6楼-- · 2019-01-01 04:04
Intent sendIntent = new Intent(Intent.ACTION_SEND); 
//CHANGE YOUR MESSAGING ACTIVITY HERE IF REQUIRED 
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
sendIntent.putExtra("sms_body",msgbody); 
sendIntent.putExtra("address",phonenumber);
//FOR MMS
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/mms.png"));
sendIntent.setType("image/png");
startActivity(sendIntent);
查看更多
与君花间醉酒
7楼-- · 2019-01-01 04:05
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", "12125551212");
smsIntent.putExtra("sms_body","Body of Message");
startActivity(smsIntent);
查看更多
登录 后发表回答