Commit 44a8a434 by gao.chao

发送短信

parent ebc4d466
package com.mayi.demo; package com.mayi.demo;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.View; import android.view.View;
import com.mayi.fastdevelop.base.BaseActivity; import com.mayi.fastdevelop.base.BaseActivity;
...@@ -11,6 +17,7 @@ import com.mayi.fastdevelop.commonpage.WebActivity; ...@@ -11,6 +17,7 @@ import com.mayi.fastdevelop.commonpage.WebActivity;
import com.mayi.fastdevelop.commonpage.amap.MapLocationActivity; import com.mayi.fastdevelop.commonpage.amap.MapLocationActivity;
import com.mayi.fastdevelop.comnon.Key; import com.mayi.fastdevelop.comnon.Key;
import com.mayi.fastdevelop.comnon.RequestCode; import com.mayi.fastdevelop.comnon.RequestCode;
import com.mayi.fastdevelop.util.SystemUtil;
import com.mayi.fastdevelop.util.ToastUtil; import com.mayi.fastdevelop.util.ToastUtil;
import com.mayi.fastdevelop.util.ToolUtils; import com.mayi.fastdevelop.util.ToolUtils;
import com.mayi.fastdevelop.view.OnMultiClickListener; import com.mayi.fastdevelop.view.OnMultiClickListener;
...@@ -25,24 +32,24 @@ public class PageActivity extends BaseActivity { ...@@ -25,24 +32,24 @@ public class PageActivity extends BaseActivity {
findViewById(R.id.b1).setOnClickListener(new OnMultiClickListener() { findViewById(R.id.b1).setOnClickListener(new OnMultiClickListener() {
@Override @Override
public void onMultiClick(View v) { public void onMultiClick(View v) {
Bundle bundle=new Bundle(); Bundle bundle = new Bundle();
bundle.putString("url","https://customer.kujiatech.com/#/?token=8427db8972dd09105a00d62d8bc7cfd5&username=18001874470&v="+System.currentTimeMillis()); bundle.putString("url", "https://customer.kujiatech.com/#/?token=8427db8972dd09105a00d62d8bc7cfd5&username=18001874470&v=" + System.currentTimeMillis());
gotoActivity(WebActivity.class,bundle); gotoActivity(WebActivity.class, bundle);
} }
}); });
findViewById(R.id.b2).setOnClickListener(new OnMultiClickListener() { findViewById(R.id.b2).setOnClickListener(new OnMultiClickListener() {
@Override @Override
public void onMultiClick(View v) { public void onMultiClick(View v) {
Bundle bundle=new Bundle(); Bundle bundle = new Bundle();
bundle.putString("url","https://customer.kujiatech.com/#/?token=8427db8972dd09105a00d62d8bc7cfd5" + bundle.putString("url", "https://customer.kujiatech.com/#/?token=8427db8972dd09105a00d62d8bc7cfd5" +
"&username=18001874470&v="+System.currentTimeMillis()+"&isNeedBackButton=true&userAppTitle=潜客"); "&username=18001874470&v=" + System.currentTimeMillis() + "&isNeedBackButton=true&userAppTitle=潜客");
gotoActivity(WebActivity.class,bundle); gotoActivity(WebActivity.class, bundle);
} }
}); });
findViewById(R.id.b3).setOnClickListener(new OnMultiClickListener() { findViewById(R.id.b3).setOnClickListener(new OnMultiClickListener() {
@Override @Override
public void onMultiClick(View v) { public void onMultiClick(View v) {
ToolUtils.goScanActivity(v.getContext(),MyScanActivity.class); ToolUtils.goScanActivity(v.getContext(), MyScanActivity.class);
} }
}); });
findViewById(R.id.b4).setOnClickListener(new OnMultiClickListener() { findViewById(R.id.b4).setOnClickListener(new OnMultiClickListener() {
...@@ -74,8 +81,8 @@ public class PageActivity extends BaseActivity { ...@@ -74,8 +81,8 @@ public class PageActivity extends BaseActivity {
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode== RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE){ if (requestCode == RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE) {
if (resultCode== Activity.RESULT_OK){ if (resultCode == Activity.RESULT_OK) {
showToast(data.getStringExtra(Key.AVTIVITY_RESULT)); showToast(data.getStringExtra(Key.AVTIVITY_RESULT));
} }
} }
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="com.mayi.fastdevelop"> package="com.mayi.fastdevelop">
<uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /> <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
......
...@@ -30,6 +30,7 @@ import com.mayi.fastdevelop.comnon.RequestCode; ...@@ -30,6 +30,7 @@ import com.mayi.fastdevelop.comnon.RequestCode;
import com.mayi.fastdevelop.util.BitmapUtil; import com.mayi.fastdevelop.util.BitmapUtil;
import com.mayi.fastdevelop.util.DialogUtils; import com.mayi.fastdevelop.util.DialogUtils;
import com.mayi.fastdevelop.util.SpUtil; import com.mayi.fastdevelop.util.SpUtil;
import com.mayi.fastdevelop.util.SystemUtil;
import com.mayi.fastdevelop.view.CustomTitleBar; import com.mayi.fastdevelop.view.CustomTitleBar;
import com.mayi.fastdevelop.view.dialog.BaseDialog; import com.mayi.fastdevelop.view.dialog.BaseDialog;
import com.tencent.bugly.crashreport.CrashReport; import com.tencent.bugly.crashreport.CrashReport;
...@@ -248,10 +249,7 @@ public class WebActivity extends BaseActivity { ...@@ -248,10 +249,7 @@ public class WebActivity extends BaseActivity {
@Override @Override
public void run() { public void run() {
if (TextUtils.equals("goCallPhone", method)) {//去打电话 if (TextUtils.equals("goCallPhone", method)) {//去打电话
Intent intent = new Intent(Intent.ACTION_DIAL); SystemUtil.makePhoneCall(WebActivity.this, data);
Uri uri = Uri.parse("tel:" + data);
intent.setData(uri);
startActivity(intent);
} else if (TextUtils.equals("backPage", method)) {//返回上一页 } else if (TextUtils.equals("backPage", method)) {//返回上一页
webPageBack(); webPageBack();
} else if (TextUtils.equals("goPage", method)) {//跳转原生页面 } else if (TextUtils.equals("goPage", method)) {//跳转原生页面
...@@ -264,18 +262,26 @@ public class WebActivity extends BaseActivity { ...@@ -264,18 +262,26 @@ public class WebActivity extends BaseActivity {
} else if (TextUtils.equals("openDebug", method)) {//开启Debug模式 } else if (TextUtils.equals("openDebug", method)) {//开启Debug模式
WebView.setWebContentsDebuggingEnabled(true); WebView.setWebContentsDebuggingEnabled(true);
} else if (TextUtils.equals("goBrowser", method)) {//跳转浏览器 } else if (TextUtils.equals("goBrowser", method)) {//跳转浏览器
Intent intent = new Intent(); SystemUtil.gotoWeb(WebActivity.this, data);
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse(data);
intent.setData(content_url);
startActivity(intent);
} else if (TextUtils.equals("getUserInfo", method)) {//给web传递用户信息 } else if (TextUtils.equals("getUserInfo", method)) {//给web传递用户信息
appCallJs("setUserInfo", SpUtil.get(Key.USER_INFO, "")); appCallJs("setUserInfo", SpUtil.get(Key.USER_INFO, ""));
} else if (TextUtils.equals("sendSMS", method)) {//发送短信
sendSMS(data);
} }
} }
}); });
} }
private void sendSMS(String data) {
try {
JSONObject jsonObject = new JSONObject(data);
SystemUtil.sendSMS(WebActivity.this, jsonObject.optString("phone")
, jsonObject.optString("msg"));
} catch (JSONException e) {
e.printStackTrace();
}
}
/** /**
* 跳转原生页面 * 跳转原生页面
* 待扩展 * 待扩展
...@@ -335,11 +341,11 @@ public class WebActivity extends BaseActivity { ...@@ -335,11 +341,11 @@ public class WebActivity extends BaseActivity {
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode==RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE){ if (requestCode == RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE) {
if (resultCode== Activity.RESULT_OK){ if (resultCode == Activity.RESULT_OK) {
showToast(data.getStringExtra(Key.AVTIVITY_RESULT)); showToast(data.getStringExtra(Key.AVTIVITY_RESULT));
} }
}else if (requestCode == RequestCode.REQUEST_CODE_ALBUM || requestCode == RequestCode.REQUEST_CODE_CAMERA) { } else if (requestCode == RequestCode.REQUEST_CODE_ALBUM || requestCode == RequestCode.REQUEST_CODE_CAMERA) {
if (uploadMessage == null && uploadMessageAboveL == null) { if (uploadMessage == null && uploadMessageAboveL == null) {
return; return;
} }
......
...@@ -10,7 +10,6 @@ import android.content.Intent; ...@@ -10,7 +10,6 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Point; import android.graphics.Point;
...@@ -19,6 +18,7 @@ import android.net.Uri; ...@@ -19,6 +18,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.annotation.FloatRange; import android.support.annotation.FloatRange;
import android.telephony.TelephonyManager;
import android.text.method.HideReturnsTransformationMethod; import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod; import android.text.method.PasswordTransformationMethod;
import android.view.Display; import android.view.Display;
...@@ -27,14 +27,11 @@ import android.view.Window; ...@@ -27,14 +27,11 @@ import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast;
import com.mayi.fastdevelop.R; import com.mayi.fastdevelop.R;
import java.io.File; import java.io.File;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URLDecoder;
/** /**
* 系统相关工具类 * 系统相关工具类
...@@ -179,7 +176,6 @@ public class SystemUtil { ...@@ -179,7 +176,6 @@ public class SystemUtil {
activity.requestWindowFeature(Window.FEATURE_NO_TITLE); activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
} }
/** /**
* 返回一个控件在其父窗口中的坐标位置 x, y * 返回一个控件在其父窗口中的坐标位置 x, y
* *
...@@ -307,11 +303,18 @@ public class SystemUtil { ...@@ -307,11 +303,18 @@ public class SystemUtil {
* @param tel 电话号码 * @param tel 电话号码
*/ */
public static void makePhoneCall(Context context, String tel) { public static void makePhoneCall(Context context, String tel) {
try { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:" + tel)); switch (tm.getSimState()) { //getSimState()取得sim的状态
context.startActivity(intent); case TelephonyManager.SIM_STATE_UNKNOWN://状态未知
} catch (Exception e) { case TelephonyManager.SIM_STATE_ABSENT://设备中没有可用的SIM卡
e.printStackTrace(); ToastUtil.show(context, context.getString(R.string.not_phone));
break;
default:
Intent intent = new Intent(Intent.ACTION_DIAL);
Uri uri = Uri.parse("tel:" + tel);
intent.setData(uri);
context.startActivity(intent);
break;
} }
} }
...@@ -488,4 +491,27 @@ public class SystemUtil { ...@@ -488,4 +491,27 @@ public class SystemUtil {
context.startActivity(intent); context.startActivity(intent);
} }
/**
* 发送短信,跳转系统发送短信页面,先验证sim状态
*
* @param context
* @param phone 手机号
* @param msg 发送的信息
*/
public static void sendSMS(Context context, String phone, String msg) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
switch (tm.getSimState()) { //getSimState()取得sim的状态
case TelephonyManager.SIM_STATE_UNKNOWN://状态未知
case TelephonyManager.SIM_STATE_ABSENT://设备中没有可用的SIM卡
ToastUtil.show(context, context.getString(R.string.not_phone));
break;
default:
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + phone));
intent.putExtra("sms_body", msg);
context.startActivity(intent);
break;
}
}
} }
...@@ -17,6 +17,7 @@ import com.mayi.fastdevelop.util.ActivitysManager; ...@@ -17,6 +17,7 @@ import com.mayi.fastdevelop.util.ActivitysManager;
import com.mayi.fastdevelop.util.DownLoadUtil; import com.mayi.fastdevelop.util.DownLoadUtil;
import com.mayi.fastdevelop.util.PermissionUtil; import com.mayi.fastdevelop.util.PermissionUtil;
import com.mayi.fastdevelop.util.SpUtil; import com.mayi.fastdevelop.util.SpUtil;
import com.mayi.fastdevelop.util.SystemUtil;
import com.mayi.fastdevelop.util.ToastUtil; import com.mayi.fastdevelop.util.ToastUtil;
import com.mayi.fastdevelop.view.dialog.BaseDialog; import com.mayi.fastdevelop.view.dialog.BaseDialog;
import com.mayi.fastdevelop.view.dialog.DialogViewHolder; import com.mayi.fastdevelop.view.dialog.DialogViewHolder;
...@@ -86,11 +87,7 @@ public class AppUpgradeManager { ...@@ -86,11 +87,7 @@ public class AppUpgradeManager {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
dismiss(); dismiss();
Intent intent = new Intent(); SystemUtil.gotoWeb(v.getContext(),info.getUpdateUrl());
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse(info.getUpdateUrl());
intent.setData(content_url);
mContext.startActivity(intent);
} }
}); });
} }
......
...@@ -20,4 +20,5 @@ ...@@ -20,4 +20,5 @@
<string name="close_light">关闭闪光灯</string> <string name="close_light">关闭闪光灯</string>
<string name="position">位置</string> <string name="position">位置</string>
<string name="send">发送</string> <string name="send">发送</string>
<string name="not_phone">本机没有手机号</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment