I need to open Telegram from my own Android App prepopulating both the message and recipient (and not having to choose betwenn Chrome or Telegram),
I achieved the first one with this code:
final String appName = "org.telegram.messenger";
Intent tIntent = new Intent(Intent.ACTION_SEND);
tIntent.setType("text/plain");
tIntent.setPackage(appName);
tIntent.putExtra(Intent.EXTRA_TEXT, msg);
mUIActivity.startActivity(tIntent);
And the second one with this code:
Intent tIntent = new Intent(Intent.ACTION_VIEW);
tIntent.setData(Uri.parse("http://telegram.me/USERID"));
startActivity(tIntent);
(I removed all checks like isTelegramInstalled for simplicity)
I tried to mix the two methods
adding some intent extra such as msg we get to this code that will open Telegram, in one click, with pre-populated message and recipient:
Intent telegramIntent = new Intent(Intent.ACTION_SEND);
tIntent.setDataAndType(Uri.parse("http://telegram.me/username"), "text/plain");
final String appName = "org.telegram.messenger";
tIntent.setPackage(appName);
tIntent.putExtra(Intent.EXTRA_TEXT, "hello");
startActivity(tIntent);
…aaand it didn’t work!
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND dat=http://telegram.me/... flg=0x1 pkg=org.telegram.messenger clip={null T:hello} (has extras) }
Any idea how to achieve this?
2
Answers
In your case
Telegram chat activity class has a different name and you pass other activity name.
Find which class use telegram for chat activity and pass it on set package method
Please try below function for open Telegram
I hope this can help You!
Thank You.