2013-06-13 09:21:09 yunlong782 阅读数 586
  • Android底层技术:HAL驱动开发

    本课程提供开发者学习Android底层的HAL(硬件抽象层)的开发方法和技术。HAL所在的位置是介于Android系统服务与Linux内核之间,HAL Driver是以library形式出现,给HAL Stub调用,供Android System架构者调用。而HAL Stub则是google设计出来的,保护硬件厂商的硬件驱动。

    17825 人正在学习 去看看 高煥堂
 

android调用系统功能

分类: android 365人阅读 评论(1) 收藏 举报

开发中的功能需要直接跳转到拨号、联系人、短信界面等等,查找了很多资料,自己整理了一下。

首先,我们先看拨号界面,代码如下:

Intent intent =new Intent();
intent.setAction("android.intent.action.CALL_BUTTON");
startActivity(intent);
Uri uri = Uri.parse("tel:xxxxxx");
Intent intent = new Intent(Intent.ACTION_DIAL, uri);
startActivity(intent);
两者都行   

但是如果是跳转到应用,使用一下代码:

Intent intent= new Intent("android.intent.action.DIAL");
intent.setClassName("com.android.contacts","com.android.contacts.DialtactsActivity");
到通话记录界面:

Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL_BUTTON);
startActivity(intent);  

到联系人界面:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Contacts.People.CONTENT_URI);
startActivity(intent);
同理,到应用:

Intent intent= new Intent("com.android.contacts.action.LIST_STREQUENT");
intent.setClassName("com.android.contacts","com.android.contacts.DialtactsActivity");  

调用联系人界面:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setData(Contacts.People.CONTENT_URI);
startActivity(intent);   

插入联系人

Intent intent=new Intent(Intent.ACTION_EDIT,
Uri.parse("content://com.android.contacts/contacts/"+"1"));
startActivity(intent);

到联系人列表界面      

Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
            intent.setType("vnd.android.cursor.item/person");
            intent.setType("vnd.android.cursor.item/contact");
            intent.setType("vnd.android.cursor.item/raw_contact");
            intent.putExtra(android.provider.ContactsContract.Intents.Insert.NAME, name);
            intent.putExtra(android.provider.ContactsContract.Intents.Insert.COMPANY,company);
            intent.putExtra(android.provider.ContactsContract.Intents.Insert.PHONE, tel);
            intent.putExtra(android.provider.ContactsContract.Intents.Insert.PHONE_TYPE, 3);  

到短信界面:

Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setType("vnd.android-dir/mms-sms");
//              intent.setData(Uri.parse("content://mms-sms/conversations/"));//此为号码
                startActivity(intent);
到应用:

Intent intent = new Intent("android.intent.action.CONVERSATION");
startActivity(intent);  

以下是在网上找到的其他方法:

1.从google搜索内容 

Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,"searchString")
startActivity(intent);   

2.浏览网页 

Uri uri = Uri.parse("http://www.google.com");
Intent it   = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);   

3.显示地图 

Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent it = new Intent(Intent.Action_VIEW,uri);
startActivity(it);   

4.路径规划 

Uri uri = Uri.parse("http://maps.google.com/maps?
f=dsaddr=startLat startLng&daddr=endLat endLng&hl=en");
Intent it = new Intent(Intent.ACTION_VIEW,URI);
startActivity(it);  

5.拨打电话 

Uri uri = Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);
和

uri = Uri.parse("tel:"+number);
                intent = new Intent(Intent.ACTION_CALL,uri);
                startActivity(intent);   

其中不同自己试验一下就知道了。 

6.调用发短信的程序 

Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "The SMS text");
it.setType("vnd.android-dir/mms-sms");
startActivity(it);  

和 

uri = Uri.parse("smsto:"+要发送短信的对方的number);
                intent = new Intent(Intent.ACTION_SENDTO,uri);
                startActivity(intent);
和

mIntent = new Intent(Intent.ACTION_VIEW);
        mIntent.putExtra("address", c.getString(c.getColumnIndex(column)));
        mIntent.setType("vnd.android-dir/mms-sms");
        startActivity(mIntent);    

7.发送短信 

Uri uri = Uri.parse("smsto:0800000123");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
String body="this is sms demo";
Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null));
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, true);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, true);
startActivity(mmsintent);

8.发送彩信 

Uri uri = Uri.parse("content://media/external/images/media/23");
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra("sms_body", "some text");
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType("image/png");
startActivity(it);
StringBuilder sb = new StringBuilder();
sb.append("file://");
sb.append(fd.getAbsoluteFile());
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number, null));
// Below extra datas are all optional.
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI, sb.toString());
intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, composeMode);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, exitOnSent);
startActivity(intent);   

9.发送Email 

Uri uri = Uri.parse("mailto:xxx@abc.com");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(it);
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");
it.putExtra(Intent.EXTRA_TEXT, "The email body text");
it.setType("text/plain");
startActivity(Intent.createChooser(it, "Choose Email Client"));
Intent it=new Intent(Intent.ACTION_SEND);
String[] tos={"me@abc.com"};
String[] ccs={"you@abc.com"};
it.putExtra(Intent.EXTRA_EMAIL, tos);
it.putExtra(Intent.EXTRA_CC, ccs);
it.putExtra(Intent.EXTRA_TEXT, "The email body text");
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.setType("message/rfc822");
startActivity(Intent.createChooser(it, "Choose Email Client"));     

Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
sendIntent.setType("audio/mp3");
startActivity(Intent.createChooser(it, "Choose Email Client"));   

10.播放多媒体   

Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);   

11.uninstall apk 

Uri uri = Uri.fromParts("package", strPackageName, null);
Intent it = new Intent(Intent.ACTION_DELETE, uri);
startActivity(it);   


12.install apk 

Uri installUri = Uri.fromParts("package", "xxx", null);
returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);   

13. 打开照相机 

<1>Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
          this.sendBroadcast(i);
    <2>long dateTaken = System.currentTimeMillis();
         String name = createName(dateTaken) + ".jpg";
         fileName = folder + name;
         ContentValues values = new ContentValues();
         values.put(Images.Media.TITLE, fileName);
         values.put("_data", fileName);
         values.put(Images.Media.PICASA_ID, fileName);
         values.put(Images.Media.DISPLAY_NAME, fileName);
         values.put(Images.Media.DESCRIPTION, fileName);
         values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);
         Uri photoUri = getContentResolver().insert(
                   MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);   

         Intent inttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
         inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
         startActivityForResult(inttPhoto, 10);   

14.从gallery选取图片 

Intent i = new Intent();
        i.setType("image/*");
        i.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(i, 11);   

15. 打开录音机 

Intent mi = new Intent(Media.RECORD_SOUND_ACTION);
         startActivity(mi);
16.显示应用详细列表      

Uri uri = Uri.parse("market://details?id=app_id");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where app_id is the application ID, find the ID
//by clicking on your application on Market home
//page, and notice the ID from the address bar

刚才找app id未果,结果发现用package name
也可以 Uri uri = Uri.parse("market://details?id=");
这个简单多了 

17寻找应用      

Uri uri = Uri.parse("market://search?q=pname:pkg_name");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where pkg_name is the full package path for an application
18打开联系人列表 

