2016-08-11 5 views
0

Android에 익숙하지 않아 공유 의도를 통해 이미지를 공유하는 중에 문제가 발생했습니다. 나는 많은 봤 거든, 여러 가지 시도했지만 여전히 해결책을 찾을 수 없습니다.Android 공유 인텐시브 이미지 공유가 작동하지 않음

내 코드는 다음과 같습니다

내가 URI를 확인했다
  Intent shareIntent = new Intent(Intent.ACTION_SEND); 
      shareIntent.setType("image/*"); 
      shareIntent.putExtra(Intent.EXTRA_STREAM,uri); 
      this.startActivityForResult(Intent.createChooser(shareIntent,"Share with"),12); 

, 저장 한 파일은 비트 맵과 그 반환 파일입니다. 그러나 공유하는 동안 표시되는 이미지는 유효하지 않습니다. Gmail에서 첨부 파일을 첨부 할 수 없다고 말하면 메시지 앱에서 이미지를로드 할 수 없습니다.

텍스트 공유가 정상적으로 작동합니다.

기본적으로 Unity 용 플러그인을 작성 중입니다. 여기 유니티 사이드에 내 코드입니다 : 내가 목적지와 URI를 기록하고

string destination = Path.Combine(Application.persistentDataPath,"sharingImage" + ".png"); 
      if (!File.Exists(destination)) { 
       print("creating new file"); 
       File.Create(destination); 
      } 
      File.WriteAllBytes(destination, bytes); 

      print("destination= "+destination); 

      AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"); 
      AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse","file://" + destination); 

      using (AndroidJavaClass pluginClass = new AndroidJavaClass("com.kashiftasneem.sharelib.ShareController")) { 

       AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 
       AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"); 

       pluginClass.CallStatic("Share",message,uriObject,jo,gameObject.name,destination); 
      } 

, 그들은은 다음과 같습니다

대상 = /data/data/com.kashiftasneem.shareandroidplugin2/files/sharingImage.png

URI = 파일 : ///data/data/com.kashiftasneem.shareandroidplugin2/files/sharingImage.png

답변

0
,

도움이 될 수 있습니다.

+0

NOP를 작동하지 않았다. – kashif789us

+0

나는 그것이 uri에 문제가 있을지도 모른다라고 생각한다. – Singh

+0

uri와 관련된 더 많은 정보를 포함하도록 질문을 편집했습니다. – kashif789us

0

이 코드를보십시오 :

 Bitmap bitmap = getBitmapFromView(idForSaveView); 
     try { 
      File file = new File(this.getExternalCacheDir(), "appdiam.png"); 
      FileOutputStream fOut = new FileOutputStream(file); 
      bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); 
      fOut.flush(); 
      //fOut.close(); 
      file.setReadable(true, false); 
      final Intent intent = new Intent(android.content.Intent.ACTION_SEND); 
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); 
      intent.setType("image/png"); 
      startActivity(Intent.createChooser(intent, "Share image via")); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
관련 문제