我正在研究Namaz Manager我已经在数据库中保存了Namaz的时间。我希望当Namaz时间战斗Azaan发挥和Azan完成移动后切换到沉默。 我只为一个Namaz尝试了这个,但这不起作用......
public class alarmService extends IntentService
{
public alarmService() {
super("alarmService");
// TODO Auto-generated constructor stub
}
protected void onHandleIntent(Intent workIntent)
{
// We want this service to continue running until it is explicitly
// stopped, so return sticky.
int i=0;
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
while(true)
{
try
{
dataBase db=new dataBase(this);
SQLiteDatabase database=db.getReadableDatabase();
Calendar calender=Calendar.getInstance();
int m=calender.get(calender.MONTH)+1;
int d=calender.get(calender.DAY_OF_MONTH);
String query="SELECT * FROM NAMAZ WHERE DAY="+d+" AND MONTH="+m+" ;";
String []values=new String[10];
android.database.Cursor cursor=database.rawQuery(query, null);
if(cursor.moveToFirst())
{
do
{
values[i]=cursor.getString(1);
i++;
SimpleDateFormat sdf=new SimpleDateFormat("hh:mm");
SimpleDateFormat sdf1=new SimpleDateFormat("hh:mm aa");
try {
java.util.Date date=sdf.parse(cursor.getString(2));
values[i]=sdf1.format(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
Toast.makeText(this,e+"" , Toast.LENGTH_LONG).show();
}
i++;
}while(cursor.moveToNext());
}
for(int c=1;c<10;c+=2)
{
SimpleDateFormat sd=new SimpleDateFormat("hh:mm aa");
Date namazTime=sd.parse(values[c]);
Date currTime=new Date(System.currentTimeMillis());
if(currTime.equals(namazTime) && values[c-1].equals("Fajar"))
{
AssetFileDescriptor afd = getAssets().openFd("Fajr Azan.mp3");
MediaPlayer player = new MediaPlayer();
player.setDataSource(afd.getFileDescriptor());
player.prepare();
player.start();
final Handler handler = new Handler();
wait(3000000);
AudioManager am=(AudioManager)getSystemService(AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
wait(3000000);
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
if(currTime.equals(namazTime))
{
}
}
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};