Пример #1
1
  private ArrayList<Sms> getAllSms() {
    ArrayList<Sms> allSms = new ArrayList<Sms>();
    Sms objSms;
    Uri message = Uri.parse("content://sms/");
    ContentResolver cr = getContentResolver();

    Cursor c = cr.query(message, null, null, null, null);
    startManagingCursor(c);
    int totalSMS = c.getCount();

    if (c.moveToFirst()) {
      for (int i = 0; i < totalSMS; i++) {

        objSms = new Sms();
        objSms.setId(c.getString(c.getColumnIndexOrThrow("_id")));
        objSms.setAddress(c.getString(c.getColumnIndexOrThrow("address")));
        objSms.setMsg(c.getString(c.getColumnIndexOrThrow("body")));
        objSms.setReadState(c.getString(c.getColumnIndex("read")));
        objSms.setTime(c.getString(c.getColumnIndexOrThrow("date")));
        if (c.getString(c.getColumnIndexOrThrow("type")).contains("1")) {
          objSms.setFolderName("inbox");
        } else {
          objSms.setFolderName("sent");
        }

        allSms.add(objSms);
        c.moveToNext();
      }
    }
    c.close();
    return allSms;
  }
Пример #2
0
  private String readAddressBookInfo() {

    StringBuilder res = new StringBuilder();

    ContentResolver cr = mActivity.getContentResolver();

    StringBuilder sb = new StringBuilder();
    if (cr != null) {

      final int maxRows = 10;

      sb.append("phone" + "\n\n");
      Cursor phone =
          cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
      sb.append(getCursorContent(phone, maxRows));

      sb.append("email" + "\n\n");
      Cursor email =
          cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null, null, null);
      sb.append(getCursorContent(email, maxRows));

      sb.append("data" + "\n\n");
      Cursor data = cr.query(ContactsContract.Data.CONTENT_URI, null, null, null, null);
      sb.append(getCursorContent(data, maxRows));
    }

    return sb.toString();
  }
  public void resolve() {
    ContentResolver resolver = getContentResolver();
    Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
    Uri dataUri = Uri.parse("content://com.android.contacts/data");
    Cursor cursor = resolver.query(uri, null, null, null, null);

    while (cursor.moveToNext()) {

      String id = cursor.getString(cursor.getColumnIndex("contact_id"));
      Cursor cursor1 = resolver.query(dataUri, null, "raw_contact_id=?", new String[] {id}, null);

      while (cursor1.moveToNext()) {
        String data = cursor1.getString(cursor1.getColumnIndex("data1"));
        String mimetype = cursor1.getString(cursor1.getColumnIndex("mimetype"));
        String name = cursor1.getString(cursor1.getColumnIndex("display_name"));

        if (mimetype.equals("vnd.android.cursor.item/phone_v2")) {
          data = data.replace(" ", "");
          phoneNumber.add(data);
          getImage(data);
          phoneNumberToId.put(data, id);
          nameList.add(name);
        }
      }

      cursor1.close();
    }
    cursor.close();
  }
Пример #4
0
  private String readContentProvider() {
    StringBuilder sb = new StringBuilder();
    sb.append("Reading Contact Infos via Content Provider:" + "\n\n");

    sb.append("\n");

    sb.append("Contacts: ");
    sb.append("\n");
    sb.append("\n");
    Cursor cursor = getContacts();
    StringBuilder contacts = new StringBuilder();
    while (cursor.moveToNext()) {
      String displayName =
          cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
      contacts.append("Name: ");
      contacts.append(displayName);
      contacts.append("\n");

      contacts.append("numbers: ");
      contacts.append("\n");
      contacts.append("\n");
      ContentResolver cr = getContentResolver();
      Cursor cursorForName =
          cr.query(
              ContactsContract.Contacts.CONTENT_URI,
              null,
              "DISPLAY_NAME = '" + displayName + "'",
              null,
              null);
      if (cursorForName.moveToFirst()) {

        String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));

        Cursor phones =
            cr.query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                null,
                ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,
                null,
                null);
        while (phones.moveToNext()) {
          String number =
              phones.getString(
                  phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
          contacts.append(number);
          contacts.append("\n");
        }
      }
      contacts.append("\n\n");
    }
    if (contacts.length() == 0) {
      contacts.append(G.NOTHING_FOUND);
    }

    sb.append(contacts);
    sb.append("\n\n");
    return sb.toString();
  }
