Hello! I have an application which reads call logs, incoming sms, and outgoing sms.
When the application is first launched, it shows call logs and then listens for incoming and outgoing sms. I have three classes: Main Activity, IncomingSms.Java and outgoingSms.java.
The main activity starts normally and shows everything fine, but the incoming and outgoing sms functions are not triggered. My incoming and outgoing sms classes are 100% correct and works fine if I create and run as new project but they don't work together.
All I want is to trigger all these processes simultaneously here is my code.
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getCallDetails();
}
@SuppressWarnings("deprecation")
private void getCallDetails() {
//rest of code here
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
my IncmingSms.java
public class IncomingSms extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
final Bundle bundle = intent.getExtras();
final SmsManager sms = SmsManager.getDefault();
// REST OF CODE HERE
}
}
OutgoingSms.java
public class OutgoingSms extends Activity {
final SmsManager sms = SmsManager.getDefault();
ContentResolver contentResolver;
ContentObserver smsContentObserver;
@Override
public void onResume() {
super.onResume();
smsContentObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
Uri smsURI = Uri.parse("content://sms/sent");
Cursor c = getContentResolver().query(smsURI, new String[] {
"address", "date", "body", "type"
}, null, null, null);
String[] columns = new String[] {
"address", "date", "body", "type"
};
c.moveToNext();
Rest of Code here@ Override
public boolean deliverSelfNotifications() {
return true;
}
};
contentResolver.registerContentObserver(Uri.parse("content://sms"), true, smsContentObserver);
}
@Override
public void onDestroy() {
super.onDestroy();
contentResolver.unregisterContentObserver(smsContentObserver);
}
}