use of fr.neamar.kiss.dataprovider.ContactsProvider in project KISS by Neamar.
the class IncomingSmsHandler method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
// Only handle SMS received
if (!intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
return;
}
// Stop if contacts are not enabled
DataHandler dataHandler = KissApplication.getDataHandler(context);
ContactsProvider contactsProvider = dataHandler.getContactsProvider();
if (contactsProvider == null) {
// Contacts have been disabled from settings
return;
}
// Get the SMS message passed in, if any
Bundle bundle = intent.getExtras();
if (bundle == null) {
return;
}
// Retrieve the SMS message received.
// Since we're not interested in content, we can safely discard
// all records but the first one
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus == null) {
return;
}
SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[0]);
// Now, retrieve the contact by its lookup key on our contactsProvider
ContactsPojo contactPojo = contactsProvider.findByPhone(msg.getOriginatingAddress());
if (contactPojo != null) {
// We have a match!
dataHandler.addToHistory(contactPojo.id);
}
}
use of fr.neamar.kiss.dataprovider.ContactsProvider in project KISS by Neamar.
the class IncomingCallHandler method onReceive.
@Override
public void onReceive(final Context context, Intent intent) {
try {
DataHandler dataHandler = KissApplication.getDataHandler(context);
ContactsProvider contactsProvider = dataHandler.getContactsProvider();
// Stop if contacts are not enabled
if (contactsProvider == null) {
return;
}
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (phoneNumber == null) {
// Skipping (private call)
return;
}
ContactsPojo contactPojo = contactsProvider.findByPhone(phoneNumber);
if (contactPojo != null) {
dataHandler.addToHistory(contactPojo.id);
}
}
} catch (Exception e) {
Log.e("Phone Receive Error", " " + e);
}
}
use of fr.neamar.kiss.dataprovider.ContactsProvider in project KISS by Neamar.
the class DataHandler method connectToProvider.
/**
* Require the data handler to be connected to the data provider with the given name
*
* @param name Data provider name (i.e.: `ContactsProvider` → `"contacts"`)
*/
protected void connectToProvider(final String name) {
// Do not continue if this provider has already been connected to
if (this.providers.containsKey(name)) {
return;
}
// Find provider class for the given service name
Intent intent = this.providerName2Intent(name);
if (intent == null) {
return;
}
// Send "start service" command first so that the service can run independently
// of the activity
this.context.startService(intent);
final ProviderEntry entry = new ProviderEntry();
// Connect and bind to provider service
this.context.bindService(intent, new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
// We've bound to LocalService, cast the IBinder and get LocalService instance
Provider.LocalBinder binder = (Provider.LocalBinder) service;
IProvider provider = binder.getService();
// Update provider info so that it contains something useful
entry.provider = provider;
entry.connection = this;
if (provider.isLoaded()) {
handleProviderLoaded();
}
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
}
}, Context.BIND_AUTO_CREATE);
// Add empty provider object to list of providers
this.providers.put(name, entry);
}
Aggregations