Но проблема в том что у меня не отправляются SMS, в Android Manifest я вписал права на отправку и написание сообщений, тут код по сути полной программы: Android manifest - 1, Main Activity -2 и activity_main.xml - 3.
Даже когда была одна кнопка, по нажатию которой исполнялось такое действие:
Код: Выделить всё
OnClickListener Btns = new OnClickListener() {
@Override
public void onClick(View v) {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("+380000000000", null, "Тест", null, null);
}
};
}В чем ошибка - и где можна найти примеры программ по отправке SMS? желательно с возможностью ввода текста(хотя в этом и сам могу разобраться, если по нажатию кнопки отправится SMS-ка)
Вот моя программа:
Android Manifest:
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ua.com.glab.smstest" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
</manifest>Код: Выделить всё
public class MainActivity extends ActionBarActivity implements View.OnClickListener {
Button Btns;
EditText edtxt;
EditText number;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtxt = (EditText) findViewById(R.id.edtxt);
number = (EditText) findViewById(R.id.number);
Btns = (Button) findViewById(R.id.Btns);
Btns.setOnClickListener(this);
}
@Override
public void onClick(View view) {
number.setText(number.getText().toString());
edtxt.setText(edtxt.getText().toString());
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(number.getText().toString(), null, edtxt.getText().toString(), null, null);
}
}Код: Выделить всё
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+380676711761"
android:id="@+id/number"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Текст"
android:id="@+id/edtxt"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Отправить SMS"
android:id="@+id/Btns" />
</LinearLayout>