<1>
         Intent i = new Intent();
         i.setAction(Intent.ACTION_GET_CONTENT);
         i.setType("vnd.android.cursor.item/phone");
         startActivityForResult(i, REQUEST_TEXT);   

<2>
         Uri uri = Uri.parse("content://contacts/people");
         Intent it = new Intent(Intent.ACTION_PICK, uri);
         startActivityForResult(it, REQUEST_TEXT);   

19 打开另一程序 

Intent i = new Intent();
         ComponentName cn = new ComponentName("com.yellowbook.android2",
                   "com.yellowbook.android2.AndroidSearch");
         i.setComponent(cn);
         i.setAction("android.intent.action.MAIN");
         startActivityForResult(i, RESULT_OK);
20 添加到短信收件箱
ContentValues cv = new ContentValues();
                cv.put("type", "1");
cv.put("address","短信地址");
cv.put("body", "短信内容");
getContentResolver().insert(Uri.parse("content://sms/inbox"), cv);   

21 从sim卡或者联系人中查询
Cursor cursor;
        Uri uri;
        if (type == 1) {
            Intent intent = new Intent();
            intent.setData(Uri.parse("content://icc/adn"));
            uri = intent.getData();
        } else
            uri = People.CONTENT_URI;  

        cursor = activity.getContentResolver().query(uri, null, null, null, null);
while (cursor.moveToNext()) {
 int peopleId = cursor.getColumnIndex(People._ID);
 int nameId = cursor.getColumnIndex(People.NAME);
 int phoneId = cursor.getColumnIndex(People.NUMBER);} 

查看某个联系人,当然这里是ACTION_VIEW,
如果为选择并返回action改为ACTION_PICK,当然处理intent时返回需要用到 startActivityforResult 

Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, ID);
//最后的ID参数为联系人Provider中的数据库BaseID,即哪一行 

Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW);
 intent.setData(personUri); startActivity(intent); 

22 删除
uri = ContentUris.withAppendedId(People.CONTENT_URI, 联系人id);
        int count = activity.getContentResolver().delete(uri, null, null);  

23 添加到联系人:
ContentValues cv = new ContentValues();
ArrayList operationList = new ArrayList();
ContentProviderOperation.Builder builder =
 ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
                    builder.withValues(cv);
                    operationList.add(builder.build());
                    builder = ContentProviderOperation.newInsert(Data.CONTENT_URI);
                    builder.withValueBackReference(StructuredName.RAW_CONTACT_ID, 0);
                    builder.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
                    builder.withValue(StructuredName.DISPLAY_NAME, "自定义联系人名");
                    operationList.add(builder.build());
                    builder = ContentProviderOperation.newInsert(Data.CONTENT_URI);
                    builder.withValueBackReference(Phone.RAW_CONTACT_ID, 0);
                    builder.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
                    builder.withValue(Phone.NUMBER, "联系人的phonenumber");
                    builder.withValue(Data.IS_PRIMARY, 1);
                    operationList.add(builder.build());
                    try {
                        getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList);
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    } catch (OperationApplicationException e) {
                        e.printStackTrace();
                    }
 23 选择一个图片 

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
 intent.setType("image/*");
 startActivityForResult(intent, 0);   

24 调用Android设备的照相机,并设置拍照后存放位置

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
 Uri.fromFile(new File(Environment .getExternalStorageDirectory().getAbsolutePath()+"/cwj",
 android123 + ".jpg")));
//存放位置为sdcard卡上cwj文件夹,文件名为android123.jpg格式
startActivityForResult(intent, 0);  

25 在market上搜索指定package name,比如搜索com.android123.cwj的写法如下 

Uri uri = Uri.parse("market://search?q=pname:com.android123.cwj");
 Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent);  

26获取文件信息,并使用相对应软件打开

view plain
private void openFile(File f)
 {
   Intent intent = new Intent();
   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   intent.setAction(android.content.Intent.ACTION_VIEW);
   String type = getMIMEType(f);
   intent.setDataAndType(Uri.fromFile(f), type);
   startActivity(intent);
 }    

 private String getMIMEType(File f){
   String end = f
       .getName()
       .substring(f.getName().lastIndexOf(".") + 1,
           f.getName().length()).toLowerCase();
   String type = "";
   if (end.equals("mp3") || end.equals("aac") || end.equals("aac")
       || end.equals("amr") || end.equals("mpeg")
       || end.equals("mp4"))
   {
     type = "audio";
   } else if (end.equals("jpg") || end.equals("gif")
       || end.equals("png") || end.equals("jpeg"))
   {
     type = "image";
   } else
   {
     type = "*";
   }
   type += "/*";
   return type;

2017-08-23 09:04:42 zhangmingziliao 阅读数 241
  • Android底层技术:HAL驱动开发

    本课程提供开发者学习Android底层的HAL(硬件抽象层)的开发方法和技术。HAL所在的位置是介于Android系统服务与Linux内核之间,HAL Driver是以library形式出现,给HAL Stub调用,供Android System架构者调用。而HAL Stub则是google设计出来的,保护硬件厂商的硬件驱动。

    17825 人正在学习 去看看 高煥堂

收集调用Android系统常用的Api使用方法大全:

1:android  安装应用方法(兼容 Android7.0)

/**
     * 安装App(支持7.0)
     *
     * @param context  上下文
     * @param filePath 文件路径
     */
    public static void installApp(Context context, String filePath) {
        //apk文件的本地路径
        File apkfile = new File(filePath);
        if (!apkfile.exists()) {
            return null;
        }
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri contentUri = RxFileTool.getUriForFile(context, apkfile);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION |     
            Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        }
        intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
        context.startActivity(intent);
    }

2:静默安装App

    public static boolean installAppSilent(Context context, String filePath) {
        File file = RxFileTool.getFileByPath(filePath);
        if (!RxFileTool.isFileExists(file)) return false;
        String command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib pm install " + filePath;
        RxShellTool.CommandResult commandResult = RxShellTool.execCmd(command, !isSystemApp(context), true);
        return commandResult.successMsg != null && commandResult.successMsg.toLowerCase().contains("success");
    }


/**
     * 返回的命令结果
     */
    public static class CommandResult {

        /**
         * 结果码
         **/
        public int result;
        /**
         * 成功的信息
         **/
        public String successMsg;
        /**
         * 错误信息
         **/
        public String errorMsg;

        public CommandResult(int result) {
            this.result = result;
        }

        public CommandResult(int result, String successMsg, String errorMsg) {
            this.result = result;
            this.successMsg = successMsg;
            this.errorMsg = errorMsg;
        }
    }


