Note that there are some explanatory texts on larger screens.

plurals
  1. POLaunch an application in background- Launch Service in background to copy sms content into db
    primarykey
    data
    text
    <p>I am trying to develop an application that allows you to save a SQLite database of SMS on the phone as they arrive. I am using the broadcast receiver to recover the message then the activity component to insert into the database. But I'd replace activity by service for the application does not bother the user. Does anyone want to help me.Here is my code://</p> <blockquote> <p>MainActivity.java</p> </blockquote> <pre><code> public class MainActivity extends BroadcastReceiver { private final String ACTION_RECEIVE_SMS = "android.provider.Telephony.SMS_RECEIVED"; @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION_RECEIVE_SMS)) { Bundle bundle = intent.getExtras(); if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); SmsMessage[] message = new SmsMessage[pdus.length]; for (int i = 0; i &lt; pdus.length; i++) { message[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); } if (message.length &gt; -1) { String messageBody = message[0].getMessageBody(); String phoneNumber = message[0].getDisplayOriginatingAddress(); Toast.makeText(context, "Expediteur - numero :" + phoneNumber + " Sms : " + messageBody, Toast.LENGTH_SHORT).show(); Intent SecondeItent = new Intent(context, SmsActivity.class); SecondeItent.putExtra("phoneNumber", phoneNumber); SecondeItent.putExtra("messageBody", messageBody); SecondeItent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(SecondeItent); } } } } } public class SmsActivity extends Activity { smsdao.open(); smsdao.insertSms(sms); Sms smsFromBdd = smsdao.getSmsWithNum(sms.getNum()); if (smsFromBdd != null) { Toast.makeText(this, sms FromBdd.toString(), Toast.LENGTH_LONG).show(); } smsdao.close(); } } </code></pre> <p>Other file: SmsDao.java,MyBaseSQLite.java, Sms.java et AndroidManifest.xml, but there are no problems on these files.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload