我声明了这两个变量,以便将文本消息发送到声明的号码:
SmsManager sender= SmsManager.getDefault();
sender.sendTextMessage(emergencyNum, null, text, null, null);
然后在onCreat()方法中我写了这个:
import sys, getopt, os
from subprocess import check_call, CalledProcessError
def scan_dir(path):
fail_count = 0
success = []
failure = []
temp_path = path
print temp_path
for file in os.listdir(path):
temp_path += file
if file.endswith(".txt"):
try:
check_call(["python", "callscript.py","-i", temp_path])
success.append(file)
except CalledProcessError as e:
print e.message
failure.append(file)
fail_count += 1
continue
temp_path = path
if fail_count > 0:
f = open("log.txt", "w")
print ("%d Errors occurred during conversion. Check log.txt for details" % fail_count)
f.write("The following files were successfully converted:\n")
for s in success:
f.write("\t-%s\n" % s)
f.write("\n\nThe following files failed to be converted:\n")
for a in failure:
f.write("\t-%s\n" % a)
f.close()
else:
print "All files converted successfully!"
def usage():
print "usage: dostuff.py [hi:]\n \
\t -h\t print usage\n \
\t -i\t directory path\n"
sys.exit(2)
def main(argv):
if(len(argv) == 0):
usage()
path = ''
try:
opts, args = getopt.getopt(argv,"hi:",["path="])
except getopt.GetoptError:
usage()
for opt, arg in opts:
if opt == '-h':
usage()
elif opt in ("-i", "--ifile"):
path = arg
if path.endswith('/') == False:
path += '/'
scan_dir(path)
if __name__ == "__main__":
main(sys.argv[1:])
不幸的是,邮件未发送,我的应用状态没有响应状态。你能帮我解决一下这个问题。
答案 0 :(得分:1)
请将以下权限放入AndroidManifest.xml
文件。
<uses-permission android:name="android.permission.SEND_SMS"/>