2014-02-08 53 views
0

我已經在意圖ACTION_SEND上在Twitter上創建了共享文本和圖片,我的圖像從我的資產文件夾訪問,以便訪問權限這些資源已經實現了內容提供商和分配的權限,我測試了在Android 4.1.2中共享的動作並正在運行,但是當使用android 4.4進行測試時,我標記了一個錯誤,並且沒有過濾出您無法添加圖像的信息,請將我的內容補充一下,我做了一個測試,爲drawable改變圖像,並將圖像列爲發佈者,但不再通過添加。在Twitter和電子郵件上共享文本和圖像不會在Android 4.4中加載圖像ACTION_SEND

我的內容提供商的宣言中的manifest.xml

<provider 
     android:name="com.domain.app.helper.ImageProvider" 
     android:authorities="com.domain.app" 
     android:grantUriPermissions="true" 
      android:exported="true" 
      android:multiprocess="true" 
     > 
    </provider> 

我的內容提供商類

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; 
import android.util.Log; 

public class ImageProvider extends ContentProvider { 

@Override 
public int delete(Uri arg0, String arg1, String[] arg2) { 
    // TODO Auto-generated method stub 
    return 0; 
} 

@Override 
public String getType(Uri arg0) { 
    // TODO Auto-generated method stub 
    return null; 
} 

@Override 
public Uri insert(Uri arg0, ContentValues arg1) { 
    // TODO Auto-generated method stub 
    return null; 
} 

@Override 
public boolean onCreate() { 
    // TODO Auto-generated method stub 
    return false; 
} 

@Override 
public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3, 
     String arg4) { 
    // TODO Auto-generated method stub 
    return null; 
} 

@Override 
public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) { 
    // TODO Auto-generated method stub 
    return 0; 
} 

@Override 
public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException { 
    AssetManager am = getContext().getAssets(); 
    String file_name = uri.getLastPathSegment(); 
    Log.i("ICP", file_name); 
    if(file_name == null) 
     throw new FileNotFoundException(); 

    AssetFileDescriptor afd = null; 
    try { 
     afd = am.openFd("images/recipes/" + file_name); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    return afd; 
} 

} 

在使用方面的共享

@SuppressLint("DefaultLocale") 
private void share(View v, String nameApp, String infoText, String nameImage) { 

    try { 

     List<Intent> targetedShareIntents = new ArrayList<Intent>(); 
     Intent share = new Intent(android.content.Intent.ACTION_SEND); 
     share.setType("image/jpeg"); 
     List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(share, 0); 
     if (!resInfo.isEmpty()){ 
      for (ResolveInfo info : resInfo) { 
       Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND); 


       if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || 
         info.activityInfo.name.toLowerCase().contains(nameApp)) { 

        //fix Facebook only share link 
        if (info.activityInfo.packageName.toLowerCase().contains("facebook") || 
          info.activityInfo.name.toLowerCase().contains("facebook")){ 

         targetedShare.setType("text/plain"); // put here your mime type 
         targetedShare.putExtra(android.content.Intent.EXTRA_SUBJECT, "The app"); 
         targetedShare.putExtra(android.content.Intent.EXTRA_TEXT, context.getResources().getString(R.string.url_short_app)); 
        } 
        else{ 
         ///targetedShare.setType("image/*"); 
         targetedShare.setType("*/*"); 

         String bodyMsg = infoText + ", " + context.getResources().getString(R.string.firm_shared) +" > " + context.getResources().getString(R.string.url_short_app); 
         targetedShare.putExtra(Intent.EXTRA_TEXT, bodyMsg); 
//this change for test 
//Uri uri = Uri.parse("android.resource://"+context.getPackageName()+"/drawable/table"); 


         Uri theUri = Uri.parse("content://"+context.getPackageName()+"/"+nameImage); 

         targetedShare.putExtra(Intent.EXTRA_STREAM, theUri); 

        } 
        targetedShare.setPackage(info.activityInfo.packageName); 
        targetedShareIntents.add(targetedShare); 

       } 
      } 

      Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share"); 
      chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{})); 
      v.getContext().startActivity(chooserIntent); 
     } 
    } catch (Exception e) { 
     Log.i("ERROR_SHARE", e.toString()); 
    } 
} 

我的內容提供商,我希望你能幫我找出故障有哪些

我假設Android 4.4改變了訪問內容提供商資源的方式

回答

1

是的,Android 4.4 KitKat的確改變了很多東西。由於您使用的是MmsSms提供商發送郵件,它會(默默)拒絕寫入ContentProvider的,除非你是「默認的短信應用」

https://developer.android.com/about/versions/android-4.4.html#SMS

公司正在開發一個「開放」的解決方案對此,但我現在還不知道......它根本不適合你。

相關問題