さて、私はこのプログラムを作成しました。SMSと自動再生を受信しますが、受信しますが再生しませんこれが私のReciver class.javaです
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class Reciving extends BroadcastReceiver{
static String from;
static String body;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method s
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
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]);
from = str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
body = str += msgs[i].getMessageBody().toString();
str += "\n";
}
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_LONG).show();
// ret = str;
SendGlass obj = new SendGlass();
// int tos = Integer.valueOf(body);
// obj.Decision(from, tos);
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
{
Main_Activity obj = new Main_Activity();
obj.sms(from, body1);
}
else{
}
}
}
}
私のSMS送信クラス
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.telephony.SmsManager;
public class SendGlass extends Activity {
static String REPLAYS1,REPLAYS2;
/** public void databaser()
{
SQLiteDatabase db = openOrCreateDatabase("TEST", MODE_PRIVATE, null);
Cursor c = db.rawQuery("SELECT REPLAYS FROM Rtm WHERE ID = 1 ",null);
c.moveToFirst();
REPLAYS1 = c.getString(c.getColumnIndex("REPLAYS"));
c = db.rawQuery("SELECT REPLAYS FROM Rtm WHERE ID = 2", null);
c.moveToFirst();
REPLAYS2 = c.getString(c.getColumnIndex("REPLAYS"));
c.moveToFirst();
db.close();
c.close();
}
public void Decision(String phone ,int mesage )
{
String phonenum = String.valueOf(mesage);
switch(mesage)
{
case 1:
sms(phonenum, "hello world1");
break;
case 2:
sms(phonenum, "hello world2");
break;
default:
sms(phonenum, "defaulter");
break;
}
} **/
public void sms (String phone,String Sms )
{
String phoneNo = phone;
String sms = Sms;
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
}
}
私のmenifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dom.example.dbfinal"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Screen1"
android:label="@string/title_activity_screen1" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Screen2"
android:label="@string/title_activity_screen2" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Screen3"
android:label="@string/title_activity_screen3" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DtaBase"
android:label="@string/title_activity_dta_base" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".Reciving" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" >
</action>
</intent-filter>
</receiver>
</application>
SMSが受信されたときにトーストが表示されるが再生されないという問題を誰か教えてもらえますか