android系统App调用
telephony call
private void startPhoneIntent() { Intent phoneIntent = new Intent("android.intent.action.CALL", Uri.parse("tel:" + (number1.getText().length() == 0 ? number1.getHint() : number1.getText()))); Log.i(TAG, "onItemClick code="); startActivity(phoneIntent); } private void startPhoneBinder() { Method method; try { method = Class.forName("android.os.ServiceManager").getMethod( "getService", String.class); method.setAccessible(true); IBinder binder = (IBinder) method.invoke(null, new Object[] { getActivity().TELEPHONY_SERVICE }); ITelephony phone = ITelephony.Stub.asInterface(binder); phone.call("com.htc.apppermissionchecktool", (number1.getText() .length() == 0 ? number1.getHint() : number1.getText()) .toString()); return; } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Toast.makeText(mContext, "Fail to call Phone Binder", Toast.LENGTH_SHORT).show(); }
SMS
private void startSmsManager() { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("10086", null, "100", null, null); } private void startSendMultiPartText() { String msg = "SMS content: abcd20igksdkfkfdsdfsdfsd40ldjsdfjsdlkfjsdlklxdjfkddsdf70abcdefgh80"; SmsManager smsManager = SmsManager.getDefault(); PendingIntent sentIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(), 0); if (msg.length() > 70) { ArrayList<String> contents = smsManager.divideMessage(msg); smsManager.sendMultipartTextMessage("10086", null, contents, null, null); } else { smsManager.sendTextMessage("10086", null, msg, sentIntent, null); } }
//需要导入许多google源码 private void startSendText() { Log.i(TAG, "onCreate onClick"); Method method; try { method = Class.forName("android.os.ServiceManager").getMethod( "getService", String.class); method.setAccessible(true); IBinder binder = (IBinder) method.invoke(null, new Object[] { "isms" }); ISms simISms = ISms.Stub.asInterface(binder); // SMS(simISms); simISms.sendText("com.htc.apppermissionchecktool", "10086", null, "100", null, null); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
//需要导入许多google源码 private void startSendData() { Method method; try { method = Class.forName("android.os.ServiceManager").getMethod( "getService", String.class); method.setAccessible(true); IBinder binder = (IBinder) method.invoke(null, new Object[] { "isms" }); ISms simISms = ISms.Stub.asInterface(binder); String szText = "haha"; byte[] bytes = szText.getBytes(); simISms.sendData("com.htc.apppermissionchecktool", "10086", "10010", 80, bytes, null, null); Toast.makeText(getActivity(), "Success to sendData()", Toast.LENGTH_SHORT).show(); return; } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NullPointerException e) { Log.w(TAG, "抱歉,手机系统不支持这种方式发送短信"); e.printStackTrace(); } Toast.makeText(getActivity(), "Fail to sendData()", Toast.LENGTH_SHORT) .show(); }
MMS
private void startMmsIntent() { String path = Environment.getExternalStorageDirectory() .getAbsolutePath() + "/Pictures/dog.jpg"; Uri uri = Uri.parse(path); Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra("address", "10086"); intent.putExtra("sms_body", "这里输入信息内容"); // 彩信附件 intent.putExtra(Intent.EXTRA_STREAM, uri); // 文件类型 intent.setType("image/png"); startActivity(intent); }
camera
private void startImageCapture() { Intent intent = new Intent(); intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); intent.addCategory(Intent.CATEGORY_DEFAULT); // mImagePath = ROOT_PATH + "/DCIM/100MEDIA/" + // System.currentTimeMillis() + ".jpg"; mImagePath = ROOT_PATH + "/DCIM/100MEDIA/"; File file = new File(mImagePath); if (file.exists()) { file.delete(); } Uri uri = Uri.fromFile(file); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(intent, ACTIVITY_REQUEST_IMAGE_CAPTURE); } private void startVideoCapture() { Intent intent = new Intent(); intent.setAction("android.media.action.VIDEO_CAPTURE"); intent.addCategory("android.intent.category.DEFAULT"); // mVideoPath = ROOT_PATH + "/DCIM/100MEDIA/" + // System.currentTimeMillis() + ".mp4"; mVideoPath = ROOT_PATH + "/DCIM/100MEDIA/"; File file = new File(mVideoPath); if (file.exists()) { file.delete(); } Uri uri = Uri.fromFile(file); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(intent, ACTIVITY_REQUEST_VIDEO_CAPTURE); }
contacts
private void startReadContacts(int activityRequestCode) { // ContentResolver cr = getActivity().getContentResolver(); // Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, // null, null, null); // cursor.close(); Intent intent = new Intent(Intent.ACTION_PICK); intent.setType("vnd.android.cursor.dir/phone"); startActivityForResult(intent, activityRequestCode); } private void startDeleteContacts() { int result = -1; try { // Uri.parse("content://com.android.contacts/raw_contacts") result = getActivity().getContentResolver().delete( Uri.parse("content://com.android.contacts/raw_contacts"), Contacts.DISPLAY_NAME + "=?", new String[] { "10086" }); Log.d(TAG, "Delete records: " + result); } catch (Exception e) { Log.e(TAG, e.getMessage()); } Log.d(TAG, "startDeleteContacts() result:" + result); if (result >= 1) { Toast.makeText(mContext, "Success to delete contact: 10086", Toast.LENGTH_LONG).show(); startReadContacts(ACTIVITY_REQUEST_DELETE_CONTACTS); } else { Toast.makeText(mContext, "Fail to delete contact: 10086", Toast.LENGTH_LONG).show(); } } private void startModifyContacts() { Uri uri = null; try { ContentValues values = new ContentValues(); Uri rawContactUri = getActivity().getContentResolver().insert( RawContacts.CONTENT_URI, values); long rawContactId = ContentUris.parseId(rawContactUri); values.clear(); values.put(Data.RAW_CONTACT_ID, rawContactId); values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE); values.put(Phone.NUMBER, "10086"); values.put(Phone.TYPE, Phone.TYPE_MOBILE); uri = getActivity().getContentResolver().insert( android.provider.ContactsContract.Data.CONTENT_URI, values); } catch (Exception e) { Log.e(TAG, e.getMessage()); } if (uri == null || TextUtils.equals("content://com.android.contacts/data/0", uri.toString())) { Toast.makeText(mContext, "Fail to modify Contacts", Toast.LENGTH_LONG).show(); } else { Log.d(TAG, "URI:" + uri.toString()); Toast.makeText(mContext, "Success to add new contact: 10086", Toast.LENGTH_LONG).show(); startReadContacts(ACTIVITY_REQUEST_MODIFY_CONTACTS); } }
CallLog
private void startReadPhoneData() { // ContentResolver cr = getActivity().getContentResolver(); // Cursor cursor = cr.query(CallLog.Calls.CONTENT_URI, new String[] { // CallLog.Calls.NUMBER, // CallLog.Calls.CACHED_NAME, CallLog.Calls.TYPE, CallLog.Calls.DATE }, // null, null, // CallLog.Calls.DEFAULT_SORT_ORDER); Intent intent = new Intent(); intent.setAction(Intent.ACTION_CALL_BUTTON); // startActivityForResult(intent, activityRequestCode); startActivity(intent); } private void startDeletePhoneData() { int result = 0; try { // getActivity().getContentResolver().delete(CallLog.Calls.CONTENT_URI, // CallLog.Calls.NUMBER + "=?", new String[] { "10086" }); result = getActivity().getContentResolver().delete( CallLog.Calls.CONTENT_URI, null, null); } catch (Exception e) { Log.e(TAG, e.getMessage()); } if (result > 0) { Toast.makeText(mContext, "Success to delete calllog", Toast.LENGTH_LONG).show(); startReadPhoneData(); } else { Toast.makeText(mContext, "Fail to delete calllog", Toast.LENGTH_LONG).show(); } } private void startModifyPhoneData() { ContentValues content = new ContentValues(); content.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE); content.put(CallLog.Calls.NUMBER, Long.toString(phoneNumber++)); content.put(CallLog.Calls.DATE, System.currentTimeMillis()); content.put(CallLog.Calls.NEW, "1");// 0已看1未看 content.put(CallLog.Calls.TYPE, 1); Uri uri = null; try { // getActivity().getContentResolver().update(CallLog.Calls.CONTENT_URI, // content, // CallLog.Calls.NUMBER + "=?", new String[] { "13078943473" }); uri = getActivity().getContentResolver().insert( CallLog.Calls.CONTENT_URI, content); } catch (Exception e) { Log.e(TAG, e.getMessage()); } if (uri == null || TextUtils.equals("content://call_log/calls/0", uri.toString())) { Toast.makeText(mContext, "Fail to add calllog", Toast.LENGTH_LONG) .show(); } else { Toast.makeText(mContext, "Success to add calllog", Toast.LENGTH_LONG).show(); startReadPhoneData(); } }
SMS
private void startReadSms() { // String[] projection = new String[] { "_id", "address", "person", // "body", "date", "type" }; // ContentResolver cr = getActivity().getContentResolver(); // Cursor cusor = cr.query(Uri.parse("content://sms/"), projection, // null, null, "date desc"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); intent.setData(Uri.parse("content://mms-sms/conversations/10086")); startActivity(intent); } private void startModifySms() { ContentValues values = new ContentValues(); values.put("address", "10086"); values.put("type", "1"); values.put("read", "0"); values.put("body", "使用ApiTestTool工具,代码写入短信"); values.put("date", new Date(14644546).getTime()); values.put("person", "test"); Uri uri = null; try { uri = getActivity().getContentResolver().insert( Uri.parse("content://sms/inbox"), values); } catch (Exception e) { Log.e(TAG, e.getMessage()); } if (uri == null || TextUtils.equals("content://sms/inbox/0", uri.toString())) { Toast.makeText(mContext, "Fail to add SMS:10086", Toast.LENGTH_LONG) .show(); } else { Toast.makeText(mContext, "Success to add SMS:10086", Toast.LENGTH_LONG).show(); startReadSms(); } } private void startDeleteSms() { ContentResolver contentResolver = getActivity().getContentResolver(); Uri uriMms = Uri.parse("content://sms"); try { int record = 0; record = contentResolver.delete(uriMms, null, null); Log.d(TAG, "startDeleteSms() record:" + record); if (record < 1) { Toast.makeText(mContext, "Fail to delete SMS", Toast.LENGTH_LONG).show(); return; } } catch (Exception e) { Toast.makeText(mContext, "Fail to delete SMS", Toast.LENGTH_LONG) .show(); e.printStackTrace(); return; } Toast.makeText(mContext, "Success to delete SMS", Toast.LENGTH_LONG) .show(); startReadSms(); }

浙公网安备 33010602011771号