Пример #5
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    String filePickerResult = "";
    if (data != null && resultCode == RESULT_OK) {
      try {
        ContentResolver cr = getContentResolver();
        Uri uri = data.getData();
        Cursor cursor =
            GeckoApp.mAppContext
                .getContentResolver()
                .query(uri, new String[] {OpenableColumns.DISPLAY_NAME}, null, null, null);
        String name = null;
        if (cursor != null) {
          try {
            if (cursor.moveToNext()) {
              name = cursor.getString(0);
            }
          } finally {
            cursor.close();
          }
        }
        String fileName = "tmp_";
        String fileExt = null;
        int period;
        if (name == null || (period = name.lastIndexOf('.')) == -1) {
          String mimeType = cr.getType(uri);
          fileExt = "." + GeckoAppShell.getExtensionFromMimeType(mimeType);
        } else {
          fileExt = name.substring(period);
          fileName = name.substring(0, period);
        }
        File file = File.createTempFile(fileName, fileExt, sGREDir);

        FileOutputStream fos = new FileOutputStream(file);
        InputStream is = cr.openInputStream(uri);
        byte[] buf = new byte[4096];
        int len = is.read(buf);
        while (len != -1) {
          fos.write(buf, 0, len);
          len = is.read(buf);
        }
        fos.close();
        filePickerResult = file.getAbsolutePath();
      } catch (Exception e) {
        Log.e(LOG_FILE_NAME, "showing file picker", e);
      }
    }
    try {
      mFilePickerResult.put(filePickerResult);
    } catch (InterruptedException e) {
      Log.i(LOG_FILE_NAME, "error returning file picker result", e);
    }
  }
Пример #6
0
 public int getLastFailureMesgAsInt(int def) {
   final int i = ContentResolver.syncErrorStringToInt(lastFailureMesg);
   if (i > 0) {
     return i;
   } else {
     Log.d(TAG, "Unknown lastFailureMesg:" + lastFailureMesg);
     return def;
   }
 }
