为什么在 android 开发者指南中 android:authorities 是这样定义的?

2023-12-19

下面是记事本示例代码,为什么android:authorities = com.google.provider.NotePad而不是使用项目包名称?到底是什么android:authorities要求?

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!-- Declare the contents of this Android application.  The namespace
     attribute brings in the Android platform namespace, and the package
     supplies a unique name for the application.  When writing your
     own application, the package name must be changed from "com.example.*"
     to come from a domain that you own or have control over. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.notepad" >

    <uses-sdk android:minSdkVersion="11" />

    <application android:icon="@drawable/app_notes"
        android:label="@string/app_name"
    >
        <provider android:name="NotePadProvider"
            android:authorities="com.google.provider.NotePad"
            android:exported="false">
            <grant-uri-permission android:pathPattern=".*" />
        </provider>

        <activity android:name="NotesList" android:label="@string/title_notes_list">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.EDIT" />
                <action android:name="android.intent.action.PICK" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.GET_CONTENT" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
            </intent-filter>
        </activity>

        <activity android:name="NoteEditor"
            android:theme="@android:style/Theme.Holo.Light"
            android:screenOrientation="sensor"
            android:configChanges="keyboardHidden|orientation"
        >
            <!-- This filter says that we can view or edit the data of
                 a single note -->
            <intent-filter android:label="@string/resolve_edit">
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.EDIT" />
                <action android:name="com.android.notepad.action.EDIT_NOTE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
            </intent-filter>

            <!-- This filter says that we can create a new note inside
                 of a directory of notes.  The INSERT action creates an
                 empty note; the PASTE action initializes a new note from
                 the current contents of the clipboard. -->
            <intent-filter>
                <action android:name="android.intent.action.INSERT" />
                <action android:name="android.intent.action.PASTE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
            </intent-filter>

        </activity>

        <activity android:name="TitleEditor"
            android:label="@string/title_edit_title"
            android:icon="@drawable/ic_menu_edit"
            android:theme="@android:style/Theme.Holo.Dialog"
            android:windowSoftInputMode="stateVisible">
            <!-- This activity implements an alternative action that can be
                 performed on notes: editing their title.  It can be used as
                 a default operation if the user invokes this action, and is
                 available as an alternative action for any note data. -->
            <intent-filter android:label="@string/resolve_title">
                <!-- This is the action we perform.  It is a custom action we
                     define for our application, not a generic VIEW or EDIT
                     action since we are not a general note viewer/editor. -->
                <action android:name="com.android.notepad.action.EDIT_TITLE" />
                <!-- DEFAULT: execute if being directly invoked. -->
                <category android:name="android.intent.category.DEFAULT" />
                <!-- ALTERNATIVE: show as an alternative action when the user is
                     working with this type of data. -->
                <category android:name="android.intent.category.ALTERNATIVE" />
                <!-- SELECTED_ALTERNATIVE: show as an alternative action the user
                     can perform when selecting this type of data. -->
                <category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
                <!-- This is the data type we operate on. -->
                <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
            </intent-filter>
        </activity>

        <activity android:name="NotesLiveFolder" android:label="@string/live_folder_name"
            android:icon="@drawable/live_folder_notes">
            <intent-filter>
                <action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

    </application>

</manifest>

为什么 android:authorities = com.google.provider.NotePad 而不是使用项目包名称?

我想是因为谷歌喜欢这样。它是一个提供商,来自 com.google。您的应用程序中还可以有多个提供程序,因此仅包名称可能还不够。

android:authorities 到底想要什么?

您的提供商的系统范围内的唯一标识符。或者更好的是全球独一无二。所有提供商都在系统中注册,并且它们必须是唯一的,否则无法安装想要使用相同名称的第二个应用程序。

您最终使用该字符串通过 Uri 与您的提供商进行通信,例如

