我对通过收件箱短信(来自特定号码)打开我的应用程序有疑问,这可能吗?请指导我或给出一些解决tje问题的技巧。
发布于 2014-01-29 19:32:09
您可以从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/...
的链接(可以在短信中),将提示用户使用您的应用程序打开它。
发布于 2014-01-29 19:36:26
通常你可以收听进来的短信,然后只需查找号码,它来自或它的内容,然后你就可以开始你想要的活动使用intent。
代码应该类似于here。您将需要更改onReceive
方法
发布于 2014-01-29 19:52:40
首先,您需要为传入的sms创建一个广播侦听器。在它的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?
希望这是有用的。
https://stackoverflow.com/questions/21429677
复制相似问题