/**
     * 是否是在root下执行命令
     *
     * @param commands        命令数组
     * @param isRoot          是否root
     * @param isNeedResultMsg 是否需要结果消息
     * @return CommandResult
     */
    public static CommandResult execCmd(String[] commands, boolean isRoot, boolean isNeedResultMsg) {
        int result = -1;
        if (commands == null || commands.length == 0) {
            return new CommandResult(result, null, null);
        }
        Process process = null;
        BufferedReader successResult = null;
        BufferedReader errorResult = null;
        StringBuilder successMsg = null;
        StringBuilder errorMsg = null;
        DataOutputStream os = null;
        try {
            process = Runtime.getRuntime().exec(isRoot ? COMMAND_SU : COMMAND_SH);
            os = new DataOutputStream(process.getOutputStream());
            for (String command : commands) {
                if (command == null) {
                    continue;
                }
                os.write(command.getBytes());
                os.writeBytes(COMMAND_LINE_END);
                os.flush();
            }
            os.writeBytes(COMMAND_EXIT);
            os.flush();

            result = process.waitFor();
            if (isNeedResultMsg) {
                successMsg = new StringBuilder();
                errorMsg = new StringBuilder();
                successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
                errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                String s;
                while ((s = successResult.readLine()) != null) {
                    successMsg.append(s);
                }
                while ((s = errorResult.readLine()) != null) {
                    errorMsg.append(s);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (os != null) {
                    os.close();
                }
                if (successResult != null) {
                    successResult.close();
                }
                if (errorResult != null) {
                    errorResult.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            if (process != null) {
                process.destroy();
            }
        }
        return new CommandResult(result, successMsg == null ? null : successMsg.toString(), errorMsg == null ? null
                : errorMsg.toString());
    }

3:判断App是否是系统应用

/**
     * 判断App是否是系统应用
     *
     * @param context     上下文
     * @param packageName 包名
     * @return {@code true}: 是<br>{@code false}: 否
     */
    public static boolean isSystemApp(Context context, String packageName) {
        if (RxDataTool.isNullString(packageName)) return false;
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
            return ai != null && (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    }

 

4:获取APP  icon图标

/**
     * 获取App图标
     *
     * @param context     上下文
     * @param packageName 包名
     * @return App图标
     */
    public static Drawable getAppIcon(Context context, String packageName) {
        if (RxDataTool.isNullString(packageName)) return null;
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(packageName, 0);
            return pi == null ? null : pi.applicationInfo.loadIcon(pm);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }

5:获取APP版本

/**
     * 获取App版本码
     *
     * @param context     上下文
     * @param packageName 包名
     * @return App版本码
     */
    public static int getAppVersionCode(Context context, String packageName) {
        if (packageName.equals("")) return -1;
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(packageName, 0);
            return pi == null ? -1 : pi.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return -1;
        }
    }

6:复制文本到剪贴板

    public static void copyText(Context context,CharSequence text) {
        ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("text", text));
    }

7:获取剪贴板的文本

    public static CharSequence getText(Context context) {
        ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = clipboard.getPrimaryClip();
        if (clip != null && clip.getItemCount() > 0) {
            return clip.getItemAt(0).coerceToText(context);
        }
        return null;
    }

8:获取手机唯一标识序列号

    public static String getUniqueSerialNumber() {
        String phoneName = Build.MODEL;// Galaxy nexus 品牌类型
        String manuFacturer = Build.MANUFACTURER;//samsung 品牌
        Log.d("详细序列号", manuFacturer + "-" + phoneName + "-" + getSerialNumber());
        return manuFacturer + "-" + phoneName + "-" + getSerialNumber();
    }

9:IMEI (唯一标识序列号)

    /**
     * IMEI (唯一标识序列号)
     * <p>需与{@link #isPhone(Context)}一起使用</p>
     * <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
     *
     * @param context 上下文
     * @return IMEI
     */
    public static String getIMEI(Context context) {
        String deviceId;
        if (isPhone(context)) {
            deviceId = getDeviceIdIMEI(context);
        } else {
            deviceId = getAndroidId(context);
        }
        return deviceId;
    }

10:获取Android手机号

    public static String getLine1Number(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return tm.getLine1Number();
    }

11:获取当前使用的网络类型

    public static int getNetworkType(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return tm.getNetworkType();
    }

12:获取设备厂商,如Xiaomi

    /**
     * 获取设备厂商,如Xiaomi
     *
     * @return 设备厂商
     */
    public static String getBuildMANUFACTURER() {
        return Build.MANUFACTURER;// samsung 品牌
    }

13:获取设备MAC地址

    /**
     * 获取设备MAC地址
     * <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>}</p>
     *
     * @param context 上下文
     * @return MAC地址
     */
    public static String getMacAddress(Context context) {
        WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = wifi.getConnectionInfo();
        if (info != null) {
            String macAddress = info.getMacAddress();
            if (macAddress != null) {
                return macAddress.replace(":", "");
            }
        }
        return null;
    }

14:判断设备是否是手机

    /**
     * 判断设备是否是手机
     *
     * @param context 上下文
     * @return {@code true}: 是<br>{@code false}: 否
     */
    public static boolean isPhone(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
    }

15:获取手机状态信息

public static String getPhoneStatus(Context context) {
        TelephonyManager tm = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        String str = "";
        str += "DeviceId(IMEI) = " + getDeviceIdIMEI(context) + "\n";
        str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
        str += "Line1Number = " + tm.getLine1Number() + "\n";
        str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
        str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
        str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
        str += "NetworkType = " + tm.getNetworkType() + "\n";
        str += "honeType = " + tm.getPhoneType() + "\n";
        str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
        str += "SimOperator = " + tm.getSimOperator() + "\n";
        str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
        str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
        str += "SimState = " + tm.getSimState() + "\n";
        str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
        str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
        return str;
    }

16:发送短信

   /**
     * 发送短信
     *
     * @param context     上下文
     * @param phoneNumber 电话号码
     * @param content     内容
     */
    public static void sendSms(Context context, String phoneNumber, String content) {
        Uri uri = Uri.parse("smsto:" + (RxDataTool.isNullString(phoneNumber) ? "" : phoneNumber));
        Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
        intent.putExtra("sms_body", RxDataTool.isNullString(content) ? "" : content);
        context.startActivity(intent);
    }

17:获取当前屏幕截图,包含状态栏

    /**
     * 获取当前屏幕截图,包含状态栏
     *
     * @param activity activity
     * @return Bitmap
     */
    public static Bitmap captureWithStatusBar(Activity activity) {
        View view = activity.getWindow().getDecorView();
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        Bitmap bmp = view.getDrawingCache();
        int width = getScreenWidth(activity);
        int height = getScreenHeight(activity);
        Bitmap ret = Bitmap.createBitmap(bmp, 0, 0, width, height);
        view.destroyDrawingCache();
        return ret;
    }

18:按采样大小压缩

 /**
     * 按采样大小压缩
     *
     * @param src        源图片
     * @param sampleSize 采样率大小
     * @param recycle    是否回收
     * @return 按采样率压缩后的图片
     */
    public static Bitmap compressBySampleSize(Bitmap src, int sampleSize, boolean recycle) {
        if (isEmptyBitmap(src)) return null;
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = sampleSize;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        src.compress(CompressFormat.JPEG, 100, baos);
        byte[] bytes = baos.toByteArray();
        if (recycle && !src.isRecycled()) src.recycle();
        return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
    }

19:获取网络类型

    public static int getNetWorkType(Context context) {
        // 获取ConnectivityManager
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo ni = cm.getActiveNetworkInfo();// 获取当前网络状态

        int netType = NETWORK_NO;

        if (ni != null && ni.isConnectedOrConnecting()) {

            switch (ni.getType()) {//获取当前网络的状态
                case ConnectivityManager.TYPE_WIFI:// wifi的情况下
                    netType = NETWORK_WIFI;
                    RxToast.success("切换到wifi环境下");
                    break;
                case ConnectivityManager.TYPE_MOBILE:

                    switch (ni.getSubtype()) {
                        case NETWORK_TYPE_GSM:
                        case TelephonyManager.NETWORK_TYPE_GPRS: // 联通2g
                        case TelephonyManager.NETWORK_TYPE_CDMA: // 电信2g
                        case TelephonyManager.NETWORK_TYPE_EDGE: // 移动2g
                        case TelephonyManager.NETWORK_TYPE_1xRTT:
                        case TelephonyManager.NETWORK_TYPE_IDEN:
                            netType = NETWORK_2G;
                            RxToast.info("切换到2G环境下");
                            break;
                        case TelephonyManager.NETWORK_TYPE_EVDO_A: // 电信3g
                        case TelephonyManager.NETWORK_TYPE_UMTS:
                        case TelephonyManager.NETWORK_TYPE_EVDO_0:
                        case TelephonyManager.NETWORK_TYPE_HSDPA:
                        case TelephonyManager.NETWORK_TYPE_HSUPA:
                        case TelephonyManager.NETWORK_TYPE_HSPA:
                        case TelephonyManager.NETWORK_TYPE_EVDO_B:
                        case TelephonyManager.NETWORK_TYPE_EHRPD:
                        case TelephonyManager.NETWORK_TYPE_HSPAP:
                        case NETWORK_TYPE_TD_SCDMA:
                            netType = NETWORK_3G;
                            RxToast.info("切换到3G环境下");
                            break;
                        case TelephonyManager.NETWORK_TYPE_LTE:

                        case NETWORK_TYPE_IWLAN:
                            netType = NETWORK_4G;
                            RxToast.info("切换到4G环境下");
                            break;
                        default:

                            String subtypeName = ni.getSubtypeName();
                            if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                                    || subtypeName.equalsIgnoreCase("WCDMA")
                                    || subtypeName.equalsIgnoreCase("CDMA2000")) {
                                netType = NETWORK_3G;
                            } else {
                                netType = NETWORK_UNKNOWN;
                            }
                            RxToast.normal("未知网络");
                    }
                    break;
                default:
                    netType = 5;
                    RxToast.normal("未知网络");
            }

        } else {
            netType = NETWORK_NO;
            RxToast.error(context, "当前无网络连接").show();
        }
        return netType;
    }

20:判断服务是否开启

    /**
     * 获取服务是否开启
     *
     * @param context   上下文
     * @param className 完整包名的服务类名
     * @return {@code true}: 是<br>{@code false}: 否
     */
    public static boolean isRunningService(Context context, String className) {
        // 进程的管理者,活动的管理者
        ActivityManager activityManager = (ActivityManager)
                context.getSystemService(Context.ACTIVITY_SERVICE);
        // 获取正在运行的服务,最多获取1000个
        List<ActivityManager.RunningServiceInfo> runningServices = activityManager.getRunningServices(1000);
        // 遍历集合
        for (ActivityManager.RunningServiceInfo runningServiceInfo : runningServices) {
            ComponentName service = runningServiceInfo.service;
            if (className.equals(service.getClassName())) {
                return true;
            }
        }
        return false;
    }

 

 

2012-01-06 15:40:17 vinny_w 阅读数 16
  • Android底层技术:HAL驱动开发

    本课程提供开发者学习Android底层的HAL(硬件抽象层)的开发方法和技术。HAL所在的位置是介于Android系统服务与Linux内核之间,HAL Driver是以library形式出现,给HAL Stub调用,供Android System架构者调用。而HAL Stub则是google设计出来的,保护硬件厂商的硬件驱动。

    17825 人正在学习 去看看 高煥堂
Android 中intent是经常要用到的。不管是页面牵转,还是传递数据,或是调用外部程序,系统功能都要用到intent。在做了一些intent的例子之后,整理了一下intent,希望对大家有用。由于intent内容太多,不可能真的写全,难免会有遗落,以后我会随时更新。如果你们有疑问或新的intent内容,希望交流。

★intent大全:
1.从google搜索内容
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,"searchString")
startActivity(intent);

