如何通过来自特定短信发送器(特定短信端口)的短信激活 Android 应用程序

发布于 2024-11-28 04:57:00 字数 75 浏览 2 评论 0原文

我需要开发一个Android应用程序,它将接收来自特定发件人的短信,当收到短信时,该应用程序必须激活并获取短信附带的所有值,请给我答案?

I need to develop an Android App which will receive SMS from a Specific sender, when the SMS received, the App has to get activated and gets all the values which came with the SMS, please provide me the answer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

做个少女永远怀春 2024-12-05 04:57:00

您可以使用 BroadcastReciver 来读取短信。并提取该短信并将值保存在 android 的数据库中。当您调用第一个活动时,检查数据库中包含的特定值,然后仅启动该活动。

 public class ReadingMessage extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {
    //---get the SMS message passed in---
    Bundle bundle = intent.getExtras(); 
    DBAdapter dbHelper = new DBAdapter(context);
    SmsMessage[] msgs = null;
    String msg=null;
    String str=null;
    if (bundle != null)
    {
        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");

        msgs = new SmsMessage[pdus.length];            
        for (int i=0; i<msgs.length; i++){
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                

            msg = msgs[i].getMessageBody().toString();
            str =msg.toUpperCase();        


            if(str.contains("your value"))
            {
            try{
                dbHelper.open();

                dbHelper.insertinfo(msg);                   

                dbHelper.close();

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

            }

        }
           }  
  }

}

此代码用于读取短信。

 public class StartActivity extends Activity{

    private static final int ACTIVITY_REGISTRATION1=0;
    private static final int ACTIVITY_SENDALERT3=1;
    private static final int ACTIVITY_REGISTRATION2 = 2;

      Context context;
      DBAdapter dbHelper=null;
      Intent intent;
      String db_activation=null;
      Cursor cursor;

  public StartActivity()
  {
      this.context=this;
  }

@Override

/* Method Header
 * Method Name      : onCreate
 * Input Parameter  : Bundle
 * Return Value     : nil
 */
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

     dbHelper=new DBAdapter(this);

     try
     {
     dbHelper.open();

     cursor = dbHelper.getActivtaion();
     if(cursor.getCount()==0)
     {

        intent=new Intent(this,Registration.class);

        intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        startActivityForResult(intent,ACTIVITY_REGISTRATION1);
     }
     else
     {
        for(int i=0;i<cursor.getCount();i++)
        {
            cursor.moveToNext();
            db_activation = cursor.getString(cursor.getColumnIndex(DBAdapter.KEY_ACTIVATION));

     if(db_activation.equals("1"))

     {


        intent=new Intent(this,SendAlert.class);

        intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        startActivityForResult(intent,ACTIVITY_SENDALERT3);



     }
    else
    {

        intent=new Intent(this,Registration.class);

        intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        startActivityForResult(intent,ACTIVITY_REGISTRATION2);
    }

     dbHelper.close();
}
     }
     }
catch(Exception e)
{
finish();
System.exit(0);
   e.toString();
}
}
@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    finish();

}

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
     if (resultCode == Activity.RESULT_OK)
     finish();
    }
  }

第一个活动的代码

  public long insertTruckinfo(String db_Truckmsg)
    {
    ContentValues cVal=new ContentValues();

    cVal.put(KEY_INFO,db_Truckmsg);


    return db.insert(TRUCKINFO_TABLE, null,cVal);

}


public Cursor getActivtaion()
{
     Cursor cursor =db.query(ACTIVATION_TABLE, new String[] {KEY_ID,KEY_ACTIVATION}, null,null, null, null, null);
     return cursor;
}


public Cursor getTruckinfo()
{
     Cursor cursor =db.query(TRUCKINFO_TABLE, new String[] {KEY_ID,KEY_INFO}, null,null, null, null, null);
     return cursor;
}

位于 DataBase 类中。

我认为这对你有帮助......

