无法使用我的应用程序设置StreamProvider

时间:2016-02-23 09:04:43

标签: android android-contentprovider commonsware-cwac

我正在尝试让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>

1 个答案:

答案 0 :(得分:2)

<provider> ... </provider>应位于<application>