2.浏览网页
Uri uri =Uri.parse("http://www.google.com");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);

3.显示地图
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent it = newIntent(Intent.Action_VIEW,uri);
startActivity(it);

4.路径规划
Uri uri =Uri.parse("http://maps.google.com/maps?f=dsaddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
Intent it = newIntent(Intent.ACTION_VIEW,URI);
startActivity(it);

5.拨打电话
Uri uri =Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL,uri);
startActivity(it);

6.调用发短信的程序
Intent it = newIntent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "TheSMS text");
it.setType("vnd.android-dir/mms-sms");
startActivity(it);

7.发送短信
Uri uri =Uri.parse("smsto:0800000123");
Intent it = newIntent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "TheSMS text");
startActivity(it);
String body="this is sms demo";
Intent mmsintent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null));
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);
startActivity(mmsintent);

8.发送彩信
Uri uri =Uri.parse("content://media/external/images/media/23");
Intent it = newIntent(Intent.ACTION_SEND);
it.putExtra("sms_body","some text");
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType("image/png");
startActivity(it);
StringBuilder sb = new StringBuilder();
sb.append("file://");
sb.append(fd.getAbsoluteFile());
Intent intent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number, null));
// Below extra datas are all optional.
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT,subject);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI,sb.toString());
intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,composeMode);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,exitOnSent);
startActivity(intent);

9.发送Email
Uri uri =Uri.parse("mailto:xxx@abc.com");
Intent it = newIntent(Intent.ACTION_SENDTO, uri);
startActivity(it);
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL,"me@abc.com");
it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");
it.setType("text/plain");
startActivity(Intent.createChooser(it,"Choose Email Client"));
Intent it=new Intent(Intent.ACTION_SEND);
String[] tos={"me@abc.com"};
String[]ccs={"you@abc.com"};
it.putExtra(Intent.EXTRA_EMAIL, tos);
it.putExtra(Intent.EXTRA_CC, ccs);
it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");
it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");
it.setType("message/rfc822");
startActivity(Intent.createChooser(it,"Choose Email Client"));

Intent it = newIntent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");
it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");
sendIntent.setType("audio/mp3");
startActivity(Intent.createChooser(it,"Choose Email Client"));

10.播放多媒体
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri =Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri,"audio/mp3");
startActivity(it);
Uri uri =Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);

11.uninstall apk
Uri uri =Uri.fromParts("package", strPackageName, null);
Intent it = newIntent(Intent.ACTION_DELETE, uri);
startActivity(it);

12.install apk
Uri installUri = Uri.fromParts("package","xxx", null);
returnIt = newIntent(Intent.ACTION_PACKAGE_ADDED, installUri);

13. 打开照相机
<1>Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
this.sendBroadcast(i);
<2>long dateTaken = System.currentTimeMillis();
String name = createName(dateTaken) + ".jpg";
fileName = folder + name;
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, fileName);
values.put("_data", fileName);
values.put(Images.Media.PICASA_ID, fileName);
values.put(Images.Media.DISPLAY_NAME, fileName);
values.put(Images.Media.DESCRIPTION, fileName);
values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);
Uri photoUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);

