Dans mon application, je passe un appel. Après la fin de l'appel, j'ai besoin d'obtenir la durée de l'appel et de supprimer cette entrée d'appel de la liste des appels du périphérique. Toutes ces fonctionnalités fonctionnent correctement comme prévu. Maintenant, le problème est lorsque je fais un appel depuis l'extérieur de l'application, comme à partir de l'appel de périphérique par défaut, il supprime l'appel en cours. comment le restreindre? emploie un BroadcastReceiver
comme ci-dessousSupprimer le journal des appels uniquement lorsque l'appel est créé à partir de l'application
@Override
public void onReceive(Context ctx, Intent intent)
{
String action = intent.getAction();
db=new DatabaseMethods(ctx);
if (action.equalsIgnoreCase("android.intent.action.PHONE_STATE"))
{
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING))
{
//when call arrives
}
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
{
Toast.makeText(ctx, "EXTRA_STATE_OFFHOOK",Toast.LENGTH_LONG).show();
start_time = System.currentTimeMillis();
AppConstants.START_TIME=Utils.formatToDateTime(start_time);
AppConstants.CALL_DURATION="00:00:00";
System.out.println("Start Time Millis"+"="+start_time);
System.out.println("Start Time"+"="+AppConstants.START_TIME);
}
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_IDLE))
{
try
{
int idOfRowToDelete = 0 ;
Uri allCalls = Uri.parse("content://call_log/calls");
String lastMinute = String.valueOf(new Date().getTime() - start_time);
//before the call started
Cursor c = ctx.getContentResolver().query(allCalls, null, Calls.DATE + " > "
+ lastMinute, null, Calls.DATE + " desc");
c.moveToFirst();
if (c.getCount() > 0) {
duration= Integer.parseInt(c.getString(c.getColumnIndex(Calls.DURATION)));
idOfRowToDelete = c.getInt(c.getColumnIndex(Calls._ID));
}
if(duration>0)
{
AppConstants.CALL_DURATION=Utils.formatSceondstoHHMMSS(duration);
}
else
{
AppConstants.CALL_DURATION="00:00:00";
}
ctx.getContentResolver().delete(allCalls, Calls._ID + "= ? ", new String[] { String.valueOf(idOfRowToDelete) });
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
db.new AsyncSaveCallDetails().execute();
}
}
}
}
son fonctionnement. J'ai essayé avec un récepteur non enregistré sur onpause aussi. Mais quand jamais un appel commence une activité onpause est toujours appelée. Donc, je pense que la seule option reste d'utiliser des drapeaux. – Meenaxi
Super !!! profiter @ Menaxi :) –