I have built a test app that upon button tap sends an automated SMS with pre-defined message to a pre-defined phone number. I have used intents.
But when I tap 'button' it crashes. Any ideas? Am I missing something or implementing wrong?
CODE:
package com.ali.sms;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Sms();
}
});
}
void Sms(){
Intent intent = new Intent( Intent.ACTION_SENDTO, Uri.parse("sms:0123456789"));
intent.putExtra("sms_body", "Hello!");
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
}
}
Manifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ali.sms"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.SEND_SMS" />
<application
android:allowBackup="true"
android:icon="@drawable/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>
</manifest>
In Eclipse/LogCat I'm getting this error:
android.content.ActivityNotFoundException: No Activity found to handle Intent {act=android.intent.action.SENDTO typ=vnd.android-dir/mms-sms (has extras) }
On phone error message is:
Unfortunately, SMS has stopped.
P.S. I have searched the web & stackoverflow for fixing No Activity found to handle Intent but to no avail.