【问题标题】:Trouble setting up StreamProvider with my application使用我的应用程序设置 StreamProvider 时遇到问题
【发布时间】:2016-02-23 09:04:43
【问题描述】:

我正在尝试让 StreamProvider 共享我的 assets/stamps 文件夹中的图像,但我做错了。很抱歉问了这么一个微不足道的问题。以演示为例,这就是我所在的地方。

我将此添加到我的 android 清单中,尽管它说此处不允许提供提供程序元素

<provider
    android:name="com.example.np161.stamp2.StreamProvider"
    android:authorities="com.example.np161.stamp2"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="com.example.np161.STREAM_PROVIDER_PATHS"
        android:resource="@xml/paths"/>
</provider>

我的 paths.xml 包含这个

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <asset name="assets" path="stamps" />
</paths>

我发送图片的活动

assetManager = getResources().getAssets();

    try {
        images = getAssets().list("stamps");
        listImages = new ArrayList<String>(Arrays.asList(images));
    }catch(IOException e){

    }

我用它来填充我的gridview,然后设置onclick方法

gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            String path = "assets/" + listImages.get(position);

            Intent shareIntent = new Intent(Intent.ACTION_SEND);

            shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            shareIntent.putExtra(Intent.EXTRA_STREAM, getUri(path));

            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            shareIntent.setType("image/png");

            shareIntent.setPackage(ChatHeadService.app);

            startActivity(Intent.createChooser(shareIntent, "Share with"));

修改getUri方法

private static final Uri PROVIDER= Uri.parse("content://com.example.np161.stamp2");

private Uri getUri(String pathEnd) {
    String path=pathEnd;

    return(PROVIDER.buildUpon().path(path).build());
}

感谢您抽出宝贵时间查看此内容。我对 android 编程还是比较陌生。

编辑:我目前正在使用 motorola moto g android 5.1 作为测试设备

编辑 2:完整清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.np161.stamp2" >

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.GET_TOP_ACTIVITY_INFO" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission
    android:name="android.permission.PACKAGE_USAGE_STATS"
    tools:ignore="ProtectedPermissions" />

<application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="Stickers 2"
    android:supportsRtl="true"
    android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
    <activity
        android:name=".MainActivity"
        android:label="Stickers 2"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" >
    </activity>
    <activity
        android:name=".chatHeadPreviewActivity"
        android:launchMode="singleInstance"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.Transparent" />
    <activity
        android:name=".HomeScreen"
        android:launchMode="singleInstance"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="Stickers 2"
        android:screenOrientation="portrait"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service android:name=".ChatHeadService" />

    <activity
        android:name=".newActivity"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".Settings"
        android:launchMode="singleInstance"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".Language"
        android:screenOrientation="portrait"
        android:label="@string/title_activity_language" >
    </activity>
</application>

<provider
    android:name="com.example.np161.stamp2.StreamProvider"
    android:authorities="com.example.np161.stamp2"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="com.example.np161.STREAM_PROVIDER_PATHS"
        android:resource="@xml/paths"/>
</provider>


</manifest>

【问题讨论】:

  • 完整清单是什么样的?完整的错误信息是什么?您可能将其添加到活动中或类似的一些琐碎的“错字”中
  • 我添加了完整的清单我在应用程序标记之外添加了提供程序标记.......哦。
  • 我建议将问题标题编辑为与问题更相关的内容,而不是您的愚蠢:) 如果您需要分享这种感觉,请将其放在问题正文中。我刚刚为你做了编辑
  • 我移动了提供程序元素,但仍然遇到问题我将图像发送到 Line 聊天,但 Line 说发生了错误。
  • @user3074140,这似乎与问题无关,而且我们也缺乏信息,请针对您的新问题另开一个详细的问题

标签: android android-contentprovider commonsware-cwac


【解决方案1】:

&lt;provider&gt; ... &lt;/provider&gt; 应该在 &lt;application&gt; 里面

【讨论】:

    猜你喜欢
    • 2018-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 1970-01-01
    相关资源
    最近更新 更多