在Android应用程序接收彩信应用程序、彩信、Android

2023-09-06 16:40:18 作者:偷看祢一秒

我已经开发一个Android应用程序和它的活动之一是:

I've to develop an android application and one of its activity is:

1,发现新的MMS消息检查2 - 获得发送方号码,如果是我想从它收到我的申请数量3充分利用MMS(TXT +图片)4-显示(文字+图片)在数据的ListView

1-Detecting New MMS messages 2- get Sender number to check if it is the number i want to receive from it in my application 3- Getting (txt + image) from MMS 4- showing (Txt + Image) data in ListView

好吧,我发现了一个code,可以帮助我在第二和第三个任务但我想它,测试它在我的手机,这是工作,但它并没有获取任何只是黑色界面!

well, I found a code that might help me in the 2nd and 3rd tasks but i tried it and test it on my mobile and it is work but it did not retrieve anything just black interface!!!

也许是我没看明白code的某些部分的问题,

Maybe the problem that i didn't understand some part of this code,

我写的每一个上述声明我的评论,我无法理解,请回答我的意见是,code里面,帮助我明白我失去了什么希望早起乌尔响应。和请予以明确。

I wrote my comment above each statement that I couldn't understand it please answer my comments that inside the code and help me to understand what i am missing hope to get ur responses early. and please be clear.

   import java.io.BufferedReader;
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.InputStreamReader;
   import java.text.MessageFormat;

   import android.app.Activity;
   import android.content.ContentResolver;
   import android.content.ContentValues;
   import android.content.Context;
   import android.database.Cursor;
   import android.graphics.Bitmap;
   import android.graphics.BitmapFactory;
   import android.net.Uri;
   import android.os.Bundle;
   import android.telephony.SmsMessage;
   import android.view.LayoutInflater;
   import android.view.View;
   import android.view.ViewGroup;
   import android.widget.ImageView;
   import android.widget.ListView;
   import android.widget.TextView;
     import android.app.Activity;
     import android.os.Bundle;

   public class MMSReceiverActivity extends Activity {

  private final Uri CONTENT_URI_PART = Uri.parse("content://mms/part");
   private static final String MSG_ID_STR = "mid=%1$s"; // I don't understand it

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Start Copying Code
    // I don't know how can I retrieve mms id
    long msg_id = this.getIntent().getLongExtra("msg_id", 0);
    // What's different between ViewGroup and ListView
    ViewGroup listview = (ViewGroup) findViewById(R.id.mmsdetaillist);
    // What's different between "content://mms/part" and "content://mms/"
    Cursor cursor = getContentResolver().query(CONTENT_URI_PART, null,
            String.format(MSG_ID_STR, msg_id), null, null);

    if (cursor.moveToFirst()) {
        do {
            // Why he puts partID
            String partId = cursor.getString(cursor.getColumnIndex("_id"));
            String type = cursor.getString(cursor.getColumnIndex("ct"));

            if ("text/plain".equals(type)) {
                String data = cursor.getString(cursor
                        .getColumnIndex("_data"));
                String body;
                // What's the different between if it's null or not all of
                // them will return (text)
                if (data != null) {
                    // implementation of this method below
                    body = getMmsText(partId);
                } else {
                    body = cursor.getString(cursor.getColumnIndex("text"));
                }

                // Why he declared it like this i mean why it didn't declare
                // like this findViewById (R.) etc
                TextView t = new TextView(this);
                t.setText(body);
                listview.addView(t);

                // Why here else ?? it should be only if because if MMS
                // contains Text + img : so it'll ignore the (else = img)
                // part !

            } else if ("image/jpeg".equals(type)
                    || "image/bmp".equals(type) || "image/gif".equals(type)
                    || "image/jpg".equals(type) || "image/png".equals(type)) {
                Bitmap bitmap = getMmsImage(partId);
                ImageView iv = new ImageView(this);
                iv.setImageBitmap(bitmap);
                listview.addView(iv);
            }
        } while (cursor.moveToNext());
    }
    cursor.close();

}

public String getMmsText(String id) {
    Uri partURI = Uri.parse("content://mms/part/" + id);
    InputStream is = null;
    StringBuilder sb = new StringBuilder();
    try {
        is = getContentResolver().openInputStream(partURI);
        if (is != null) {
            InputStreamReader isr = new InputStreamReader(is, "UTF-8");
            BufferedReader reader = new BufferedReader(isr);
            String temp = reader.readLine();
            while (temp != null) {
                sb.append(temp);
                temp = reader.readLine();
            }
        }
    } catch (IOException e) {
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
    return sb.toString();
}

public Bitmap getMmsImage(String _id) {
    Uri partURI = Uri.parse("content://mms/part/" + _id);
    InputStream is = null;
    Bitmap bitmap = null;
    try {
        is = getContentResolver().openInputStream(partURI);
        bitmap = BitmapFactory.decodeStream(is);
    } catch (IOException e) {
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
    return bitmap;
}
 }

请注意:每次我在发送或接收彩信我得到这个链接进行搜索,但是到现在为止我不明白这一点。

Note: everyTime i search on sending or receiving MMS i got this link , But until now i do not get it

我应该用回购和Git?什么是回购和Git?我为什么要在MMS使用?

Should i use repo and Git? and what is repo and Git? why should i use in MMS?

我应该使用它时,发送和接收彩信?如果是为什么?我可以用这个code

should i use it when send and receive MMS? if yes for why? can i use this code

 content://mms-sms/conversations

而不是回购和git?

instead of repo and git?

回购和Git

推荐答案

你的大多数问题都无关,与你的任务的一部分,MMS。大部分是标准的Java和/或Android,您需要承担这样的任务之前,了解。

Most of your questions have nothing to do with the MMS part of your assignment. Most of it is standard java and/or Android, that you need to understand before taking on such a task.

除此之外,SMS和MMS不直接支持并且主要undocumentet,所以它是非常难的工作。

Besides that, SMS and MMS are not directly supported and is mostly undocumentet, so it is very hard to work with.

我一直在短信和彩信玩了一圈,发现这些链接非常有用:

I have been playing around with sms and mms and found these links very useful:

如何在Android的阅读彩信数据?

http://groups.google.com/group/android-developers/browse_thread/thread/d0c15ec17c12af0e?fwc=1&pli=1

而现在,我在这,我还不如回答一些你有更多的简单问题:

And now that i'm at it, i might as well answer some of the more simple questions you have:

的ViewGroup和ListView

一个ViewGroup中是可以包含其他视图(的LinearLayout,RelativeLayout的...),其中一个ListView最意见父创建可滚动的项目列表的ViewGorup。

A ViewGroup is a superclass for most views that can contain other views (LinearLayout, RelativeLayout ...), where a ListView is "a ViewGorup that creates a list of scrollable items."

为什么他宣称它像这样我的意思是,它为什么没有宣布类似这样的findViewById(R.)等

findViewById使用。在这种情况下,他创建(而不是在一个XML文件中定义它),在运行时一个TextView并将其添加到ListView。

findViewById is used when you have an xml layout file, and want to reference a View in that layout. In this case he creates a TextView at runtime (Instead of defining it in an xml file) and adds it to the ListView.