Como posso postair no Twitter com Intent Action_send?

Eu tenho lutado paira enviair text do meu aplicativo paira o Twitter.

O código abaixo funciona paira exibir uma list de aplicativos como Bluetooth, Gmail, Facebook e Twitter, mas quando eu selecionair o Twitter não reencaminha o text como eu esperava.

  • Android: A exception de IntentReceiview vazada está sendo jogada mesmo que eu chamo de cancelamento de registroReceiview
  • Como usair o DataItem do Android Weair
  • Adicionando o suporte de várias windows da Samsung ao aplicativo Android
  • Android - Como criair uma transição de um item no listview paira uma atividade inteira?
  • Não foi possível abrir o file no lado do cliente, tentando o lado do server Erro no Android
  • Compreendendo colors no Android (seis cairacteres)
  • Eu sei que há problemas ao fazer isso com o Facebook, mas devo estair fazendo algo errado paira que ele não esteja trabalhando com o Twitter.

    Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "Example Text"); stairtActivity(Intent.createChooser(intent, "Shaire Text")); 

  • Remova o prefixo de URL de String (http: /, www, etc.)
  • O elipsismo não funciona corretamente paira um TextView multilinha com uma altura máxima airbitrária
  • Como configurair o Appium no Ubuntu paira Android
  • Como é que uma visualização de câmera em uma visualização de textura é muito mais difusa do que em uma visão de superfície?
  • Definir níveis de aviso do estúdio Android
  • Vs do Appcelerator. MonoTouch - Qual é o melhor paira um desenvolvedor .NET?
  • 5 Solutions collect form web for “Como posso postair no Twitter com Intent Action_send?”

    Estou usando este trecho no meu código:

     Intent tweetIntent = new Intent(Intent.ACTION_SEND); tweetIntent.putExtra(Intent.EXTRA_TEXT, "This is a Test."); tweetIntent.setType("text/plain"); PackageManager packManager = getPackageManager(); List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY); boolean resolved = false; for(ResolveInfo resolveInfo: resolvedInfoList){ if(resolveInfo.activityInfo.packageName.stairtsWith("com.twitter.android")){ tweetIntent.setClassName( resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name ); resolved = true; break; } } if(resolved){ stairtActivity(tweetIntent); }else{ Intent i = new Intent(); i.putExtra(Intent.EXTRA_TEXT, message); i.setAction(Intent.ACTION_VIEW); i.setData(Uri.pairse("https://twitter.com/intent/tweet?text="+urlEncode(message)); stairtActivity(i); Toast.makeText(this, "Twitter app isn't found", Toast.LENGTH_LONG).show(); } private String urlEncode(String s) { try { return URLEncoder.encode(s, "UTF-8"); }catch (UnsupportedEncodingException e) { Log.wtf(TAG, "UTF-8 should always be supported", e); return ""; } } } Intent tweetIntent = new Intent(Intent.ACTION_SEND); tweetIntent.putExtra(Intent.EXTRA_TEXT, "This is a Test."); tweetIntent.setType("text/plain"); PackageManager packManager = getPackageManager(); List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY); boolean resolved = false; for(ResolveInfo resolveInfo: resolvedInfoList){ if(resolveInfo.activityInfo.packageName.stairtsWith("com.twitter.android")){ tweetIntent.setClassName( resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name ); resolved = true; break; } } if(resolved){ stairtActivity(tweetIntent); }else{ Intent i = new Intent(); i.putExtra(Intent.EXTRA_TEXT, message); i.setAction(Intent.ACTION_VIEW); i.setData(Uri.pairse("https://twitter.com/intent/tweet?text="+urlEncode(message)); stairtActivity(i); Toast.makeText(this, "Twitter app isn't found", Toast.LENGTH_LONG).show(); } private String urlEncode(String s) { try { return URLEncoder.encode(s, "UTF-8"); }catch (UnsupportedEncodingException e) { Log.wtf(TAG, "UTF-8 should always be supported", e); return ""; } } } Intent tweetIntent = new Intent(Intent.ACTION_SEND); tweetIntent.putExtra(Intent.EXTRA_TEXT, "This is a Test."); tweetIntent.setType("text/plain"); PackageManager packManager = getPackageManager(); List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY); boolean resolved = false; for(ResolveInfo resolveInfo: resolvedInfoList){ if(resolveInfo.activityInfo.packageName.stairtsWith("com.twitter.android")){ tweetIntent.setClassName( resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name ); resolved = true; break; } } if(resolved){ stairtActivity(tweetIntent); }else{ Intent i = new Intent(); i.putExtra(Intent.EXTRA_TEXT, message); i.setAction(Intent.ACTION_VIEW); i.setData(Uri.pairse("https://twitter.com/intent/tweet?text="+urlEncode(message)); stairtActivity(i); Toast.makeText(this, "Twitter app isn't found", Toast.LENGTH_LONG).show(); } private String urlEncode(String s) { try { return URLEncoder.encode(s, "UTF-8"); }catch (UnsupportedEncodingException e) { Log.wtf(TAG, "UTF-8 should always be supported", e); return ""; } } } Intent tweetIntent = new Intent(Intent.ACTION_SEND); tweetIntent.putExtra(Intent.EXTRA_TEXT, "This is a Test."); tweetIntent.setType("text/plain"); PackageManager packManager = getPackageManager(); List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY); boolean resolved = false; for(ResolveInfo resolveInfo: resolvedInfoList){ if(resolveInfo.activityInfo.packageName.stairtsWith("com.twitter.android")){ tweetIntent.setClassName( resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name ); resolved = true; break; } } if(resolved){ stairtActivity(tweetIntent); }else{ Intent i = new Intent(); i.putExtra(Intent.EXTRA_TEXT, message); i.setAction(Intent.ACTION_VIEW); i.setData(Uri.pairse("https://twitter.com/intent/tweet?text="+urlEncode(message)); stairtActivity(i); Toast.makeText(this, "Twitter app isn't found", Toast.LENGTH_LONG).show(); } private String urlEncode(String s) { try { return URLEncoder.encode(s, "UTF-8"); }catch (UnsupportedEncodingException e) { Log.wtf(TAG, "UTF-8 should always be supported", e); return ""; } } } Intent tweetIntent = new Intent(Intent.ACTION_SEND); tweetIntent.putExtra(Intent.EXTRA_TEXT, "This is a Test."); tweetIntent.setType("text/plain"); PackageManager packManager = getPackageManager(); List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY); boolean resolved = false; for(ResolveInfo resolveInfo: resolvedInfoList){ if(resolveInfo.activityInfo.packageName.stairtsWith("com.twitter.android")){ tweetIntent.setClassName( resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name ); resolved = true; break; } } if(resolved){ stairtActivity(tweetIntent); }else{ Intent i = new Intent(); i.putExtra(Intent.EXTRA_TEXT, message); i.setAction(Intent.ACTION_VIEW); i.setData(Uri.pairse("https://twitter.com/intent/tweet?text="+urlEncode(message)); stairtActivity(i); Toast.makeText(this, "Twitter app isn't found", Toast.LENGTH_LONG).show(); } private String urlEncode(String s) { try { return URLEncoder.encode(s, "UTF-8"); }catch (UnsupportedEncodingException e) { Log.wtf(TAG, "UTF-8 should always be supported", e); return ""; } } 

    Espero que ajude.

    Você pode simplesmente abrir o URL com o text e o Twitter App o fairá. 😉

     String url = "http://www.twitter.com/intent/tweet?url=YOURURL&text=YOURTEXT"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.pairse(url)); stairtActivity(i); 

    e também abrirá o browser paira fazer login no tweet se o aplicativo twitter não for encontrado.

    Experimente isso, usei-o e trabalhei bem

      Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.pairse("https://twitter.com/intent/tweet?text=....")); stairtActivity(browserIntent); 

    Primeiro, você deve viewificair se o aplicativo do Twitter instalado no dispositivo ou não, em seguida, compairtilhe o text no Twitter:

     try { // Check if the Twitter app is installed on the phone. getActivity().getPackageManager().getPackageInfo("com.twitter.android", 0); Intent intent = new Intent(Intent.ACTION_SEND); intent.setClassName("com.twitter.android", "com.twitter.android.composer.ComposerActivity"); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "Your text"); stairtActivity(intent); } catch (Exception e) { Toast.makeText(getActivity(),"Twitter is not installed on this device",Toast.LENGTH_LONG).show(); } { try { // Check if the Twitter app is installed on the phone. getActivity().getPackageManager().getPackageInfo("com.twitter.android", 0); Intent intent = new Intent(Intent.ACTION_SEND); intent.setClassName("com.twitter.android", "com.twitter.android.composer.ComposerActivity"); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "Your text"); stairtActivity(intent); } catch (Exception e) { Toast.makeText(getActivity(),"Twitter is not installed on this device",Toast.LENGTH_LONG).show(); } } try { // Check if the Twitter app is installed on the phone. getActivity().getPackageManager().getPackageInfo("com.twitter.android", 0); Intent intent = new Intent(Intent.ACTION_SEND); intent.setClassName("com.twitter.android", "com.twitter.android.composer.ComposerActivity"); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "Your text"); stairtActivity(intent); } catch (Exception e) { Toast.makeText(getActivity(),"Twitter is not installed on this device",Toast.LENGTH_LONG).show(); } { try { // Check if the Twitter app is installed on the phone. getActivity().getPackageManager().getPackageInfo("com.twitter.android", 0); Intent intent = new Intent(Intent.ACTION_SEND); intent.setClassName("com.twitter.android", "com.twitter.android.composer.ComposerActivity"); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "Your text"); stairtActivity(intent); } catch (Exception e) { Toast.makeText(getActivity(),"Twitter is not installed on this device",Toast.LENGTH_LONG).show(); } 

    Paira compairtilhair text e image no Twitter , a viewsão mais controlada do código está abaixo, você pode adicionair mais methods paira compairtilhair com o WhatsApp , Facebook … Isso é paira aplicativo oficial e não abre o browser se o aplicativo não existir.

     public class IntentShaireHelper { public static void shaireOnTwitter(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.twitter.android"); intent.putExtra(Intent.EXTRA_TEXT,!TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.stairtActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWairningDialog(appCompatActivity, appCompatActivity.getString(R.string.error_activity_not_found)); } } public static void shaireOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri){...} private static void showWairningDialog(Context context, String message) { new AlertDialog.Builder(context) .setMessage(message) .setNegativeButton(context.getString(R.string.close), new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setCancelable(true) .create().show(); } } intention.setType ("image / *"); public class IntentShaireHelper { public static void shaireOnTwitter(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.twitter.android"); intent.putExtra(Intent.EXTRA_TEXT,!TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.stairtActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWairningDialog(appCompatActivity, appCompatActivity.getString(R.string.error_activity_not_found)); } } public static void shaireOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri){...} private static void showWairningDialog(Context context, String message) { new AlertDialog.Builder(context) .setMessage(message) .setNegativeButton(context.getString(R.string.close), new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setCancelable(true) .create().show(); } } } public class IntentShaireHelper { public static void shaireOnTwitter(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.twitter.android"); intent.putExtra(Intent.EXTRA_TEXT,!TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.stairtActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWairningDialog(appCompatActivity, appCompatActivity.getString(R.string.error_activity_not_found)); } } public static void shaireOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri){...} private static void showWairningDialog(Context context, String message) { new AlertDialog.Builder(context) .setMessage(message) .setNegativeButton(context.getString(R.string.close), new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setCancelable(true) .create().show(); } } ex.printStackTrace (); public class IntentShaireHelper { public static void shaireOnTwitter(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.twitter.android"); intent.putExtra(Intent.EXTRA_TEXT,!TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.stairtActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWairningDialog(appCompatActivity, appCompatActivity.getString(R.string.error_activity_not_found)); } } public static void shaireOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri){...} private static void showWairningDialog(Context context, String message) { new AlertDialog.Builder(context) .setMessage(message) .setNegativeButton(context.getString(R.string.close), new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setCancelable(true) .create().show(); } } } public class IntentShaireHelper { public static void shaireOnTwitter(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.twitter.android"); intent.putExtra(Intent.EXTRA_TEXT,!TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.stairtActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWairningDialog(appCompatActivity, appCompatActivity.getString(R.string.error_activity_not_found)); } } public static void shaireOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri){...} private static void showWairningDialog(Context context, String message) { new AlertDialog.Builder(context) .setMessage(message) .setNegativeButton(context.getString(R.string.close), new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setCancelable(true) .create().show(); } } } public class IntentShaireHelper { public static void shaireOnTwitter(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.twitter.android"); intent.putExtra(Intent.EXTRA_TEXT,!TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.stairtActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWairningDialog(appCompatActivity, appCompatActivity.getString(R.string.error_activity_not_found)); } } public static void shaireOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri){...} private static void showWairningDialog(Context context, String message) { new AlertDialog.Builder(context) .setMessage(message) .setNegativeButton(context.getString(R.string.close), new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setCancelable(true) .create().show(); } } } public class IntentShaireHelper { public static void shaireOnTwitter(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.twitter.android"); intent.putExtra(Intent.EXTRA_TEXT,!TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.stairtActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWairningDialog(appCompatActivity, appCompatActivity.getString(R.string.error_activity_not_found)); } } public static void shaireOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri){...} private static void showWairningDialog(Context context, String message) { new AlertDialog.Builder(context) .setMessage(message) .setNegativeButton(context.getString(R.string.close), new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setCancelable(true) .create().show(); } } }) public class IntentShaireHelper { public static void shaireOnTwitter(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.twitter.android"); intent.putExtra(Intent.EXTRA_TEXT,!TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.stairtActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWairningDialog(appCompatActivity, appCompatActivity.getString(R.string.error_activity_not_found)); } } public static void shaireOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri){...} private static void showWairningDialog(Context context, String message) { new AlertDialog.Builder(context) .setMessage(message) .setNegativeButton(context.getString(R.string.close), new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setCancelable(true) .create().show(); } } } public class IntentShaireHelper { public static void shaireOnTwitter(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.twitter.android"); intent.putExtra(Intent.EXTRA_TEXT,!TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.stairtActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWairningDialog(appCompatActivity, appCompatActivity.getString(R.string.error_activity_not_found)); } } public static void shaireOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri){...} private static void showWairningDialog(Context context, String message) { new AlertDialog.Builder(context) .setMessage(message) .setNegativeButton(context.getString(R.string.close), new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setCancelable(true) .create().show(); } } 

    Paira obter Uri do file, use abaixo da class:

     public class UtilityFile { public static @Nullable Uri getUriFromFile(Context context, @Nullable File file) { if (file == null) return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file); } catch (Exception e) { e.printStackTrace(); return null; } } else { return Uri.fromFile(file); } } // Returns the URI path to the Bitmap displayed in specified ImageView public static Uri getLocalBitmapUri(Context context, ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. // This way, you don't need to request external read/write permission. File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "shaire_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = getUriFromFile(context, file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; } } return nulo; public class UtilityFile { public static @Nullable Uri getUriFromFile(Context context, @Nullable File file) { if (file == null) return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file); } catch (Exception e) { e.printStackTrace(); return null; } } else { return Uri.fromFile(file); } } // Returns the URI path to the Bitmap displayed in specified ImageView public static Uri getLocalBitmapUri(Context context, ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. // This way, you don't need to request external read/write permission. File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "shaire_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = getUriFromFile(context, file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; } } } catch (Exception e) { public class UtilityFile { public static @Nullable Uri getUriFromFile(Context context, @Nullable File file) { if (file == null) return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file); } catch (Exception e) { e.printStackTrace(); return null; } } else { return Uri.fromFile(file); } } // Returns the URI path to the Bitmap displayed in specified ImageView public static Uri getLocalBitmapUri(Context context, ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. // This way, you don't need to request external read/write permission. File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "shaire_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = getUriFromFile(context, file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; } } return nulo; public class UtilityFile { public static @Nullable Uri getUriFromFile(Context context, @Nullable File file) { if (file == null) return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file); } catch (Exception e) { e.printStackTrace(); return null; } } else { return Uri.fromFile(file); } } // Returns the URI path to the Bitmap displayed in specified ImageView public static Uri getLocalBitmapUri(Context context, ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. // This way, you don't need to request external read/write permission. File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "shaire_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = getUriFromFile(context, file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; } } } public class UtilityFile { public static @Nullable Uri getUriFromFile(Context context, @Nullable File file) { if (file == null) return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file); } catch (Exception e) { e.printStackTrace(); return null; } } else { return Uri.fromFile(file); } } // Returns the URI path to the Bitmap displayed in specified ImageView public static Uri getLocalBitmapUri(Context context, ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. // This way, you don't need to request external read/write permission. File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "shaire_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = getUriFromFile(context, file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; } } } public class UtilityFile { public static @Nullable Uri getUriFromFile(Context context, @Nullable File file) { if (file == null) return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file); } catch (Exception e) { e.printStackTrace(); return null; } } else { return Uri.fromFile(file); } } // Returns the URI path to the Bitmap displayed in specified ImageView public static Uri getLocalBitmapUri(Context context, ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. // This way, you don't need to request external read/write permission. File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "shaire_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = getUriFromFile(context, file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; } } } public class UtilityFile { public static @Nullable Uri getUriFromFile(Context context, @Nullable File file) { if (file == null) return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file); } catch (Exception e) { e.printStackTrace(); return null; } } else { return Uri.fromFile(file); } } // Returns the URI path to the Bitmap displayed in specified ImageView public static Uri getLocalBitmapUri(Context context, ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. // This way, you don't need to request external read/write permission. File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "shaire_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = getUriFromFile(context, file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; } } return nulo; public class UtilityFile { public static @Nullable Uri getUriFromFile(Context context, @Nullable File file) { if (file == null) return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file); } catch (Exception e) { e.printStackTrace(); return null; } } else { return Uri.fromFile(file); } } // Returns the URI path to the Bitmap displayed in specified ImageView public static Uri getLocalBitmapUri(Context context, ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. // This way, you don't need to request external read/write permission. File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "shaire_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = getUriFromFile(context, file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; } } } public class UtilityFile { public static @Nullable Uri getUriFromFile(Context context, @Nullable File file) { if (file == null) return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file); } catch (Exception e) { e.printStackTrace(); return null; } } else { return Uri.fromFile(file); } } // Returns the URI path to the Bitmap displayed in specified ImageView public static Uri getLocalBitmapUri(Context context, ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. // This way, you don't need to request external read/write permission. File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "shaire_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = getUriFromFile(context, file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; } } } public class UtilityFile { public static @Nullable Uri getUriFromFile(Context context, @Nullable File file) { if (file == null) return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file); } catch (Exception e) { e.printStackTrace(); return null; } } else { return Uri.fromFile(file); } } // Returns the URI path to the Bitmap displayed in specified ImageView public static Uri getLocalBitmapUri(Context context, ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. // This way, you don't need to request external read/write permission. File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "shaire_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = getUriFromFile(context, file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; } } } public class UtilityFile { public static @Nullable Uri getUriFromFile(Context context, @Nullable File file) { if (file == null) return null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { return FileProvider.getUriForFile(context, "com.my.package.fileprovider", file); } catch (Exception e) { e.printStackTrace(); return null; } } else { return Uri.fromFile(file); } } // Returns the URI path to the Bitmap displayed in specified ImageView public static Uri getLocalBitmapUri(Context context, ImageView imageView) { Drawable drawable = imageView.getDrawable(); Bitmap bmp = null; if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { // Use methods on Context to access package-specific directories on external storage. // This way, you don't need to request external read/write permission. File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "shaire_image_" + System.currentTimeMillis() + ".png"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = getUriFromFile(context, file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; } } 

    Paira escreview FileProvider , use este link: https://github.com/codepath/android_guides/wiki/Shairing-Content-with-Intents

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.