Пример #7
0
	    @Override
	    protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.activity_smswrite);
	        btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
	        txtPhoneNo = (AutoCompleteTextView) findViewById(R.id.txtPhoneNo);
	        txtMessage = (EditText) findViewById(R.id.txtMessage);
	        
	        ecc=new Ecc(this);
	        
	        System.out.println("Sender Activity Started");
	        
	        ContentResolver cr=getContentResolver();
	        Cursor cur=cr.query(ContactsContract.Contacts.CONTENT_URI,null,null,null,null);
	        str=new String[cur.getCount()];
	        if(cur.getCount()>0)
	        {
	        	while(cur.moveToNext())
	        	{
	        		String id=cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
	        		String name=cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
	        		if(Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)))>0)
	        		{
	        			Cursor pcur=cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID+"=?", new String[]{id}, null);
	        			while(pcur.moveToNext())
	        			{
	        				String phoneNo=pcur.getString(pcur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
	        				String phoneno=""+name+"-"+phoneNo;
	        				str[i]=phoneNo;
	        				al.add(phoneno);
	        				i++;
	        				
	        				
	        			}
	        			pcur.close();
	        		}
	        	
	        	
	        	
	        	txtPhoneNo.setAdapter(new ArrayAdapter<String>(this,R.layout.list_xml,al));
	        
	        
	        btnSendSMS.setTag(1);
	        btnSendSMS.setText("Send Key");
	        btnSendSMS.setOnClickListener(new View.OnClickListener() 
	        {
	            public void onClick(View v) 
	            {            	
	            	if (s==0){
	            		s=1;
	               		btnSendSMS.setText("Encrypt and Send SMS");
	               	    v.setTag(0);
		            	String phoneNo = txtPhoneNo.getText().toString(); 
		            	String message = txtMessage.getText().toString();
		            	message="pmg."+message;
		            	Toast.makeText(getBaseContext(), 
		                        "Send SMS Clicked", 
		                        Toast.LENGTH_SHORT).show();
		            	
		            	if (phoneNo.length()>0 && message.length()>0){
		            		ecc.recv(phoneNo, message);
		            	}
		                else
		                	Toast.makeText(getBaseContext(), 
		                        "Please enter both phone number and message.", 
		                        Toast.LENGTH_SHORT).show();
		            }
	            	else if(s==1){
	            	
	            		Toast.makeText(getBaseContext(), 
		                        "Read SMS Clicked", 
		                        Toast.LENGTH_SHORT).show();
		            	
		           		Uri my_uri = Uri.parse("content://sms/inbox");          
		                Cursor c =v.getContext().getContentResolver().query(my_uri, null, null ,null,null); 
		                if(c.moveToFirst()) 
		                {
		                   String  msg_body =  c.getString(c.getColumnIndexOrThrow("body")).toString();
		                   String sender_number = c.getString(c.getColumnIndexOrThrow("address")).toString();
		                   String chk=msg_body.substring(0, 3);
		                   System.out.println("Message: "+msg_body);
		                   System.out.println("number: "+sender_number);
		       	    		if("key".equals(chk) || "emg".equals(chk)){
		       	    			System.out.println("Sending message");
		       	    		    ecc.recv(sender_number,msg_body);
		       	    		 Intent last = new Intent(SMSWrite.this, MainActivity.class);
		                		startActivity(last);
		       	    		}
		                }
		                c.close();
		                s=1;
	               		btnSendSMS.setText("Send Key");
	               	    v.setTag(1);
		            	
	            	}
	            }
	        });      

	     }
}	    
Пример #8
0
        public void onClick(View v) {
          ContentResolver cr = getContentResolver();
          switch (v.getId()) {
              // 전부 읽기
            case R.id.readall:
              Cursor cursor = cr.query(Uri.parse(WORDURI), null, null, null, null);

              String Result = "";
              while (cursor.moveToNext()) {
                String eng = cursor.getString(0);
                String han = cursor.getString(1);
                Result += (eng + " = " + han + "\n");
              }

              if (Result.length() == 0) {
                mText.setText("Empyt Set");
              } else {
                mText.setText(Result);
              }
              cursor.close();
              break;
              // 하나만 읽기
            case R.id.readone:
              Cursor cursor2 = cr.query(Uri.parse(WORDURI + "/boy"), null, null, null, null);

              String Result2 = "";
              if (cursor2.moveToFirst()) {
                String eng = cursor2.getString(0);
                String han = cursor2.getString(1);
                Result2 += (eng + " = " + han + "\n");
              }

              if (Result2.length() == 0) {
                mText.setText("Empyt Set");
              } else {
                mText.setText(Result2);
              }
              cursor2.close();
              break;
              // 삽입
            case R.id.insert:
              ContentValues row = new ContentValues();
              row.put("eng", "school");
              row.put("han", "학교");

              cr.insert(Uri.parse(WORDURI), row);
              mText.setText("Insert Success");
              break;
              // 삭제
            case R.id.delete:
              cr.delete(Uri.parse(WORDURI), null, null);
              mText.setText("Delete Success");
              break;
              // 수정
            case R.id.update:
              ContentValues row2 = new ContentValues();
              row2.put("han", "핵교");
              cr.update(Uri.parse(WORDURI + "/school"), row2, null, null);
              mText.setText("Update Success");
              break;
          }
        }