【问题标题】:How to open up a specific SMS in android如何在android中打开特定的短信
【发布时间】:2010-11-27 14:05:35
【问题描述】:

有没有办法通过特定的 SMS 在 android 上打开消息传递活动?

【问题讨论】:

    标签: android sms android-intent


    【解决方案1】:

    threadId应该是你要查看的短信/彩信线程的id

    Intent defineIntent = new Intent(Intent.ACTION_VIEW); 
    defineIntent.setData(Uri.parse("content://mms-sms/conversations/"+threadId));  
    myActivity.startActivity(defineIntent);
    

    这是我找到的最简单的方法

    【讨论】:

    【解决方案2】:

    试试这个

    int req_thread_id;
    
    Uri mSmsinboxQueryUri = Uri.parse("content://sms"));
    Cursor cursor1 = getContentResolver().query(
                            mSmsinboxQueryUri,
                            new String[] { "_id", "thread_id", "address", "person", "date",
                                    "body", "type" }, null, null, null);
    
    startManagingCursor(cursor1);
    if (cursor1.getCount() > 0)
    {
    while (cursor1.moveToNext())
    {
    
    int thread_id = cursor1.getInt(1);
    String address; = cursor1.getString(cursor1
                                .getColumnIndex(columns[0]));
    if("your desired no".equals(address)
     req_thread_id = thread_id;
    }
    }
    Intent defineIntent = new Intent(Intent.ACTION_VIEW); 
    defineIntent.setData(Uri.parse("content://mms-sms/conversations/"+req_thread_id));  
    myActivity.startActivity(defineIntent);
    

    【讨论】:

      【解决方案3】:

      我从 Messaging 应用程序 (lines 311-315) 的源代码中挖掘了这个,所以我很确定它会起作用,但我没有任何经验。

      // threadId should be the id of the sms/mms thread you want to view
      long threadId = 0; 
      Intent i = new Intent("com.android.mms");
      i.setData(
              Uri.withAppendedPath(
                      i.getData(), Long.toString(threadId)
              )
      );
      i.setAction(Intent.ACTION_VIEW);
      

      【讨论】:

      • 我认为'thread id'与'sms id'不同?来自同一个人的不同短信(每个都有自己的 id)可以有相同的线程 id。
      【解决方案4】:

      此 sn-p 来自已接受答案中的评论。把方法贴在这里供后人参考。

      public static long findThreadIdFromAddress(Context context, String address) {
          if (address == null)
              return 0;
      
          String THREAD_RECIPIENT_QUERY = "recipient";
      
          Uri.Builder uriBuilder = THREAD_ID_CONTENT_URI.buildUpon();
          uriBuilder.appendQueryParameter(THREAD_RECIPIENT_QUERY, address);
      
          long threadId = 0;
      
          Cursor cursor = null;
          try {
      
              cursor = context.getContentResolver().query(
                      uriBuilder.build(),
                      new String[] { Contacts._ID },
                      null, null, null);
      
              if (cursor != null && cursor.moveToFirst()) {
                  threadId = cursor.getLong(0);
              }
          } finally {
              if (cursor != null) {
                  cursor.close();
              }
          }
          return threadId;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-25
        • 2015-08-10
        • 1970-01-01
        • 1970-01-01
        • 2020-01-08
        • 1970-01-01
        相关资源
        最近更新 更多