2015-10-15 76 views
0

我試圖將資產文件夾中的圖像附加到電子郵件。但我沒有得到在相當大的成功,而我已經能夠從資產與ContentProvider的幫助無法將文件附加到Android資產文件夾中的電子郵件應用程序

公共類AssetProvider擴展ContentProvider的{

@Override 
public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException 
{ 
    Log.v("HERREEE", "AssetsGetter: Open asset file"); 
    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 String getType(Uri p1) 
{ 
    // TODO: Implement this method 
    return null; 
} 

@Override 
public int delete(Uri p1, String p2, String[] p3) 
{ 
    // TODO: Implement this method 
    return 0; 
} 

@Override 
public Cursor query(Uri p1, String[] p2, String p3, String[] p4, String p5) 
{ 
    // TODO: Implement this method 
    return null; 
} 

@Override 
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal) 
{ 
    // TODO: Implement this method 
    return super.query(uri, projection, selection, selectionArgs, sortOrder, cancellationSignal); 
} 

@Override 
public Uri insert(Uri p1, ContentValues p2) 
{ 
    // TODO: Implement this method 
    return null; 
} 

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

@Override 
public int update(Uri p1, ContentValues p2, String p3, String[] p4) 
{ 
    // TODO: Implement this method 
    return 0; 
} 

}

代碼張貼鳴叫的圖像從資產文件夾圖像嘰嘰喳喳:

Intent intent = new Intent(Intent.ACTION_SEND); 
      intent.putExtra(Intent.EXTRA_TEXT,"Test tweet"); 
      intent.setType("*/*"); 
      final PackageManager pm = mContext.getPackageManager(); 
      final List<?> activityList = pm.queryIntentActivities(intent, 0); 
      int len = activityList.size(); 
      boolean isFound = false; 
      for (int i = 0; i < len; i++) { 
       final ResolveInfo app = (ResolveInfo) activityList.get(i); 
       if(app.activityInfo.packageName.contains("com.twitter.android")){ 
        isFound = true; 
        final ActivityInfo activity=app.activityInfo; 
        final ComponentName name=new ComponentName(activity.applicationInfo.packageName, activity.name); 
        intent.addCategory(Intent.CATEGORY_LAUNCHER); 
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
        intent.setComponent(name); 
        Uri uri = Uri.parse("content://com.authority/file:///android_asset/image.png"); 
        intent.putExtra(android.content.Intent.EXTRA_STREAM, uri); 
        mContext.startActivity(intent); 
        break; 
       } 
      } 

但是,儘管電子郵件做同樣的,它提供了消息「無法附加空文件」

電子郵件:

Intent intent = new Intent(Intent.ACTION_SEND); 
     intent.setType("*/*"); 
     intent.putExtra(Intent.EXTRA_SUBJECT, "Checkout MY Application"); 
     intent.putExtra(Intent.EXTRA_TEXT, "Test mail"); 
     Uri uri = Uri.parse("content://com.authority/file:///android_asset/image.png")); 
     intent.putExtra(android.content.Intent.EXTRA_STREAM,uri); 
     mContext.startActivity(intent); 

請建議。

在此先感謝。

+0

查看我答案的Edit1。 –

回答

0

最新Facebook應用版本不允許您使用意圖共享文本。您必須使用Facebook SDK共享/發佈帖子,或者您只能分享圖片或網址。

請參考post,它表示Facebook設計團隊故意關閉了預先填寫的信息,因爲它違反了他們的政策。

欲瞭解更多信息,您可以參考這些堆棧溢出問題:

  1. Share Text on Facebook from Android App via ACTION_SEND
  2. Android: How to share image with text on facebook via intent?

編輯1:有一個變通參照此SO Answer

相關問題