You can use BroadcastReciver for reading sms. And extract that sms and save values in DataBase in android . When you call the first Activity check the particular value contains in the DataBase then only start the Activity.

 public class ReadingMessage extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {
    //---get the SMS message passed in---
    Bundle bundle = intent.getExtras(); 
    DBAdapter dbHelper = new DBAdapter(context);
    SmsMessage[] msgs = null;
    String msg=null;
    String str=null;
    if (bundle != null)
    {
        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");

        msgs = new SmsMessage[pdus.length];            
        for (int i=0; i<msgs.length; i++){
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                

            msg = msgs[i].getMessageBody().toString();
            str =msg.toUpperCase();        


            if(str.contains("your value"))
            {
            try{
                dbHelper.open();

                dbHelper.insertinfo(msg);                   

                dbHelper.close();

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

            }

        }
           }  
  }

}

This code for Reading SMS.

 public class StartActivity extends Activity{

    private static final int ACTIVITY_REGISTRATION1=0;
    private static final int ACTIVITY_SENDALERT3=1;
    private static final int ACTIVITY_REGISTRATION2 = 2;

      Context context;
      DBAdapter dbHelper=null;
      Intent intent;
      String db_activation=null;
      Cursor cursor;

  public StartActivity()
  {
      this.context=this;
  }

@Override

/* Method Header
 * Method Name      : onCreate
 * Input Parameter  : Bundle
 * Return Value     : nil
 */
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

     dbHelper=new DBAdapter(this);

     try
     {
     dbHelper.open();

     cursor = dbHelper.getActivtaion();
     if(cursor.getCount()==0)
     {

        intent=new Intent(this,Registration.class);

        intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        startActivityForResult(intent,ACTIVITY_REGISTRATION1);
     }
     else
     {
        for(int i=0;i<cursor.getCount();i++)
        {
            cursor.moveToNext();
            db_activation = cursor.getString(cursor.getColumnIndex(DBAdapter.KEY_ACTIVATION));

     if(db_activation.equals("1"))

     {


        intent=new Intent(this,SendAlert.class);

        intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        startActivityForResult(intent,ACTIVITY_SENDALERT3);



     }
    else
    {

        intent=new Intent(this,Registration.class);

        intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        startActivityForResult(intent,ACTIVITY_REGISTRATION2);
    }

     dbHelper.close();
}
     }
     }
catch(Exception e)
{
finish();
System.exit(0);
   e.toString();
}
}
@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    finish();

}

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
     if (resultCode == Activity.RESULT_OK)
     finish();
    }
  }

this code for the First Activity

  public long insertTruckinfo(String db_Truckmsg)
    {
    ContentValues cVal=new ContentValues();

    cVal.put(KEY_INFO,db_Truckmsg);


    return db.insert(TRUCKINFO_TABLE, null,cVal);

}


public Cursor getActivtaion()
{
     Cursor cursor =db.query(ACTIVATION_TABLE, new String[] {KEY_ID,KEY_ACTIVATION}, null,null, null, null, null);
     return cursor;
}


public Cursor getTruckinfo()
{
     Cursor cursor =db.query(TRUCKINFO_TABLE, new String[] {KEY_ID,KEY_INFO}, null,null, null, null, null);
     return cursor;
}

This is in DataBase class.

I think thi is helpful for u....

墨小墨 2024-12-05 04:57:00

使用广播接收器捕获所有传入消息。然而,初始化接收器的地点、时间和方式取决于您的应用程序。您可以在启动时或首次打开应用程序时执行此操作。

您必须扫描所有传入的短信,读取内容和号码,然后在应用程序内的某处检查并设置标志。

Use a broadcast receiver to capture all the incoming messages. However, where, when and how you initialize your receiver depends on your application. You can do it on boot, or on first open of your application etc.

You will have to scan all the incoming sms, read the content, and the number and check and set a flag somewhere inside your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文