乙巳🐍年

acc8226 的博客

安卓 android.net.Uri 类使用

Uri.Builder
Helper class for building or manipulating URI references.

1
2
3
4
5
6
7
8
 Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon()
.appendQueryParameter(QUERY_PARAM, params[0])
.appendQueryParameter(FORMAT_PARAM, format)
.appendQueryParameter(UNITS_PARAM, units)
.appendQueryParameter(DAYS_PARAM, Integer.toString(numDays))
.appendQueryParameter(APPID_PARAM, BuildConfig.OPEN_WEATHER_MAP_API_KEY)
.build();
URL url = new URL(builtUri.toString());
阅读全文 »

https://developer.android.google.cn/training/permissions/index.html

声明权限

每款 Android 应用都在访问受限的沙盒中运行。如果应用需要使用其沙盒外的资源或信息,则必须请求相应权限。您可以在应用清单中列出相应的权限,声明应用需要此权限。
根据权限的敏感性,系统可能会自动授予权限,或者需要由设备用户对请求进行许可。例如,如果您的应用请求打开设备手电筒的权限,系统将自动授予该权限。但如果您的应用需要读取用户联系人,系统会要求用户授权。
用户需要在安装应用(运行 Android 5.1 和更低版本的设备)或者运行应用(运行 Android 6.0 和更高版本的设备)时授予权限,具体取决于平台版本。

确定您的应用需要哪些权限

开发应用时,您应注意应用何时使用需要权限的功能。通常,在使用并非由自身创建的信息资源、执行会影响设备或其他应用行为的操作时,应用都需要获得相应的权限。例如,如果应用需要访问互联网、使用设备摄像头或者打开或关闭 WLAN,应用需要获得相应的权限。要查看系统权限的列表,请参阅正常权限和危险权限

阅读全文 »

http://developer.android.youdaxue.com/guide/topics/resources/string-resource.html

字符串资源

字符串资源为您的应用提供具有可选文本样式和格式设置的文本字符串。 共有三种类型的资源可为您的应用提供字符串:

所有字符串都能应用某些样式设置标记和格式设置参数。如需了解有关样式和格式设置字符串的信息,请参阅有关格式和样式设置的部分

阅读全文 »

http://developer.android.youdaxue.com/guide/topics/ui/menus.html

菜单是许多应用类型中常见的用户界面组件。要提供熟悉而一致的用户体验,您应使用 Menu API 呈现 Activity 中的用户操作和其他选项。
从 Android 3.0(API 级别 11)开始,采用 Android 技术的设备不必再提供一个专用“菜单”按钮。随着这种改变,Android 应用需摆脱对包含 6 个项目的传统菜单面板的依赖,取而代之的是要提供一个应用栏来呈现常见的用户操作。
尽管某些菜单项的设计和用户体验已发生改变,但定义一系列操作和选项所使用的语义仍是以 Menu API 为基础。本指南将介绍所有 Android 版本系统中三种基本菜单或操作呈现效果的创建方法:

  • 选项菜单和应用栏
    选项菜单是某个 Activity 的主菜单项, 供您放置对应用产生全局影响的操作,如“搜索”、“撰写电子邮件”和“设置”。请参阅创建选项菜单部分。

  • 上下文菜单和上下文操作模式
    上下文菜单是用户长按某一元素时出现的浮动菜单。 它提供的操作将影响所选内容或上下文框架。上下文操作模式在屏幕顶部栏显示影响所选内容的操作项目,并允许用户选择多项。
    请参阅创建上下文菜单部分。

  • 弹出菜单
    弹出菜单将以垂直列表形式显示一系列项目,这些项目将锚定到调用该菜单的视图中。 它特别适用于提供与特定内容相关的大量操作,或者为命令的另一部分提供选项。 弹出菜单中的操作不会直接影响对应的内容,而上下文操作则会影响。 相反,弹出菜单适用于与您 Activity 中的内容区域相关的扩展操作。请参阅创建弹出菜单部分。

阅读全文 »

AsyncTask

http://developer.android.youdaxue.com/reference/android/os/AsyncTask.html

1
2
3
public abstract class AsyncTask extends [Object](http://developer.android.youdaxue.com/reference/java/lang/Object.html) 
[java.lang.Object](http://developer.android.youdaxue.com/reference/java/lang/Object.html)
android.os.AsyncTask<Params, Progress, Result>

AsyncTask enables proper and easy use of the UI thread. This class allows you to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.
AsyncTask is designed to be a helper class around Thread and Handler and does not constitute a generic threading framework. AsyncTasks should ideally be used for short operations (a few seconds at the most.) If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent package such as Executor, ThreadPoolExecutor and FutureTask.
An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by 3 generic types, called Params, Progress and Result, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and onPostExecute.

阅读全文 »
0%