0

I am trying to get the StreamProvider to share images in my assets/stamps folder, but am doing something wrong. Sorry for asking such a trivial question. Using the demo as an example this is where I am at.

I added this to my android manifest although it says the provider element is not allowed here

<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>

my paths.xml contains this

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

The activity where I am sending the image

assetManager = getResources().getAssets();

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

    }

I use this to populate my gridview and then set the onclick method

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"));

modified getUri method

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());
}

Thanks for taking the time to look at this. I am still relatively new to android programming.

Edit: I am currently using motorola moto g android 5.1 as test device

Edit 2: full manifest file

<?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>
user3074140
  • 733
  • 3
  • 13
  • 30
  • what's the full manifest look like? What's the full error message? You probably added it inside an activity or some trivial "typo" like that – Gavriel Feb 23 '16 at 09:12
  • I added the full manifest i added the provider tag outside of application tag.......ohhh. – user3074140 Feb 23 '16 at 09:16
  • 1
    I'd suggest editing question title to something more related to the problem not your stupidity :) If you need to share that feeling, put that in question body. I just did the edit for you – Marcin Orlowski Feb 23 '16 at 09:19
  • I moved the provider element but am still having issues I am sending the image to a Line chat, but Line says an error occurred. – user3074140 Feb 23 '16 at 09:28
  • @user3074140, that seems to be unrelated to the question, and we also lack information, please open a separate, detailed question about your new problem – Gavriel Feb 23 '16 at 09:32
  • I don't know what "a Line chat" is. I also don't know why you have `setPackage()` on the `Intent`, or what that value is supposed to be. Assuming that "a Line chat" refers to a third-party app, check LogCat for warnings and errors coming from that app. For example, you might find a stack trace. If you do, open up a fresh Stack Overflow question linking to this one (for the code), with the stack trace from the third-party app. Also, if you have not done so already, make sure that you're on `0.3.1` of the `cwac-provider` artifact. – CommonsWare Feb 23 '16 at 11:49

1 Answers1

2

<provider> ... </provider> should be inside <application>

Gavriel
  • 18,880
  • 12
  • 68
  • 105