Intent inttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(inttPhoto, 10);

14.从gallery选取图片
Intent i = new Intent();
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(i, 11);

15. 打开录音机
Intent mi = new Intent(Media.RECORD_SOUND_ACTION);
startActivity(mi);

16.显示应用详细列表
Uri uri =Uri.parse("market://details?id=app_id");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
//where app_id is the application ID, findthe ID
//by clicking on your application on Markethome
//page, and notice the ID from the addressbar

刚才找app id未果,结果发现用package name也可以
Uri uri =Uri.parse("market://details?id=<packagename>");
这个简单多了

17寻找应用
Uri uri =Uri.parse("market://search?q=pname:pkg_name");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
//where pkg_name is the full package pathfor an application

18打开联系人列表
<1>
Intent i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
i.setType("vnd.android.cursor.item/phone");
startActivityForResult(i, REQUEST_TEXT);

<2>
Uri uri = Uri.parse("content://contacts/people");
Intent it = new Intent(Intent.ACTION_PICK, uri);
startActivityForResult(it, REQUEST_TEXT);

19 打开另一程序
Intent i = new Intent();
ComponentName cn = newComponentName("com.yellowbook.android2",
"com.yellowbook.android2.AndroidSearch");
i.setComponent(cn);
i.setAction("android.intent.action.MAIN");
startActivityForResult(i, RESULT_OK);

20.调用系统编辑添加联系人(高版本SDK有效):
Intent it = newIntent(Intent.ACTION_INSERT_OR_EDIT);
it.setType("vnd.android.cursor.item/contact");
//it.setType(Contacts.CONTENT_ITEM_TYPE);
it.putExtra("name","myName");
it.putExtra(android.provider.Contacts.Intents.Insert.COMPANY, "organization");
it.putExtra(android.provider.Contacts.Intents.Insert.EMAIL,"email");
it.putExtra(android.provider.Contacts.Intents.Insert.PHONE,"homePhone");
it.putExtra(android.provider.Contacts.Intents.Insert.SECONDARY_PHONE,
"mobilePhone");
it.putExtra( android.provider.Contacts.Intents.Insert.TERTIARY_PHONE,
"workPhone");
it.putExtra(android.provider.Contacts.Intents.Insert.JOB_TITLE,"title");
startActivity(it);

21.调用系统编辑添加联系人(全有效):
Intent intent = newIntent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(People.CONTENT_ITEM_TYPE);
intent.putExtra(Contacts.Intents.Insert.NAME, "My Name");
intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");
intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE);
intent.putExtra(Contacts.Intents.Insert.EMAIL, "com@com.com");
intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE, Contacts.ContactMethodsColumns.TYPE_WORK);
startActivity(intent);

★intent action大全:
android.intent.action.ALL_APPS
android.intent.action.ANSWER
android.intent.action.ATTACH_DATA
android.intent.action.BUG_REPORT
android.intent.action.CALL
android.intent.action.CALL_BUTTON
android.intent.action.CHOOSER
android.intent.action.CREATE_LIVE_FOLDER
android.intent.action.CREATE_SHORTCUT
android.intent.action.DELETE
android.intent.action.DIAL
android.intent.action.EDIT
android.intent.action.GET_CONTENT
android.intent.action.INSERT
android.intent.action.INSERT_OR_EDIT
android.intent.action.MAIN
android.intent.action.MEDIA_SEARCH
android.intent.action.PICK
android.intent.action.PICK_ACTIVITY
android.intent.action.RINGTONE_PICKER
android.intent.action.RUN
android.intent.action.SEARCH
android.intent.action.SEARCH_LONG_PRESS
android.intent.action.SEND
android.intent.action.SENDTO
android.intent.action.SET_WALLPAPER
android.intent.action.SYNC
android.intent.action.SYSTEM_TUTORIAL
android.intent.action.VIEW
android.intent.action.VOICE_COMMAND
android.intent.action.WEB_SEARCH
android.net.wifi.PICK_WIFI_NETWORK
android.settings.AIRPLANE_MODE_SETTINGS
android.settings.APN_SETTINGS
android.settings.APPLICATION_DEVELOPMENT_SETTINGS
android.settings.APPLICATION_SETTINGS
android.settings.BLUETOOTH_SETTINGS
android.settings.DATA_ROAMING_SETTINGS
android.settings.DATE_SETTINGS
android.settings.DISPLAY_SETTINGS
android.settings.INPUT_METHOD_SETTINGS
android.settings.INTERNAL_STORAGE_SETTINGS
android.settings.LOCALE_SETTINGS
android.settings.LOCATION_SOURCE_SETTINGS
android.settings.MANAGE_APPLICATIONS_SETTINGS
android.settings.MEMORY_CARD_SETTINGS
android.settings.NETWORK_OPERATOR_SETTINGS
android.settings.QUICK_LAUNCH_SETTINGS
android.settings.SECURITY_SETTINGS
android.settings.SETTINGS
android.settings.SOUND_SETTINGS
android.settings.SYNC_SETTINGS
android.settings.USER_DICTIONARY_SETTINGS
android.settings.WIFI_IP_SETTINGS
android.settings.WIFI_SETTINGS
android.settings.WIRELESS_SETTINGS
2012-04-12 11:58:00 iteye_3535 阅读数 91
  • Android底层技术:HAL驱动开发

    本课程提供开发者学习Android底层的HAL(硬件抽象层)的开发方法和技术。HAL所在的位置是介于Android系统服务与Linux内核之间,HAL Driver是以library形式出现,给HAL Stub调用,供Android System架构者调用。而HAL Stub则是google设计出来的,保护硬件厂商的硬件驱动。

    17825 人正在学习 去看看 高煥堂

android系统调用

android 中intent是经常要用到的。不管是页面跳转,还是传递数据,或是调用外部程序,系统功能都要用到intent。

随着Android版本升级,以后会持续更新。


★intent大全:

1.从google搜索内容

Intent intent = newIntent();

intent.setAction(Intent.ACTION_WEB_SEARCH);

intent.putExtra(SearchManager.QUERY,"searchString")

startActivity(intent);

2.浏览网页

Uri uri=Uri.parse("http://www.google.com");

Intent it= newIntent(Intent.ACTION_VIEW,uri);

startActivity(it);

3.显示地图

Uri uri =Uri.parse("geo:38.899533,-77.036476");

Intent it =newIntent(Intent.Action_VIEW,uri);

startActivity(it);

4.路径规划

Uri uri=Uri.parse("http://maps.google.com/maps?f=dsaddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");

Intent it =newIntent(Intent.ACTION_VIEW,URI);

startActivity(it);

5.拨打电话

Uri uri=Uri.parse("tel:xxxxxx");

Intent it = newIntent(Intent.ACTION_DIAL,uri);

startActivity(it);

6.调用发短信的程序

Intent it =newIntent(Intent.ACTION_VIEW);

it.putExtra("sms_body","TheSMS text");

it.setType("vnd.android-dir/mms-sms");

startActivity(it);

7.发送短信

