清单
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.SEND_SMS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="Konfigurační zprávy"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SaveRecord"
android:label="@string/title_activity_save_record"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".ZobrazeniSeznamu" />
<activity
android:name=".DataList"
android:label="@string/title_activity_data_list"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".SMS"></activity>
</application>
Noobish短信经理
public class SMS extends AppCompatActivity {
TextView tvUkazka;
Button bOdeslat;
EditText tvCislo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
tvUkazka = (TextView)findViewById(R.id.tvUkazka);
tvUkazka.setText(DataList.smsText);
tvCislo = (EditText)findViewById(R.id.etCislo);
bOdeslat = (Button)findViewById(R.id.bOdeslat);
bOdeslat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String cislo = tvCislo.getText().toString();
String telo = DataList.smsText;
//Uri uri = Uri.parse("smsto:" + cislo);
//Intent smsIntent = new Intent(Intent.ACTION_SENDTO, uri);
//smsIntent.putExtra("sms_body", telo);
//startActivity(smsIntent);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(cislo, null, telo, null, null);
Intent navrat = new Intent(SMS.this,MainActivity.class);
startActivity(navrat);
} catch (Exception e){
Toast.makeText(getBaseContext(), "Něco je špatně", Toast.LENGTH_LONG).show();
}
}
});
}
}