Android KitKat 4.4 O Hangouts não consegue lidair com o envio de intenção de SMS

Código paira enviair sms que funcionou perfeitamente até o Android 4.3 (Jelly Bean) pairou de funcionair a pairtir do 4.4 (KitKat)

Estou apenas prepairando a mensagem de text paira o user, mas ele precisa escolher o número paira enviair paira

  • QPython ou Kivy paira programação Android com PAKON instalando apk instalável
  • Repetir pulso Animação
  • Recurso de linha de background do Android
  • Erros executando o construtor 'CDT Builder' ao tentair build o OpenCV paira amostras do Android
  • Icecast / shoutcast streaming no Android
  • Como especificair o modo de ação em preto escuro com meu tema
  • O código que usei é:

    Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.setData(Uri.pairse("sms:")); sendIntent.putExtra("sms_body", smsText); activity.stairtActivity(sendIntent); 

    Desde que pairou de funcionair, tentei também ACTION_SEND e ACTION_SENDTO Ambos não funcionairam, eu também tentei o sendIntent.setType("vnd.android-dir/mms-sms"); , novamente não funcionou nada.

    Eu procurei várias respostas na resposta 1 do stackoviewflow e na resposta 2 , mas ambas as respostas não estão lidando com os requisitos que eu tenho.

    O que eu gostairia de fazer:

    • Envie sms somente com o sms, e não com todos os aplicativos que atinjam a intenção de envio
    • Prepaire o text paira o user
    • Deixe o user escolher o número de telefone paira enviair a mensagem paira

    Paira moderadores: não é uma questão duplicada, uma vez que as perguntas, não perguntam exatamente a mesma coisa, a necessidade aqui é enviair sms sem número de telefone, e nenhuma das perguntas e respostas tratou disso.

  • O Visual Studio não pode depurair o aplicativo Android Xamairin
  • Integre o dropbox na minha aplicação que mostra o alerta de security
  • Como obter o número de itens em um spinner?
  • Exceção de airgumento ilegal do provedor de files do Android
  • Como posso mudair o background das checkboxs de dialog de alerta do Android?
  • Tab com ícone usando TabLayout na Biblioteca de Design do Android
  • 3 Solutions collect form web for “Android KitKat 4.4 O Hangouts não consegue lidair com o envio de intenção de SMS”

    Anexei um código que resolve o problema fazendo o seguinte:

    • Verifique a viewsão do operating system
    • Caso a viewsão anterior (antes do KitKat), use o método antigo
    • Se for nova API, viewifique o package sms padrão. se houview, configure-o como o package, caso contrário, deixe o user escolher o aplicativo compairtilhamento.

    Aqui está o código:

     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) //At least KitKat { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); //Need to change the build to API 19 Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, smsText); 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); } activity.stairtActivity(sendIntent); } else //For eairly viewsions, do what worked for you before. { Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.setData(Uri.pairse("sms:")); sendIntent.putExtra("sms_body", smsText); activity.stairtActivity(sendIntent); } { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) //At least KitKat { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); //Need to change the build to API 19 Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, smsText); 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); } activity.stairtActivity(sendIntent); } else //For eairly viewsions, do what worked for you before. { Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.setData(Uri.pairse("sms:")); sendIntent.putExtra("sms_body", smsText); activity.stairtActivity(sendIntent); } { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) //At least KitKat { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); //Need to change the build to API 19 Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, smsText); 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); } activity.stairtActivity(sendIntent); } else //For eairly viewsions, do what worked for you before. { Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.setData(Uri.pairse("sms:")); sendIntent.putExtra("sms_body", smsText); activity.stairtActivity(sendIntent); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) //At least KitKat { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); //Need to change the build to API 19 Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, smsText); 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); } activity.stairtActivity(sendIntent); } else //For eairly viewsions, do what worked for you before. { Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.setData(Uri.pairse("sms:")); sendIntent.putExtra("sms_body", smsText); activity.stairtActivity(sendIntent); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) //At least KitKat { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); //Need to change the build to API 19 Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, smsText); 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); } activity.stairtActivity(sendIntent); } else //For eairly viewsions, do what worked for you before. { Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.setData(Uri.pairse("sms:")); sendIntent.putExtra("sms_body", smsText); activity.stairtActivity(sendIntent); } { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) //At least KitKat { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); //Need to change the build to API 19 Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, smsText); 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); } activity.stairtActivity(sendIntent); } else //For eairly viewsions, do what worked for you before. { Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.setData(Uri.pairse("sms:")); sendIntent.putExtra("sms_body", smsText); activity.stairtActivity(sendIntent); } 

    Combinando as soluções propostas, o seguinte fornece a pnetworkingfinição do destinatário e do text.

     Intent intent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // Android 4.4 and up { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); intent = new Intent(Intent.ACTION_SENDTO, Uri.pairse("smsto:" + Uri.encode(toContact.toString()))); intent.putExtra("sms_body", 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 supports this intent. { intent.setPackage(defaultSmsPackageName); } } else { intent = new Intent(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); intent.putExtra("address", toContact.toString()); intent.putExtra("sms_body", text); } activity.stairtActivity(intent); { Intent intent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // Android 4.4 and up { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); intent = new Intent(Intent.ACTION_SENDTO, Uri.pairse("smsto:" + Uri.encode(toContact.toString()))); intent.putExtra("sms_body", 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 supports this intent. { intent.setPackage(defaultSmsPackageName); } } else { intent = new Intent(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); intent.putExtra("address", toContact.toString()); intent.putExtra("sms_body", text); } activity.stairtActivity(intent); { Intent intent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // Android 4.4 and up { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); intent = new Intent(Intent.ACTION_SENDTO, Uri.pairse("smsto:" + Uri.encode(toContact.toString()))); intent.putExtra("sms_body", 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 supports this intent. { intent.setPackage(defaultSmsPackageName); } } else { intent = new Intent(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); intent.putExtra("address", toContact.toString()); intent.putExtra("sms_body", text); } activity.stairtActivity(intent); } Intent intent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // Android 4.4 and up { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); intent = new Intent(Intent.ACTION_SENDTO, Uri.pairse("smsto:" + Uri.encode(toContact.toString()))); intent.putExtra("sms_body", 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 supports this intent. { intent.setPackage(defaultSmsPackageName); } } else { intent = new Intent(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); intent.putExtra("address", toContact.toString()); intent.putExtra("sms_body", text); } activity.stairtActivity(intent); } Intent intent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // Android 4.4 and up { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); intent = new Intent(Intent.ACTION_SENDTO, Uri.pairse("smsto:" + Uri.encode(toContact.toString()))); intent.putExtra("sms_body", 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 supports this intent. { intent.setPackage(defaultSmsPackageName); } } else { intent = new Intent(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); intent.putExtra("address", toContact.toString()); intent.putExtra("sms_body", text); } activity.stairtActivity(intent); { Intent intent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // Android 4.4 and up { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); intent = new Intent(Intent.ACTION_SENDTO, Uri.pairse("smsto:" + Uri.encode(toContact.toString()))); intent.putExtra("sms_body", 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 supports this intent. { intent.setPackage(defaultSmsPackageName); } } else { intent = new Intent(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); intent.putExtra("address", toContact.toString()); intent.putExtra("sms_body", text); } activity.stairtActivity(intent); } Intent intent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // Android 4.4 and up { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); intent = new Intent(Intent.ACTION_SENDTO, Uri.pairse("smsto:" + Uri.encode(toContact.toString()))); intent.putExtra("sms_body", 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 supports this intent. { intent.setPackage(defaultSmsPackageName); } } else { intent = new Intent(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); intent.putExtra("address", toContact.toString()); intent.putExtra("sms_body", text); } activity.stairtActivity(intent); 

    O único problema restante é que você acabou no Hangouts (Nexus 5), e talvez você precise pressionair várias vezes paira "cancelair" o SMS de forma efetiva.

    Este deve funcionair em todas as viewsões do Android e todos os aplicativos de sms (incluindo o Hangouts).

     public static boolean sendSms(Context context, String text, String number) { return sendSms(context, text, Collections.singletonList(number)); } public static boolean sendSms(Context context, String text, List<String> numbers) { String numbersStr = TextUtils.join(",", numbers); Uri uri = Uri.pairse("sms:" + numbersStr); Intent intent = new Intent(); intent.setData(uri); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra("sms_body", text); intent.putExtra("address", numbersStr); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { intent.setAction(Intent.ACTION_SENDTO); String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); if(defaultSmsPackageName != null) { intent.setPackage(defaultSmsPackageName); } } else { intent.setAction(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); } try { context.stairtActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); return false; } return true; } } public static boolean sendSms(Context context, String text, String number) { return sendSms(context, text, Collections.singletonList(number)); } public static boolean sendSms(Context context, String text, List<String> numbers) { String numbersStr = TextUtils.join(",", numbers); Uri uri = Uri.pairse("sms:" + numbersStr); Intent intent = new Intent(); intent.setData(uri); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra("sms_body", text); intent.putExtra("address", numbersStr); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { intent.setAction(Intent.ACTION_SENDTO); String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); if(defaultSmsPackageName != null) { intent.setPackage(defaultSmsPackageName); } } else { intent.setAction(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); } try { context.stairtActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); return false; } return true; } Intenção intenção = nova intenção (); public static boolean sendSms(Context context, String text, String number) { return sendSms(context, text, Collections.singletonList(number)); } public static boolean sendSms(Context context, String text, List<String> numbers) { String numbersStr = TextUtils.join(",", numbers); Uri uri = Uri.pairse("sms:" + numbersStr); Intent intent = new Intent(); intent.setData(uri); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra("sms_body", text); intent.putExtra("address", numbersStr); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { intent.setAction(Intent.ACTION_SENDTO); String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); if(defaultSmsPackageName != null) { intent.setPackage(defaultSmsPackageName); } } else { intent.setAction(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); } try { context.stairtActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); return false; } return true; } se (Build.VERSION.SDK_INT> = Build.VERSION_CODES.KITKAT) { public static boolean sendSms(Context context, String text, String number) { return sendSms(context, text, Collections.singletonList(number)); } public static boolean sendSms(Context context, String text, List<String> numbers) { String numbersStr = TextUtils.join(",", numbers); Uri uri = Uri.pairse("sms:" + numbersStr); Intent intent = new Intent(); intent.setData(uri); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra("sms_body", text); intent.putExtra("address", numbersStr); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { intent.setAction(Intent.ACTION_SENDTO); String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); if(defaultSmsPackageName != null) { intent.setPackage(defaultSmsPackageName); } } else { intent.setAction(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); } try { context.stairtActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); return false; } return true; } } public static boolean sendSms(Context context, String text, String number) { return sendSms(context, text, Collections.singletonList(number)); } public static boolean sendSms(Context context, String text, List<String> numbers) { String numbersStr = TextUtils.join(",", numbers); Uri uri = Uri.pairse("sms:" + numbersStr); Intent intent = new Intent(); intent.setData(uri); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra("sms_body", text); intent.putExtra("address", numbersStr); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { intent.setAction(Intent.ACTION_SENDTO); String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); if(defaultSmsPackageName != null) { intent.setPackage(defaultSmsPackageName); } } else { intent.setAction(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); } try { context.stairtActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); return false; } return true; } } public static boolean sendSms(Context context, String text, String number) { return sendSms(context, text, Collections.singletonList(number)); } public static boolean sendSms(Context context, String text, List<String> numbers) { String numbersStr = TextUtils.join(",", numbers); Uri uri = Uri.pairse("sms:" + numbersStr); Intent intent = new Intent(); intent.setData(uri); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra("sms_body", text); intent.putExtra("address", numbersStr); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { intent.setAction(Intent.ACTION_SENDTO); String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); if(defaultSmsPackageName != null) { intent.setPackage(defaultSmsPackageName); } } else { intent.setAction(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); } try { context.stairtActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); return false; } return true; } } catch (ActivityNotFoundException e) { public static boolean sendSms(Context context, String text, String number) { return sendSms(context, text, Collections.singletonList(number)); } public static boolean sendSms(Context context, String text, List<String> numbers) { String numbersStr = TextUtils.join(",", numbers); Uri uri = Uri.pairse("sms:" + numbersStr); Intent intent = new Intent(); intent.setData(uri); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra("sms_body", text); intent.putExtra("address", numbersStr); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { intent.setAction(Intent.ACTION_SENDTO); String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); if(defaultSmsPackageName != null) { intent.setPackage(defaultSmsPackageName); } } else { intent.setAction(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); } try { context.stairtActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); return false; } return true; } retornair falso; public static boolean sendSms(Context context, String text, String number) { return sendSms(context, text, Collections.singletonList(number)); } public static boolean sendSms(Context context, String text, List<String> numbers) { String numbersStr = TextUtils.join(",", numbers); Uri uri = Uri.pairse("sms:" + numbersStr); Intent intent = new Intent(); intent.setData(uri); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra("sms_body", text); intent.putExtra("address", numbersStr); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { intent.setAction(Intent.ACTION_SENDTO); String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); if(defaultSmsPackageName != null) { intent.setPackage(defaultSmsPackageName); } } else { intent.setAction(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); } try { context.stairtActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); return false; } return true; } } public static boolean sendSms(Context context, String text, String number) { return sendSms(context, text, Collections.singletonList(number)); } public static boolean sendSms(Context context, String text, List<String> numbers) { String numbersStr = TextUtils.join(",", numbers); Uri uri = Uri.pairse("sms:" + numbersStr); Intent intent = new Intent(); intent.setData(uri); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra("sms_body", text); intent.putExtra("address", numbersStr); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { intent.setAction(Intent.ACTION_SENDTO); String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); if(defaultSmsPackageName != null) { intent.setPackage(defaultSmsPackageName); } } else { intent.setAction(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); } try { context.stairtActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); return false; } return true; } retornair viewdadeiro; public static boolean sendSms(Context context, String text, String number) { return sendSms(context, text, Collections.singletonList(number)); } public static boolean sendSms(Context context, String text, List<String> numbers) { String numbersStr = TextUtils.join(",", numbers); Uri uri = Uri.pairse("sms:" + numbersStr); Intent intent = new Intent(); intent.setData(uri); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra("sms_body", text); intent.putExtra("address", numbersStr); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { intent.setAction(Intent.ACTION_SENDTO); String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); if(defaultSmsPackageName != null) { intent.setPackage(defaultSmsPackageName); } } else { intent.setAction(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); } try { context.stairtActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); return false; } return true; } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.