Uri uri=Uri.parse("smsto:0800000123");

Intent it =newIntent(Intent.ACTION_SENDTO, uri);

it.putExtra("sms_body","TheSMS text");

startActivity(it);

Stringbody="this is sms demo";

Intent mmsintent =newIntent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number,null));

mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);

mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);

mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);

startActivity(mmsintent);

8.发送彩信

Uri uri=Uri.parse("content://media/external/images/media/23");

Intent it =newIntent(Intent.ACTION_SEND);

it.putExtra("sms_body","sometext");

it.putExtra(Intent.EXTRA_STREAM,uri);

it.setType("image/png");

startActivity(it);

StringBuilder sb =new StringBuilder();

sb.append("file://");

sb.append(fd.getAbsoluteFile());

Intent intent =newIntent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number,null));

// Below extra datasare all optional.

intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT,subject);

intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);

intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI,sb.toString());

intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,composeMode);

intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,exitOnSent);

startActivity(intent);

9.发送Email

Uri uri=Uri.parse("mailto:xxx@abc.com");

Intent it =newIntent(Intent.ACTION_SENDTO, uri);

startActivity(it);

Intent it = newIntent(Intent.ACTION_SEND);

it.putExtra(Intent.EXTRA_EMAIL,"me@abc.com");

it.putExtra(Intent.EXTRA_TEXT,"Theemail body text");

it.setType("text/plain");

startActivity(Intent.createChooser(it,"ChooseEmail Client"));

Intent it=newIntent(Intent.ACTION_SEND);

String[]tos={"me@abc.com"};

String[]ccs={"you@abc.com"};

it.putExtra(Intent.EXTRA_EMAIL,tos);

it.putExtra(Intent.EXTRA_CC,ccs);

it.putExtra(Intent.EXTRA_TEXT,"Theemail body text");

it.putExtra(Intent.EXTRA_SUBJECT,"Theemail subject text");

it.setType("message/rfc822");

startActivity(Intent.createChooser(it,"ChooseEmail Client"));

Intent it =newIntent(Intent.ACTION_SEND);

it.putExtra(Intent.EXTRA_SUBJECT,"Theemail subject text");

it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");

sendIntent.setType("audio/mp3");

startActivity(Intent.createChooser(it,"ChooseEmail Client"));

10.播放多媒体

Intent it = newIntent(Intent.ACTION_VIEW);

Uri uri=Uri.parse("file:///sdcard/song.mp3");

it.setDataAndType(uri,"audio/mp3");

startActivity(it);

Uri uri=Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");

Intent it = newIntent(Intent.ACTION_VIEW,uri);

startActivity(it);

11.uninstall apk

Uri uri=Uri.fromParts("package", strPackageName, null);

Intent it =newIntent(Intent.ACTION_DELETE, uri);

startActivity(it);

12.install apk

Uri installUri =Uri.fromParts("package","xxx", null);

returnIt =newIntent(Intent.ACTION_PACKAGE_ADDED, installUri);

13. 打开照相机

<1>Intenti = new Intent(Intent.ACTION_CAMERA_BUTTON, null);

this.sendBroadcast(i);

<2>longdateTaken = System.currentTimeMillis();

Stringname = createName(dateTaken) + ".jpg";

fileName= folder + name;

ContentValuesvalues = new ContentValues();

values.put(Images.Media.TITLE,fileName);

values.put("_data",fileName);

values.put(Images.Media.PICASA_ID,fileName);

values.put(Images.Media.DISPLAY_NAME,fileName);

values.put(Images.Media.DESCRIPTION,fileName);

values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME,fileName);

UriphotoUri = getContentResolver().insert(

MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);

IntentinttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT,photoUri);

startActivityForResult(inttPhoto,10);

14.从gallery选取图片

Intent i = new Intent();

i.setType("image/*");

i.setAction(Intent.ACTION_GET_CONTENT);

startActivityForResult(i,11);

15. 打开录音机

Intent mi= new Intent(Media.RECORD_SOUND_ACTION);

startActivity(mi);

16.显示应用详细列表

Uri uri=Uri.parse("market://details?id=app_id");

Intent it = newIntent(Intent.ACTION_VIEW,uri);

startActivity(it);

//where app_id is theapplication ID, findtheID

//by clicking on yourapplication on Markethome

//page, and noticethe ID from the addressbar

刚才找app id未果,结果发现用package name也可以

Uri uri=Uri.parse("market://details?id=<packagename>");

这个简单多了

17寻找应用

Uri uri=Uri.parse("market://search?q=pname:pkg_name");

Intent it = newIntent(Intent.ACTION_VIEW,uri);

startActivity(it);

//where pkg_name isthe full package pathfor an application

18打开联系人列表

(1).通过关键字查找联系人

Intent intent = new Intent(android.provider.Contacts.Intents.UI.FILTER_CONTACTS_ACTION);
intent.setData(ContactsContract.Contacts.CONTENT_URI);
intent.putExtra(android.provider.Contacts.Intents.UI.FILTER_TEXT_EXTRA_KEY,"peng");

(2)查看所有联系人列表

Intent intent = new Intent(android.provider.Contacts.Intents.UI.LIST_ALL_CONTACTS_ACTION);

startActivity(intent);

(3).查看联系人列表:

Intent intent = new Intent(Intent.ACTION_VIEW, ContactsContract.Contacts.CONTENT_URI);
startActivity(intent);

(4).从联系人列表挑选联系人:

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);

startActivityForResult(intent,PICK_CONTACT);

实现onActivityResult

@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);

switch (reqCode) {
case (PICK_CONTACT) :
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
if (c.moveToFirst()) {
String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
String phoneNumber = null;
if ( hasPhone.equalsIgnoreCase("1")) {
hasPhone = "true";
} else {
hasPhone = "false" ;
}
if (Boolean.parseBoolean(hasPhone)) {
Cursor phones= getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
while (phones.moveToNext()) {
phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
phones.close();
}
}
}
break;
}
}

19 打开另一程序

Intent i = newIntent();

ComponentNamecn = newComponentName("com.yellowbook.android2",

"com.yellowbook.android2.AndroidSearch");

i.setComponent(cn);

i.setAction("android.intent.action.MAIN");

startActivityForResult(i,RESULT_OK);

20.调用系统编辑添加联系人(高版本SDK有效):

Intent it =newIntent(Intent.ACTION_INSERT_OR_EDIT);

it.setType("vnd.android.cursor.item/contact");

//it.setType(Contacts.CONTENT_ITEM_TYPE);

it.putExtra("name","myName");

it.putExtra(android.provider.Contacts.Intents.Insert.COMPANY,"organization");

it.putExtra(android.provider.Contacts.Intents.Insert.EMAIL,"email");

it.putExtra(android.provider.Contacts.Intents.Insert.PHONE,"homePhone");

it.putExtra(android.provider.Contacts.Intents.Insert.SECONDARY_PHONE,

"mobilePhone");

it.putExtra( android.provider.Contacts.Intents.Insert.TERTIARY_PHONE,

"workPhone");

it.putExtra(android.provider.Contacts.Intents.Insert.JOB_TITLE,"title");

startActivity(it);