Uri uri = Uri.parse("content://" + "your.authoritiy.string")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么在 android 开发者指南中 android:authorities 是这样定义的? 的相关文章

  • 在第一个框中输入字符后,将焦点转到下一个框

    我必须实现一个应用程序 其中我设置了较小的值edittext用于输入 PIN 码和手机号码 每个编辑文本一次包含 1 个字符 现在 当我运行这个应用程序时 我发现对于每个框 我需要将焦点放在每个框上edittext 因此 在这种情况下 是否
  • Android 卷页动画

    我对 Android 动画有点陌生 目前我正在开发一个故事活动 需要像 iPhone 中那样使用卷页动画 我发现 iPhone 中有一种方法可以做到这一点 但我仍然找不到在android中做的方法 所以请帮我解决这个问题 谢谢大家 谷歌代码
  • PopupWindow onitemclick 中的 Android Listview 在某些设备上不起作用

    我的 ListView 在 PopupWindow 内 当我显示 PopupWindow 并单击设备 ASUS K00z 中的 Listview 行时 fonepad 工作得很好 但在 HTC Z715e 中不起作用 项目单击事件未触发 1
  • ViewFlipper中的VideoView在播放视频时是透明的

    我有一个 Activity 在 ViewFlipper 中设置了两个视图 其中一个视图是带有 GLSurfaceView 和一些其他小部件的布局 另一个视图只有带有 TextView 和 VideoView 的布局 当我单击 GLSurfa
  • 如何将Android中的cURL发送到REST服务

    我是 android 新手 我想从 REST 服务获取一些数据 但在初始化发送到 REST 服务的方法时遇到一些问题 您知道 REST 服务使用 cURL 来操作一些数据 POST PUT GET DELETE 现在如何在 android
  • 使用Picasso从url保存图像?

    我正在尝试使用 API Picasso 保存图像 为了做到这一点 我正在尝试使用Target保存 但我无法完成这项工作 我怎么能这样做呢 Trying save image public static void imageDownload
  • 如何在Android中访问现有的sqlite数据库?

    到目前为止 我们已经在 Android 中开发了在运行时创建数据库的应用程序 我们想知道如何在 Android 应用程序中访问预构建或现有的数据库 sqlite 文件 请提供详细信息 查看文档android database sqlite
  • 有人可以给出一个 android 中 webview 实现的确切例子吗

    嗨 我正在使用开发 Android 应用程序WebView执行 我跟着官方安卓教程 http developer android com resources tutorials views hello webview html 在 Ecli
  • 无法在 Android 上编译 avahi

    我是交叉编译的新手 我被分配了使用android补丁的任务http avahi org ticket 354 http avahi org ticket 354将 avahi 核心编译为 android ndk build avahi co
  • AltBeacon 服务位于单独的 Android 进程中

    我需要帮助 有一个适用于 Xamarin Android 的应用程序 在其中 启动了一个与 AltBeacon 库配合使用的服务 在此服务中 创建了一个线程 在该线程中不断扫描信标 服务以 StartForeground 启动 该服务应该有
  • 如何在其他呼叫运行时以编程方式合并呼叫(电话会议)

    我的要求是这样的 假设我当时正在拨打一个号码 并且我想以编程方式拨打另一个号码 到目前为止 我所做的是 当某些呼叫已经进行时 我能够呼叫特定号码 例如 假设我正在拨打号码 123 1 分钟后 通过使用Alarm Manger我触发一个事件来
  • org.apache.http.conn.HttpHostConnectException:在 android 中连接到 http://localhost 被拒绝

    我正在制作一个应用程序 在执行它时将图像上传到服务器并将其数据库更新到android中的服务器 它显示错误 Connection to http localhost refused 还有更多错误 我研究了这个问题 发现不是提供 URL 连接
  • 在没有 BluetoothManagerCallback 的情况下调用 getBluetoothService

    我正进入 状态getBluetoothService called with no BluetoothManagerCallback在我的 Android 应用程序中经常出现错误 我不知道是什么原因导致这个或任何有关蓝牙管理器回调的事情 谁
  • Android 解析 JSON 卡在 get 任务上

    我正在尝试解析一些 JSON 数据 我的代码工作了一段时间 我不确定我改变了什么突然破坏了代码 当我运行代码时 我没有收到任何运行时错误或警告 我创建一个新的 AsyncTask 并执行它 当我打电话时 get 在这个新任务中 调试器在此行
  • 调整 SwipeRefreshLayout 高度,将 View 置于其底部

    I have SwipeRefreshLayout里面一个RelativeLayout 问题是SwipeRefreshLayout占据了屏幕上的所有位置 我需要放置一个视图after这个观点 看图片 https i stack imgur
  • Android OptionsMenu问题,背景始终透明

    我的选项菜单总是不显示背景 背景是透明的 有谁知道如何摆脱这个 我的失败起源活动是从另一个自定义活动扩展的 我在 eclipse 上有这个项目 选项菜单工作正常 但自从我迁移到 AndroidStudio 后 选项菜单始终是透明的 我尝试更
  • 如何为 flutter 绘图应用实现橡皮擦功能

    有一个关于通过 flutter 创建绘图应用程序的视频 YouTube https www youtube com watch v yyHhloFMNNA 它支持当用户点击屏幕时绘制线 点 但我找不到像 Android 本机那样擦除用户绘制
  • Android 10 请求 ACTIVITY_RECOGNITION 权限

    我试图遵守 Google 的要求 为 Android 10 请求 ACTIVITY RECOGNITION 权限 但我似乎不明白为什么没有显示权限弹出窗口 就像其他权限 即位置 存储等 一样 我的代码是 if ContextCompat c
  • 按“重置应用程序首选项”后,我的应用程序的所有权限都被撤销

    我开发了一个应用程序 支持Android 6 0 当我在 设置 gt 应用程序 gt 重置应用程序首选项 中重置应用程序首选项时 我的应用程序的所有权限都将被撤销 并且应用程序不会重新启动 撤销权限后未能重新启动应用程序可能会导致许多意外崩
  • 应用程序关闭时单击 Firebase 通知后打开特定活动/片段

    我知道这个问题似乎重复 但根据我的要求 我在网上搜索了很多帖子 但没有任何对我有用 我的要求 我正在使用 Firebase 来获取推送通知 当应用程序打开时意味着一切正常 但我的问题是 如果有任何推送通知出现 应用程序处于后台 关闭意味着我

随机推荐