如题
依次执行以下命令
sudo su adb kill-server adb start-server exit
尝试后会发现已经有权限了
【翻译】(68)uses-permission元素
see
http://developer.android.com/guide/topics/manifest/uses-permission-element.html
原文见
http://developer.android.com/guide/topics/manifest/uses-permission-element.html
-------------------------------
<uses-permission>
uses-permission元素
-------------------------------
<uses-permission> and filtering on Android Market.
<uses-permission>和Android市场上的过滤。
In some cases, the permissions that you request through <uses-permission> can affect how your application is filtered by Android Market.
在一些情况下,你通过<uses-permission>请求的权限可以影响你的应用程序如何被Android市场过滤。
If you request a hardware-related permission — CAMERA, for example — Android Market assumes that your application requires the underlying hardware feature and filters the application from devices that do not offer it.
如果你请求一个硬件相关权限——例如,CAMERA——那么Android市场假设你的应用程序请求底层硬件特性并且从不提供它的设备中过滤掉该应用程序。
To control filtering, always explicitly declare hardware features in <uses-feature> elements, rather than relying on Android Market to "discover" the requirements in <uses-permission> elements. Then, if you want to disable filtering for a particular feature, you can add a android:required="false" attribute to the <uses-feature> declaration.
为了控制过滤,总是显式地在<uses-feature>元素中声明硬件特性,而非依赖Android市场在<uses-permission>元素中“发现”那些要求。然后,如果你希望屏蔽对一个特定特性的过滤,你可以添加android:required="false"属性到<uses-feature>声明。
-------------------------------
For a list of permissions that imply hardware features, see the documentation for the <uses-feature> element.
想获得一个暗示硬件特性的权限列表,参见<uses-feature>元素的文档。
-------------------------------
-------------------------------
* syntax:
* 语法:
-------------------------------
<uses-permission android:name="string" />
-------------------------------
* contained in:
* 被包含在:
<manifest>
* description:
* 描述:
Requests a permission that the application must be granted in order for it to operate correctly. Permissions are granted by the user when the application is installed, not while it's running.
请求一个应用程序必须被授权的权限,以便让它正确地操作。权限在应用程序被安装时被用户授权,而非在它正在运行的时候。
For more information on permissions, see the Permissions section in the introduction and the separate Security and Permissions document. A list of permissions defined by the base platform can be found at android.Manifest.permission.
想获得关于权限的更多信息,参见介绍中的权限章节以及单独的安全和权限文档。一个被基础平台定义的权限列表可以在android.Manifest.permission中找到。
* attributes:
* 属性:
* android:name
The name of the permission. It can be a permission defined by the application with the <permission> element, a permission defined by another application, or one of the standard system permissions, such as "android.permission.CAMERA" or "android.permission.READ_CONTACTS". As these examples show, a permission name typically includes the package name as a prefix.
权限的名称。它可以是一个由该应用程序用<permission>元素定义的权限,或者是被另一个应用程序定义的权限,或者是标准系统权限之一,诸如"android.permission.CAMERA"或"android.permission.READ_CONTACTS"。正如这些示例所示,一个权限名称典型地包含包名作为前缀。
* introduced in:
* 引入:
API Level 1
API级别1
* see also:
* 另见:
* <permission>
* <uses-feature>
Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.
除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。
Android 4.0 r1 - 14 Feb 2012 21:12
-------------------------------
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)
(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:
* ソフトウェア技術ドキュメントを勝手に翻訳
http://www.techdoctranslator.com/android
* Ley's Blog
http://leybreeze.com/blog/
* 农民伯伯
http://www.cnblogs.com/over140/
* Android中文翻译组
http://androidbox.sinaapp.com/
)
最近自己在写个小项目,需要从服务器下载文件,之前也写过下载文件的代码,都是采用传统的方式,既使用HttpClient来下载,但是需要自己处理很多异常,觉得甚是麻烦,后来发现android2.3里面提供了DownloadManager服务,那为何不拿来用了?于是有了下面的小例子:
代码如下:
public class ApkClientActivity extends Activity { static final String TAG = "ApkClientActivity"; Context mContext; DownloadManager manager ; DownloadCompleteReceiver receiver; Button downBtn ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mContext = this; //获取下载服务 manager =(DownloadManager)getSystemService(DOWNLOAD_SERVICE); receiver = new DownloadCompleteReceiver(); downBtn = (Button)findViewById(R.id.downBtn); downBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //创建下载请求 DownloadManager.Request down=new DownloadManager.Request (Uri.parse("http://192.168.0.66:8080/qqinput.apk")); //设置允许使用的网络类型,这里是移动网络和wifi都可以 down.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE|DownloadManager.Request.NETWORK_WIFI); //禁止发出通知,既后台下载 down.setShowRunningNotification(false); //不显示下载界面 down.setVisibleInDownloadsUi(false); //设置下载后文件存放的位置 down.setDestinationInExternalFilesDir(mContext, null, "qqinput.apk"); //将下载请求放入队列 manager.enqueue(down); } }); } //接受下载完成后的intent class DownloadCompleteReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if(intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)){ long downId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); Log.v(TAG," download complete! id : "+downId); Toast.makeText(context, intent.getAction()+"id : "+downId, Toast.LENGTH_SHORT).show(); } } } @Override protected void onResume() { registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); super.onResume(); } @Override protected void onDestroy() { if(receiver != null)unregisterReceiver(receiver); super.onDestroy(); } }
其中在设置 down.setShowRunningNotification(false);时,需要添加相应的权限:
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
否则,会报错!
AndroidManifest.xml文件内容如下:
<uses-sdk android:minSdkVersion="9" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".ApkClientActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
因为这个DownloadManager是android2.3才提供的,所以minSdkVersion = 9
还有更多的用法,等待后面去发现!
是的,这个只能在2.3及以上版本使用。但是,可以把它的源码拿过来阅读,进行改写实现自己的下载。
另外对于内置于系统的应用,还是可以使用这个DownloadProvider的。