无法使用Android中的Content Provider通过BlueTooth共享图像?

时间:2014-02-07 18:33:49

标签: java android android-contentprovider

这是负责通过Intent.Share共享图像的ShareImageClass,但不幸的是我无法附加图像和蓝牙我收到消息“文件未发送”而图像在我的资产文件夹中。    的 ShareImageClass.java

package com.jamia.binoria;
import java.io.FileNotFoundException;
import java.io.IOException;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.net.Uri;

public class ShareImageClass extends ContentProvider
{
    @Override
    public AssetFileDescriptor openAssetFile(Uri uri,String mode) throws FileNotFoundException {
        AssetManager am = getContext().getAssets();
        String file_name = uri.getLastPathSegment();
        if(file_name == null) 
            throw new FileNotFoundException();
        AssetFileDescriptor afd = null;
        try {
            afd = am.openFd(file_name);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return afd;//super.openAssetFile(uri, mode);
    }
    @Override
    public int delete(Uri arg0, String arg1, String[] arg2) {
        return 0;
    }

    @Override
    public String getType(Uri arg0) {
        return null;
    }

    @Override
    public Uri insert(Uri arg0, ContentValues arg1) {
        return null;
    }

    @Override
    public boolean onCreate() {
        return false;
    }

    @Override
    public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3, String arg4) {
        return null;
    }

    @Override
    public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
        return 0;
    }

}

活动按钮将共享图片onClick

shareButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
          // shareImage();  
            Uri theUri = Uri.parse("content://com.jamia.binoria/quran_o_hadess_ques1_fatwa2.png");
            Intent theIntent = new Intent(Intent.ACTION_SEND);
            theIntent.setType("image/png");
            theIntent.putExtra(Intent.EXTRA_STREAM,theUri);
            theIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject for message");                        
            theIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Body for message");
            startActivity(Intent.createChooser(theIntent,"share image"));
        }
    });

manifest资源配置文件

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jamia.banoria"
    android:versionCode="1"
    android:versionName="1.0"
   >
<uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="17" /> 
<application 
android:allowBackup="true" 
android:icon="@drawable/app_icon2"  
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
android:label="@string/app_name">
        <activity
            android:name="com.jamia.binoria.SplashActivity"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 <provider android:name="com.jamia.binoria.ShareImageClass"               
  android:authorities="com.jamia.binoria"/>
    </application>

</manifest>

0 个答案:

没有答案