Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>earlier i came here for solution but didn't get. now i have solved it and decided to post answer myself.</p> <h1>if you want to know message type is Text or MMS?</h1> <p>create an Activity where we will start a Service</p> <hr> <pre><code>public class ListenSMSActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //start the service to listen startService(new Intent(getBaseContext(),ListenSMSService.class)); }} </code></pre> <hr> <p>create a service where we will use content Observer</p> <hr> <pre><code>public class ListenSMSService extends Service{ //Context globalContext; ContentResolver contentResolver; @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public void onCreate() { registerObserver(); } public void registerObserver() { contentResolver = getContentResolver(); contentResolver.registerContentObserver(Uri.parse ("content://mms-sms/conversations/"), true, new MyObserver(new Handler())); Log.v("Debug", " in registerObserver method........."); } @Override public int onStartCommand(Intent intent, int flags, int startId) { return START_STICKY; } class MyObserver extends ContentObserver { public MyObserver(Handler handler) { super(handler); // TODO Auto-generated constructor stub } @Override public void onChange(boolean selfChange) { super.onChange(selfChange); Log.v("Current Locaion", "in onChange method...."); final String[] projection = new String[]{"_id", "ct_t"}; Uri uri = Uri.parse("content://mms-sms/conversations/"); Cursor query = contentResolver.query(uri, projection, null, null, null); query.moveToFirst(); String string = query.getString(query.getColumnIndex("ct_t")); if ("application/vnd.wap.multipart.related".equals(string)) { // it's MMS Log.v("Debug", "it's MMS"); } else { // it's SMS Log.v("Debug", "it's SMS"); } } } </code></pre> <p>}</p> <hr> <p>and finally add permissions and make entry for service in manifest file</p> <hr> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rdc" android:versionCode="1" android:versionName="1.0"&gt; &lt;uses-sdk android:minSdkVersion="8" /&gt; &lt;uses-permission android:name="android.permission.SEND_SMS"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.RECEIVE_SMS"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.READ_SMS"&gt;&lt;/uses-permission&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name="com.rdc.ListenSMSActivity" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;service android:enabled="true" android:name="com.rdc.ListenSMSService"&gt; &lt;intent-filter&gt; &lt;action android:name="com.kns.ListenSMSService"&gt; &lt;/action&gt; &lt;/intent-filter&gt; &lt;/service&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <hr> <p>you will get the message type (sms/mms) in Logcat.</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.
    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