2016-08-11 3 views
0

Я новичок в Android и сталкивается с проблемой совместного использования изображения через совместное намерение. Я много искал в googled, пробовал разные вещи, но до сих пор не смог найти решение.Android Share Intent Image Sharing не работает

Мой код:

  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. Вот мой код на Unity Side:

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
Intent shareIntent = new Intent(); 
shareIntent.setAction(Intent.ACTION_SEND); 
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage); 
shareIntent.setType("image/jpeg"); 
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to))); 

Это может помочь.

+0

NOPS не работает. – 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(); 
     } 
Смежные вопросы