21.调用系统编辑添加联系人(全有效):

Intent intent =newIntent(Intent.ACTION_INSERT_OR_EDIT);

intent.setType(People.CONTENT_ITEM_TYPE);

intent.putExtra(Contacts.Intents.Insert.NAME,"My Name");

intent.putExtra(Contacts.Intents.Insert.PHONE,"+1234567890");

intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE);

intent.putExtra(Contacts.Intents.Insert.EMAIL,"com@com.com");

intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE,Contacts.ContactMethodsColumns.TYPE_WORK);

startActivity(intent);

★intent action大全:

android.intent.action.ALL_APPS

android.intent.action.ANSWER

android.intent.action.ATTACH_DATA

android.intent.action.BUG_REPORT

android.intent.action.CALL

android.intent.action.CALL_BUTTON

android.intent.action.CHOOSER

android.intent.action.CREATE_LIVE_FOLDER

android.intent.action.CREATE_SHORTCUT

android.intent.action.DELETE

android.intent.action.DIAL

android.intent.action.EDIT

android.intent.action.GET_CONTENT

android.intent.action.INSERT

android.intent.action.INSERT_OR_EDIT

android.intent.action.MAIN

android.intent.action.MEDIA_SEARCH

android.intent.action.PICK

android.intent.action.PICK_ACTIVITY

android.intent.action.RINGTONE_PICKER

android.intent.action.RUN

android.intent.action.SEARCH

android.intent.action.SEARCH_LONG_PRESS

android.intent.action.SEND

android.intent.action.SENDTO

android.intent.action.SET_WALLPAPER

android.intent.action.SYNC

android.intent.action.SYSTEM_TUTORIAL

android.intent.action.VIEW

android.intent.action.VOICE_COMMAND

android.intent.action.WEB_SEARCH

android.net.wifi.PICK_WIFI_NETWORK

android.settings.AIRPLANE_MODE_SETTINGS

android.settings.APN_SETTINGS

android.settings.APPLICATION_DEVELOPMENT_SETTINGS

android.settings.APPLICATION_SETTINGS

android.settings.BLUETOOTH_SETTINGS

android.settings.DATA_ROAMING_SETTINGS

android.settings.DATE_SETTINGS

android.settings.DISPLAY_SETTINGS

android.settings.INPUT_METHOD_SETTINGS

android.settings.INTERNAL_STORAGE_SETTINGS

android.settings.LOCALE_SETTINGS

android.settings.LOCATION_SOURCE_SETTINGS

android.settings.MANAGE_APPLICATIONS_SETTINGS

android.settings.MEMORY_CARD_SETTINGS

android.settings.NETWORK_OPERATOR_SETTINGS

android.settings.QUICK_LAUNCH_SETTINGS

android.settings.SECURITY_SETTINGS

android.settings.SETTINGS

android.settings.SOUND_SETTINGS

android.settings.SYNC_SETTINGS

android.settings.USER_DICTIONARY_SETTINGS

android.settings.WIFI_IP_SETTINGS

android.settings.WIFI_SETTINGS

android.settings.WIRELESS_SETTINGS

2011-12-01 08:41:51 liguangzhenghi 阅读数 11
  • Android底层技术:HAL驱动开发

    本课程提供开发者学习Android底层的HAL(硬件抽象层)的开发方法和技术。HAL所在的位置是介于Android系统服务与Linux内核之间,HAL Driver是以library形式出现,给HAL Stub调用,供Android System架构者调用。而HAL Stub则是google设计出来的,保护硬件厂商的硬件驱动。

    17825 人正在学习 去看看 高煥堂

android系统调用

android intent是经常要用到的。不管是页面牵转,还是传递数据,或是调用外部程序,系统功能都要用到intent。在做了一些intent的例子之后,整理了一下intent,希望对大家有用。由于intent内容太多,不可能真的写全,难免会有遗落,以后我会随时更新。如果你们有疑问或新的intent内容,希望交流。

intent大全:

1.google搜索内容

Intent intent = new Intent();

intent.setAction(Intent.ACTION_WEB_SEARCH);

intent.putExtra(SearchManager.QUERY,"searchString")

startActivity(intent);

 

2.浏览网页

Uri uri =Uri.parse("http://www.google.com");

Intent it = new Intent(Intent.ACTION_VIEW,uri);

startActivity(it);

 

3.显示地图

Uri uri = Uri.parse("geo:38.899533,-77.036476");

Intent it = newIntent(Intent.Action_VIEW,uri);

startActivity(it);

 

4.路径规划

Uri uri =Uri.parse("http://maps.google.com/maps?f=dsaddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");

Intent it = newIntent(Intent.ACTION_VIEW,URI);

startActivity(it);

 

5.拨打电话

Uri uri =Uri.parse("tel:xxxxxx");

Intent it = new Intent(Intent.ACTION_DIAL,uri);  

startActivity(it);

 

6.调用发短信的程序

Intent it = newIntent(Intent.ACTION_VIEW);   

it.putExtra("sms_body", "TheSMS text");   

it.setType("vnd.android-dir/mms-sms");   

startActivity(it);

 

7.发送短信

Uri uri =Uri.parse("smsto:0800000123");   

Intent it = newIntent(Intent.ACTION_SENDTO, uri);   

it.putExtra("sms_body", "TheSMS text");   

startActivity(it);

String body="this is sms demo";

Intent mmsintent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null));

mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);

mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);

mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);

startActivity(mmsintent);

 

8.发送彩信

Uri uri =Uri.parse("content://media/external/images/media/23");   

Intent it = newIntent(Intent.ACTION_SEND);   

it.putExtra("sms_body","some text");   

it.putExtra(Intent.EXTRA_STREAM, uri);   

it.setType("image/png");   

startActivity(it);

StringBuilder sb = new StringBuilder();

sb.append("file://");

sb.append(fd.getAbsoluteFile());

Intent intent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number, null));

// Below extra datas are all optional.

intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT,subject);

intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);

intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI,sb.toString());

intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,composeMode);

intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,exitOnSent);

startActivity(intent);

 

9.发送Email

Uri uri =Uri.parse("mailto:xxx@abc.com");

Intent it = newIntent(Intent.ACTION_SENDTO, uri);

startActivity(it);

Intent it = new Intent(Intent.ACTION_SEND);   

it.putExtra(Intent.EXTRA_EMAIL,"me@abc.com");   

it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");   

it.setType("text/plain");   

startActivity(Intent.createChooser(it,"Choose Email Client"));

Intent it=new Intent(Intent.ACTION_SEND);     

String[] tos={"me@abc.com"};     

String[]ccs={"you@abc.com"};     

it.putExtra(Intent.EXTRA_EMAIL, tos);     

it.putExtra(Intent.EXTRA_CC, ccs);     

it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");     

it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");     

it.setType("message/rfc822");     

startActivity(Intent.createChooser(it,"Choose Email Client"));   

 

Intent it = newIntent(Intent.ACTION_SEND);   

it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");    

it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");   

sendIntent.setType("audio/mp3");   

startActivity(Intent.createChooser(it,"Choose Email Client"));

 

10.播放多媒体  

Intent it = new Intent(Intent.ACTION_VIEW);

