Using Telegram to send a message

I am trying to send a message to a user of telegram applications, but the intention is to open only the telegram application - it does not select the concatent and does not send the message:

public void shareTelegram(String message) { Intent waIntent = new Intent(Intent.ACTION_SEND); waIntent.setType("text/plain"); waIntent.setPackage("org.telegram.messenger"); if (waIntent != null) { waIntent.putExtra(Intent.EXTRA_TEXT, message);// startActivity(Intent.createChooser(waIntent, "Daniel")); } else { Toast.makeText(getApplicationContext(), "Telegram is not installed", Toast.LENGTH_SHORT).show(); } } 

Is there a way to send a message in full? Can I send a message completely without displaying a telegram?

+5
source share
2 answers

TLSharp is the basic implementation of the Telegram API in C #. See here https://github.com/sochix/TLSharp

+1
source

Try it.

 try { Toast.makeText(getApplicationContext(), "Sharing Via telegram !", Toast.LENGTH_LONG).show(); Intent waIntent = new Intent(Intent.ACTION_SEND); waIntent.setType("image/*"); waIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);//Check if package exists or not. If not then code waIntent.setPackage("org.telegram"); //package check whether telegram is installed waIntent.putExtra(Intent.EXTRA_TEXT, txt.getText().toString());//place your text here startActivity(Intent.createChooser(waIntent, "Share with")); } catch (PackageManager.NameNotFoundException e) { Toast.makeText(SingleItemView.this, "telegram not installed", Toast.LENGTH_SHORT).show(); } 
0
source

Source: https://habr.com/ru/post/1206015/


All Articles