Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 安卓信息中的可点击链接_Java_Android_Sms - Fatal编程技术网

Java 安卓信息中的可点击链接

Java 安卓信息中的可点击链接,java,android,sms,Java,Android,Sms,我是android新手,我需要你的帮助。 我试图在警报对话框中显示新传入消息的内容??并使消息中的内容“链接”可单击 这是我的留言活动 public class SecureMessagesActivity extends Activity implements OnClickListener, OnItemClickListener { public void onCreate(Bundle savedInstanceState) { super.onCre

我是android新手,我需要你的帮助。 我试图在警报对话框中显示新传入消息的内容??并使消息中的内容“链接”可单击

这是我的留言活动

  public class SecureMessagesActivity extends Activity implements OnClickListener,    OnItemClickListener
 {
  public void onCreate(Bundle savedInstanceState) 
   {
      super.onCreate(savedInstanceState);

    setTheme( android.R.style.Theme_Light );
     setContentView(R.layout.main);

    /**
     * You can also register your intent filter here.
     * And here is example how to do this.
     *
     * IntentFilter filter = new IntentFilter(    "android.provider.Telephony.SMS_RECEIVED" );
     * filter.setPriority( IntentFilter.SYSTEM_HIGH_PRIORITY );
     * registerReceiver( new SmsReceiver(), filter );
    **/

    this.findViewById( R.id.UpdateList ).setOnClickListener( this );
   }

    ArrayList<String> smsList = new ArrayList<String>();

  public void onItemClick( AdapterView<?> parent, View view, int pos, long id ) 
{
    try 
    {
        String[] splitted = smsList.get( pos ).split("\n"); 
        String sender = splitted[0];
        String encryptedData = "";
        for ( int i = 1; i < splitted.length; ++i )
        {
            encryptedData += splitted[i];
        }
        String data = sender + "\n" + StringCryptor.decrypt( new String(SmsReceiver.PASSWORD), encryptedData );
        Toast.makeText( this, data, Toast.LENGTH_SHORT ).show();
     } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
    }

   public void onClick( View v ) 
  {

    ContentResolver contentResolver = getContentResolver();
    Cursor cursor = contentResolver.query( Uri.parse( "content://sms/inbox" ), null, null, null, null);

    int indexBody = cursor.getColumnIndex( SmsReceiver.BODY );
    int indexAddr = cursor.getColumnIndex( SmsReceiver.ADDRESS );
    //int indexCont = cursor.getColumnIndex(SmsReceiver.READ);

    if ( indexBody < 0 || !cursor.moveToFirst() ) return;

    Builder builder = new AlertDialog.Builder(this); 
     builder.setTitle("Simple Alert");  
     builder.setMessage("This is simple alert box");
     builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            dialog.dismiss();  
        }

     });
    smsList.clear();

    do
    {
        String str = "Sender: " + cursor.getString( indexAddr ) + "\n" + cursor.getString( indexBody );
        smsList.add( str );
    }
    while( cursor.moveToNext() );


    ListView smsListView = (ListView) findViewById( R.id.SMSList );
    smsListView.setAdapter( new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, smsList) );
    smsListView.setOnItemClickListener( this );
 }

 public void DisplayAlert() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
     builder.setTitle("Simple Alert");  
     builder.setMessage(R.string.app_name);
     builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            dialog.dismiss();  

        }
         });
     AlertDialog alert = builder.create();  
     alert.show();          
}
公共类SecureMessagesActivity扩展活动实现OnClickListener、OnItemClickListener
{
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Light);
setContentView(R.layout.main);
/**
*你也可以在这里注册你的意图过滤器。
*这是一个如何做到这一点的例子。
*
*IntentFilter=newintentfilter(“android.provider.Telephony.SMS_RECEIVED”);
*filter.setPriority(IntentFilter.SYSTEM\u高优先级);
*registerReceiver(新的SmsReceiver(),过滤器);
**/
this.findviewbyd(R.id.UpdateList).setOnClickListener(this);
}
ArrayList smsList=新的ArrayList();
public void onItemClick(AdapterView父项、视图、整数位置、长id)
{
尝试
{
String[]splitted=smsList.get(pos.split)(“\n”);
字符串发送方=已拆分的[0];
字符串encryptedData=“”;
对于(int i=1;i
我的smsReceive.java

  public class SmsReceiver extends BroadcastReceiver 
    {
// All available column names in SMS table
     // [_id, thread_id, address, 
// person, date, protocol, read, 
// status, type, reply_path_present, 
// subject, body, service_center, 
// locked, error_code, seen]

public static final String SMS_EXTRA_NAME = "pdus";
public static final String SMS_URI = "content://sms";

public static final String ADDRESS = "address";
     public static final String PERSON = "person";
   public static final String DATE = "date";
   public static final String READ = "read";
   public static final String STATUS = "status";
   public static final String TYPE = "type";
   public static final String BODY = "body";
   public static final String SEEN = "seen";

   public static final int MESSAGE_TYPE_INBOX = 1;
    public static final int MESSAGE_TYPE_SENT = 2;

    public static final int MESSAGE_IS_NOT_READ = 0;
  public static final int MESSAGE_IS_READ = 1;

   public static final int MESSAGE_IS_NOT_SEEN = 0;
   public static final int MESSAGE_IS_SEEN = 1;

  // Change the password here or give a user possibility to change it
   public static final byte[] PASSWORD = new byte[]{ 0x20, 0x32, 0x34, 0x47, (byte) 0x84, 0x33, 0x58 };

 public void onReceive( Context context, Intent intent ) 
{
    // Get SMS map from Intent
     Bundle extras = intent.getExtras();

    String messages = "";

    if ( extras != null )
    {
        // Get received SMS array
        Object[] smsExtra = (Object[]) extras.get( SMS_EXTRA_NAME );

        // Get ContentResolver object for pushing encrypted SMS to incoming folder
        ContentResolver contentResolver = context.getContentResolver();

        for ( int i = 0; i < smsExtra.length; ++i )
        {
            SmsMessage sms = SmsMessage.createFromPdu((byte[])smsExtra[i]);

            String body = sms.getMessageBody().toString();
            String address = sms.getOriginatingAddress();

            messages += "SMS from " + address + " :\n";                    
            messages += body + "\n";



            // Here you can add any your code to work with incoming SMS
            // I added encrypting of all received SMS 

            putSmsToDatabase( contentResolver, sms );
        }


        // Display SMS message
      //  Toast.makeText( context, messages, Toast.LENGTH_SHORT ).show();
      }


}

private void putSmsToDatabase( ContentResolver contentResolver, SmsMessage sms )
{
    // Create SMS row
    ContentValues values = new ContentValues();
    values.put( ADDRESS, sms.getOriginatingAddress() );
    values.put( DATE, sms.getTimestampMillis() );
    values.put( READ, MESSAGE_IS_NOT_READ );
    values.put( STATUS, sms.getStatus() );
    values.put( TYPE, MESSAGE_TYPE_INBOX );
    values.put( SEEN, MESSAGE_IS_NOT_SEEN );
    try
    {
        String encryptedPassword = StringCryptor.encrypt( new String(PASSWORD), sms.getMessageBody().toString() ); 
        values.put( BODY, encryptedPassword );
    }
    catch ( Exception e ) 
    { 
        e.printStackTrace(); 
    }

    // Push row into the SMS table
    contentResolver.insert( Uri.parse( SMS_URI ), values );
}
    }
公共类SmsReceiver扩展了BroadcastReceiver
{
//SMS表中所有可用的列名
//[\u id,线程id,地址,
//人,日期,协议,阅读,
//状态、类型、回复路径,
//主体、主体、服务中心、,
//锁定,错误\u代码,已查看]
公共静态最终字符串SMS_EXTRA_NAME=“pdus”;
公共静态最终字符串SMS_URI=”content://sms";
公共静态最终字符串ADDRESS=“ADDRESS”;
公共静态最终字符串PERSON=“PERSON”;
公共静态最终字符串DATE=“DATE”;
公共静态最终字符串READ=“READ”;
公共静态最终字符串STATUS=“STATUS”;
公共静态最终字符串TYPE=“TYPE”;
公共静态最终字符串BODY=“BODY”;
公共静态最终字符串SEEN=“SEEN”;
公共静态最终int消息类型收件箱=1;
公共静态最终整型消息类型发送=2;
公共静态最终整型消息\u为\u非\u读取=0;
公共静态最终int消息_为_READ=1;
公共静态最终整型消息\u为\u未\u可见=0;
公共静态最终int消息_为_SEEN=1;
//在此处更改密码,或允许用户更改密码
公共静态最终字节[]密码=新字节[]{0x20、0x32、0x34、0x47,(字节)0x84、0x33、0x58};
公共void onReceive(上下文、意图)
{
//从Intent获取SMS映射
Bundle extras=intent.getExtras();
字符串消息=”;
如果(附加值!=null)
{
//获取接收到的SMS阵列
Object[]smsExtra=(Object[])extras.get(SMS\u EXTRA\u NAME);
//获取ContentResolver对象,用于将加密短信推送到传入文件夹
ContentResolver ContentResolver=context.getContentResolver();
对于(int i=0;i