- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用“sendTextMessage”或“sendMultipartTextMessage”从我自己的应用程序发送短信。对于高于 API 19 (KitKat) 的手机,此消息将保存到已发送文件夹中。但是在我的 Android 8.0 Oreo 手机上它没有保存到已发送的项目。
为了在此处发布,我创建了一个非常基本的测试应用程序。当 MainActivity 的 Resume 函数触发时,此应用程序将简单地检查权限并发送文本。这是代码。
list :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.focus4software.www.myapplicationtest">
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
建筑等级
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.focus4software.www.myapplicationtest2"
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
主要 Activity :
package com.focus4software.www.myapplicationtest;
import android.Manifest;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.provider.Telephony;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_RESULTCODE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onResume(){
super.onResume();
//Check Permissions first
if (android.os.Build.VERSION.SDK_INT >= 23) {
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED) {
//Permissions not found.. request them
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.SEND_SMS}, REQUEST_RESULTCODE);
}
else {
this.SendSMS();
}
}
else {
this.SendSMS();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case REQUEST_RESULTCODE: {
if (grantResults.length == 1) {
//Make sure none of the permissions were denied
boolean somethingDenied = false;
for (int result : grantResults){
if (result != PackageManager.PERMISSION_GRANTED){
somethingDenied = true;
}
}
if (somethingDenied){
//a permission was denied
Toast.makeText(getApplicationContext(), "Failed to Send The TEST SMS, Permission was denied", Toast.LENGTH_SHORT).show();
}
else {
//turn the app on.. permissions accepted
this.SendSMS();
}
}
else {
Toast.makeText(getApplicationContext(), "Failed to Send The TEST SMS, incorrect amount of permissions returned.", Toast.LENGTH_SHORT).show();
}
return;
}
}
}
private void SendSMS (){
String phone = "[INSERT PHONE NUMBER]";
String message = "InCodeTestExtra";
//send sms
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phone, null, message, null, null);
//Show we got here
Toast.makeText(getApplicationContext(), "Code Executed... SMS Passed on.", Toast.LENGTH_SHORT).show();
//Save SMS
//this.SaveSMS(getApplicationContext(), phone, message);
}
private void SaveSMS(Context inContext, String inAddress, String inBody) {
try {
ContentValues values = new ContentValues();
values.put("address", inAddress);
values.put("body", inBody);
values.put("read", 1);
values.put("date", System.currentTimeMillis());
//values.put("status", delivered);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Uri uri = Telephony.Sms.Sent.CONTENT_URI;
inContext.getApplicationContext().getContentResolver().insert(uri, values);
}
else {
inContext.getApplicationContext().getContentResolver().insert(Uri.parse("content://sms/sent"), values);
}
//notify of the save
Toast.makeText(getApplicationContext(), "SMS SAVED (Maybe)", Toast.LENGTH_SHORT).show();
} catch (Exception ex) {
//notify of the Failure
Toast.makeText(getApplicationContext(), "SMS Failed to save (" + ex.getMessage() + ")", Toast.LENGTH_SHORT).show();
}
}
}
如前所述,这不会将消息保存到我的 Android Oreo 手机的“发送”文件夹中。
根据 Android 文档,这是注定要发生的。
Note: Beginning with Android 4.4 (API level 19), if and only if an app is not selected as the default SMS app, the system automatically writes messages sent using this method to the SMS Provider (the default SMS app is always responsible for writing its sent messages to the SMS Provider). For information about how to behave as the default SMS app, see Telephony.
作为解决方法,我尝试手动保存消息。在 SendSMS 函数的底部,它被注释掉了。但是,运行此代码不会导致异常,但也不会将 SMS 保存到发送文件夹。这在旧手机上也能正常工作。我不确定这是否是相关问题。
我在这里遗漏了什么吗?谁能帮忙? :)
最佳答案
只是想 id 将此线程更新为我发现的内容。
看来 Mike M 是正确的,因为这是特定于某些模型的。我正在使用 Honor 9,另一个堆栈溢出用户在 p20 lite 上遇到了类似的问题。都是 Hwawei。我对许多不是 Hwawei 的模型进行了很多测试,但从未设法重现该问题。
正如我在问题中提到的,如果短信不存在,使用代码手动保存短信也无法保存短信……在这种情况下,这可能适用于其他用户。
我发现唯一可行的解决方法是显示 SMS Activity 并让用户自己发送短信。缺点是它需要用户输入,您只需填充 SMS Activity 即可让他们发送消息。这是一个关于如何做到这一点的有用链接: launch sms application with an intent
对于有类似问题的人,可能只弹出 SMS Activity 某些带有一些古怪代码的模型.. 或者通过尝试保存虚拟短信并查看它是否有效来检测是否存在此问题(记住将其删除如果它确实有效).. 如果失败则显示 SMS Activity ......
IMO 的每一个变通办法都是令人不安的困惑,我愿意接受任何人提出的任何建议。 :)
关于java - Oreo 8.0 - 'sendTextMessage()' 未将邮件保存到已发送文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51537810/
我想在文本区域中向许多其他用户发送电子邮件。在名为内容的文本区域中,如果我键入星号包围的“用户”,我想让它们填写每个电子邮件的用户名(“@”之前的文本)。每封电子邮件中的每个用户名都会产生很多不同。然
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Problem when loading php file into variable (Load resu
我正在从数据库中提取信息,并尝试将其作为电子邮件发送。将从数据库中拉取多行数据。这就是我的代码的样子... 所有的信息邮件都很好。我的问题是,我想保留中断。例如,在标题之后,我想中断一下,然后开始备
当我使用我们使用 java 邮件的门户发送 TEXT 电子邮件时没有问题,但是,当我选择放置 HTML 内容并发送电子邮件时,会引发以下警报。花了几个小时搜索但没有有用的答案! 谁能帮忙 电子邮件主题
我有这个类,它处理 gmail 的登录。无论我输入什么电子邮件和密码,程序都会返回 session 。我不明白如何在返回 session 对象之前检查登录是否成功。 package mailActio
我设置的短信作为文本文件附在信中。我不明白为什么会这样。 replied letter example public void sendEmail(MimeMessage message, Strin
所以我正在制作一个网络系统,这个想法是当用户关闭浏览器时它会向我发送一封电子邮件。目前,用户正在使用 Javascript Ajax 来让 PHP 更新数据库的当前时间。当时间超过 5 分钟时,我希望
我想发送邮件,当产品从之前、日期和之后过期时,在 php 中,我在 php 中使用了 datediff mysql 函数,但如果产品过期日期类似于 31-1-2012 ,则不同值是不适合我的编码,请帮
我正在尝试设置一个邮件脚本,该脚本将首先从 mysql 运行一个简单的选择,并在消息中使用这些数组变量。然而,所有的变量并没有输出到消息体,只有一行变量。这是我的脚本: $sql1 = "SE
我最近一直在努力研究这个问题。是否有我可以使用并添加到其中的 android API?我想为电子邮件应用程序制作一个插件,但我不想制作整个电子邮件应用程序。 我非常想要一些已经可以处理发送和接收电子邮
嗨 我有一个 PHP 西类牙文网站。在此邮件正文中包含一个主题“Solicitud de cotización”,但该主题出现在热门邮箱中,如 Solicitud de cotización 。但它在
我想写一个脚本,使用 php 自动向我的客户发送电子邮件 我如何自动发送它,例如,如果他们输入他们的电子邮件。然后点击提交 我想自动发送这封邮件 其次,我的主机上是否需要 smtp 服务器?我可以在任
今天早上我已经解决了一个问题: Java Mail, sending multiple attachments not working 这次我遇到了一个稍微复杂一点的问题:我想将附件和图片结合起来。
下面是用于连接 IMAP 文件夹并对其执行操作的代码。所以我的问题是关于 javax.mail.Session 的,在这种情况下它会每秒重新创建一次(取决于 checkInbox() 的 hibern
我正尝试按照 http://www.tutorialspoint.com/java/java_sending_email.htm 上的指南发送电子邮件 Java 应用程序 当我尝试运行它时,从上面的链
我有一个包含 2 列 email 和 id 的表格。我需要找到密切相关的电子邮件。例如: john.smith12@example.com 和 john.smith12@some.subdomains
首先是一些信息: Debian 压缩 PHP 5.3.3 带有 mod_cgi 的 PHP 在这种情况下,我绝对必须使用 mail()。对于我所有的其他项目,我已经使用 SMTP 邮件。 我已将站点超
在对电子邮件主机的联系表单进行故障排除时,他们告诉我在 php 邮件功能的发件人地址中使用“-f”。 “-f”标志的作用是什么?为什么它可以解决允许发送电子邮件的问题?我阅读了一些文档,但不是很清楚。
一个简单的问题:群发邮件哪个性能好? mail() 函数或sendmail 流行的 PHP 列表管理器包使用哪个? 最佳答案 嗯,mail() 函数并不适合批量发送电子邮件,因为它会为您发送的每封
我正在制作一个 PHP 表单,允许用户上传附件并将其发送到我的电子邮件。我一直在寻找很长一段时间才能做到。最后,我找到了这个。 http://www.shotdev.com/php/php-mail/
我是一名优秀的程序员,十分优秀!