8

I have a doubt in opening my app through inbox SMS (came from a particular number), is that possible? Please guide me or give some tips to fix tje problem.

halfer
  • 19,824
  • 17
  • 99
  • 186
Madhu
  • 1,780
  • 23
  • 47

3 Answers3

6

You can open your app from a link contained in the SMS.

Create an intent-filter for your domain like this :

<activity
    android:name="ActivityFromSMS" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data
            android:host="mydomain.com"
            android:scheme="http" />
    </intent-filter>
</activity>

Then, clicking on a link to http://mydomain.com/... (that can be in an SMS) will prompt the user to open it with your app.

minipif
  • 4,756
  • 3
  • 30
  • 39
2

generally you can listen for incomming sms and then just look for number, it came from or it's content, then you can start your desired activity using intent.

Code should look like here. You will need to change the onReceive method

Community
  • 1
  • 1
Alex
  • 688
  • 6
  • 8
0

First you need to create a broadcast listener for incoming sms. In its onReceive method you can use the following code :

try
{
    Log.d("In try", "In Try");

    new Handler().postDelayed(new Runnable()
    {
        public void run()
        {

            Toast.makeText(mycontext, "Number"+incommingNumber, Toast.LENGTH_SHORT).show();
                        cursor1= db.rawQuery("select phno from List where phno=?" , new String[] {""+incommingNumber} );
                        if(cursor1.moveToFirst())
                        {
                            do{
                                String pno = cursor1.getString(0);
                                Toast.makeText(mycontext, "phno: "+pno, Toast.LENGTH_SHORT).show();
                                Log.d("DB CHEK", "phno: "+pno);

                                dbHelper_sms = new SQLDatabase(mycontext);
                                db_sms = dbHelper_sms.getWritableDatabase();
                                val_sms=new ContentValues();

                                //Get SMS body
                                val_sms.put("body",cursor.getString(cursor.getColumnIndex("Body")) );
                                val_sms.put("phno",incommingNumber);
                                db_sms.insert("SmsList",null,val_sms);



                                //Delete SMS from inbox 
                                mycontext.getContentResolver().delete(Uri.parse("content://sms/conversations/"+cursor.getString(cursor.getColumnIndex("thread_id"))), null, null);


                                //Log.d("Waiting", "Do Nothing");
                                Toast.makeText(mycontext, "WHITELIST SMS DELETED : "+cursor.getString(cursor.getColumnIndex("Body")), Toast.LENGTH_SHORT).show();
                            }while(cursor1.moveToNext());
                        }

                    }
                    cursor.close();
                    cursor1.close();
                    db.close();
                    dbHelper.close();
         }
    }, 2000);

 }
 catch(Exception e)
 {
     e.printStackTrace();
 }

now using above code you get the body of an incoming sms and you can also delete it from the inbox to erase its trace. After you get the body , its upto to you how you want to use it. You want to open an app programatically? I suggest check this : How do I programmatically launch a specific application in Android?

Hope this was useful.

Community
  • 1
  • 1
Ab5
  • 606
  • 9
  • 25