Uri uri =Uri.parse("file:///sdcard/song.mp3");

it.setDataAndType(uri,"audio/mp3");

startActivity(it);

Uri uri =Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");   

Intent it = new Intent(Intent.ACTION_VIEW,uri);   

startActivity(it);

 

11.uninstall apk

Uri uri =Uri.fromParts("package", strPackageName, null);   

Intent it = newIntent(Intent.ACTION_DELETE, uri);   

startActivity(it);

 

12.install apk

Uri installUri = Uri.fromParts("package","xxx", null);

returnIt = newIntent(Intent.ACTION_PACKAGE_ADDED, installUri);

 

13. 打开照相机

   <1>Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);

          this.sendBroadcast(i);

    <2>long dateTaken = System.currentTimeMillis();

           String name = createName(dateTaken) + ".jpg";

           fileName = folder + name;

           ContentValues values = new ContentValues();

           values.put(Images.Media.TITLE, fileName);

           values.put("_data", fileName);

           values.put(Images.Media.PICASA_ID, fileName);

           values.put(Images.Media.DISPLAY_NAME, fileName);

           values.put(Images.Media.DESCRIPTION, fileName);

           values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);

           Uri photoUri = getContentResolver().insert(

                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);

 

           Intent inttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

           inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);

           startActivityForResult(inttPhoto, 10);

 

14.gallery选取图片

 Intent i = new Intent();

           i.setType("image/*");

           i.setAction(Intent.ACTION_GET_CONTENT);

           startActivityForResult(i, 11);

 

15. 打开录音机

  Intent mi = new Intent(Media.RECORD_SOUND_ACTION);

           startActivity(mi);

 

16.显示应用详细列表      

Uri uri =Uri.parse("market://details?id=app_id");        

Intent it = new Intent(Intent.ACTION_VIEW,uri);        

startActivity(it);        

//where app_id is the application ID, findthe ID         

//by clicking on your application on Markethome         

//page, and notice the ID from the addressbar     

 

刚才找app id未果,结果发现用package name也可以

Uri uri =Uri.parse("market://details?id=<packagename>");

这个简单多了

 

17寻找应用      

Uri uri =Uri.parse("market://search?q=pname:pkg_name");        

Intent it = new Intent(Intent.ACTION_VIEW,uri);        

startActivity(it);

//where pkg_name is the full package pathfor an application      

 

18打开联系人列表

           <1>           

          Intent i = new Intent();

          i.setAction(Intent.ACTION_GET_CONTENT);

          i.setType("vnd.android.cursor.item/phone");

          startActivityForResult(i, REQUEST_TEXT);

 

           <2>

           Uri uri = Uri.parse("content://contacts/people");

           Intent it = new Intent(Intent.ACTION_PICK, uri);

           startActivityForResult(it, REQUEST_TEXT);

 

19 打开另一程序

Intent i = new Intent();

           ComponentName cn = newComponentName("com.yellowbook.android2",

                   "com.yellowbook.android2.AndroidSearch");

           i.setComponent(cn);

           i.setAction("android.intent.action.MAIN");

           startActivityForResult(i, RESULT_OK);

 

20.调用系统编辑添加联系人(高版本SDK有效):

Intent it = newIntent(Intent.ACTION_INSERT_OR_EDIT);

               it.setType("vnd.android.cursor.item/contact");

                //it.setType(Contacts.CONTENT_ITEM_TYPE);

                it.putExtra("name","myName");

               it.putExtra(android.provider.Contacts.Intents.Insert.COMPANY,  "organization");

               it.putExtra(android.provider.Contacts.Intents.Insert.EMAIL,"email");

                it.putExtra(android.provider.Contacts.Intents.Insert.PHONE,"homePhone");

                it.putExtra(android.provider.Contacts.Intents.Insert.SECONDARY_PHONE,

                               "mobilePhone");

                it.putExtra(  android.provider.Contacts.Intents.Insert.TERTIARY_PHONE,

                               "workPhone");

               it.putExtra(android.provider.Contacts.Intents.Insert.JOB_TITLE,"title");

                startActivity(it);

 

21.调用系统编辑添加联系人(全有效):

Intent intent = newIntent(Intent.ACTION_INSERT_OR_EDIT);

           intent.setType(People.CONTENT_ITEM_TYPE);

           intent.putExtra(Contacts.Intents.Insert.NAME, "My Name");

           intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");

           intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE);

           intent.putExtra(Contacts.Intents.Insert.EMAIL, "com@com.com");

           intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE,                    Contacts.ContactMethodsColumns.TYPE_WORK);

           startActivity(intent);

 

intent action大全:

android.intent.action.ALL_APPS

android.intent.action.ANSWER

android.intent.action.ATTACH_DATA

android.intent.action.BUG_REPORT

android.intent.action.CALL

android.intent.action.CALL_BUTTON

android.intent.action.CHOOSER

android.intent.action.CREATE_LIVE_FOLDER

android.intent.action.CREATE_SHORTCUT

android.intent.action.DELETE

android.intent.action.DIAL

android.intent.action.EDIT

android.intent.action.GET_CONTENT

android.intent.action.INSERT

android.intent.action.INSERT_OR_EDIT

android.intent.action.MAIN

android.intent.action.MEDIA_SEARCH

android.intent.action.PICK

android.intent.action.PICK_ACTIVITY

android.intent.action.RINGTONE_PICKER

android.intent.action.RUN

android.intent.action.SEARCH

android.intent.action.SEARCH_LONG_PRESS

android.intent.action.SEND

android.intent.action.SENDTO

android.intent.action.SET_WALLPAPER

android.intent.action.SYNC

android.intent.action.SYSTEM_TUTORIAL

android.intent.action.VIEW

android.intent.action.VOICE_COMMAND

android.intent.action.WEB_SEARCH

android.net.wifi.PICK_WIFI_NETWORK

android.settings.AIRPLANE_MODE_SETTINGS

android.settings.APN_SETTINGS

android.settings.APPLICATION_DEVELOPMENT_SETTINGS

android.settings.APPLICATION_SETTINGS

android.settings.BLUETOOTH_SETTINGS

android.settings.DATA_ROAMING_SETTINGS

android.settings.DATE_SETTINGS

android.settings.DISPLAY_SETTINGS

android.settings.INPUT_METHOD_SETTINGS

android.settings.INTERNAL_STORAGE_SETTINGS

android.settings.LOCALE_SETTINGS

android.settings.LOCATION_SOURCE_SETTINGS

android.settings.MANAGE_APPLICATIONS_SETTINGS

android.settings.MEMORY_CARD_SETTINGS

android.settings.NETWORK_OPERATOR_SETTINGS

android.settings.QUICK_LAUNCH_SETTINGS

android.settings.SECURITY_SETTINGS

android.settings.SETTINGS

android.settings.SOUND_SETTINGS

android.settings.SYNC_SETTINGS

android.settings.USER_DICTIONARY_SETTINGS

android.settings.WIFI_IP_SETTINGS

android.settings.WIFI_SETTINGS

android.settings.WIRELESS_SETTINGS

Android调用系统相册系统相册

博文 来自: u011976726

ptrace系统调用

阅读数 1299

没有更多推荐了,返回首页