2014-01-29 34 views

回答

5

您可以從SMS中包含的鏈接打開您的應用程序。

爲您的域這樣的創建意圖過濾器:

<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> 

然後,點擊一個鏈接到http://mydomain.com/...(即可以在短信)上會提示用戶與您的應用程序打開它。

+0

非常感謝,我會試試.. – Madhu

+1

使用 而不是

2

一般來說,你可以收聽短信,然後尋找號碼,它來自或它的內容,然後你可以使用意向開始你想要的活動。

代碼應該看起來像here。您需要更改onReceive方法

0

首先,您需要爲傳入的短信創建廣播偵聽器。在它的onReceive方法,你可以使用下面的代碼:

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(); 
} 

現在使用上面的代碼中你會得到一個收到SMS的身體,你也可以從收件箱中刪除,以清除其蹤影。在你得到身體後,你會如何使用它。你想以編程方式打開一個應用程序?我建議檢查一下:How do I programmatically launch a specific application in Android?

希望這是有用的。

相關問題