着信 SMS でアクティビティを開始したいので、これを行いました...
public class ReceiveSMS extends BroadcastReceiver {
Boolean SendSMS;
String Mobileno;
String VarMessageBody;
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i = 0; i < msgs.length; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
Mobileno = msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
VarMessageBody = msgs[i].getMessageBody().toString();
str += "\n";
Mobileno = msgs[i].getOriginatingAddress();
}
if (VarMessageBody.startsWith("START")) {
Intent intentHome = new Intent(context,SwitchBluetoothActivity.class);
intentHome.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentHome);
}
}
}
}
私のSwitchBluetoothActivityクラスはこのようなものです..
public class SwitchBluetoothActivity extends Activity {
private TextView tv;
private ToggleButton tb;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.bluetoothText);
tb = (ToggleButton) findViewById(R.id.toggleButton);
final BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
if (bta == null) {
tv.setText("Device does not support Bluetooth");
}
else if(bta.isEnabled()){
tv.setText("Bluetooth is enabled");
tb.setChecked(true);
}
else{
tv.setText("Bluetooth is disabled");
tb.setChecked(false);
}
tb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(bta.isEnabled()){
bta.disable();
tv.setText("Bluetooth is disabled");
}
else{
bta.enable();
tv.setText("Bluetooth is enabled");
}
}
});
}
}
そして、私は AndroidManifest.xml にもインテントフィルターを追加しました.しかし、私の問題は. このアクティビティを開始できません。どこで間違いを犯したのか教えてください。
ここに私のマニフェストファイルがあります
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxxxxx.smsServices"
android:versionCode="1"
android:versionName="1.0" >
<activity android:name=".SwitchBluetoothActivity">
</activity>
<receiver android:name=".ReceiveSMS">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.BROADCAST_SMS"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
</application>
</manifest>