Android实现短信加密功能(发送加密短信、解密本地短信)

2019-12-10 19:29:23于丽

ReceiveActivity_show:

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 
 
public class ReceiveActivity_show extends Activity { 
 private TextView Address_show; 
 private TextView Time_show; 
 private TextView Early_body_show; 
 private TextView Late_body_show; 
 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.activity_receive_show); 
 
 InitView(); 
 } 
 
 private void InitView() { 
 
 Address_show = (TextView) findViewById(R.id.address_show); 
 Time_show = (TextView) findViewById(R.id.time_show); 
 Early_body_show = (TextView) findViewById(R.id.early_body_show); 
 Late_body_show = (TextView) findViewById(R.id.late_body_show); 
 
 //接收内容和id 
 Bundle bundle = this.getIntent().getExtras(); 
 String body = bundle.getString("body"); 
 String time = bundle.getString("time"); 
 String address = bundle.getString("address"); 
 
 
 Address_show.setText(address); 
 Early_body_show.setText(body); 
 Time_show.setText(time); 
 
 //对短信消息进行解密后显示在textview中 
 //倘若char+8超出了表示范围,则直接按照原字符解析 
 String real_content = ""; 
 for (int i = 0; i < body.length(); i++) { 
  try { 
  char textchar=(char) (body.charAt(i) + 8); 
  real_content += (char) (body.charAt(i) - 8); 
  }catch (Exception e){ 
  real_content += (char) (body.charAt(i)); 
  } 
 } 
 Late_body_show.setText(real_content); 
 } 
 
} 

activity_main:

<?xml version="1.0" encoding="utf-8"?> 
 
<LinearLayout xmlns:android="http://www.easck.com/apk/res/android" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:orientation="vertical"> 
 
 <TextView 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:background="#000" 
 android:padding="12dp" 
 android:text="加密短信" 
 android:textColor="#fff" 
 android:textSize="25sp" 
 android:textStyle="bold" /> 
 <Button 
 android:layout_marginTop="120dp" 
 android:id="@+id/bt_send" 
 android:layout_width="200dp" 
 android:layout_height="80dp" 
 android:text="发送加密短信" 
 android:layout_gravity="center" 
 android:textSize="20dp"/> 
 <Button 
 android:id="@+id/bt_receive" 
 android:layout_width="200dp" 
 android:layout_height="80dp" 
 android:layout_gravity="center" 
 android:text="解密本地短信" 
 android:textSize="20dp" 
 android:layout_below="@+id/bt_send"/> 
 
</LinearLayout>