Let us say that user opens Twitter app and hits share button for a selected tweet. He then sees my app in the list along with other apps like Gmail, SMS etc.
In OnCreate method of my activity, I process the tweet. Remove short links etc and then call the PostActivity of twitter app. Below code then shows "My tweet" in compose tweet section of twitter app.
Intent intent1 = new Intent("android.intent.action.MAIN");
intent1.setComponent(new ComponentName("com.twitter.android","com.twitter.android.PostActivity"));
intent1.setAction(android.content.Intent.ACTION_SEND);
intent1.putExtra(android.content.Intent.EXTRA_TEXT,"my tweet");
intent1.setType("text/plain");
startActivity(intent1);
What i want to do is ,before i call PostActivity, i need make 100% sure that my activity was called from twitter app.
Related
I want to get something like this:
Download my app here
...but in a Telegram message when the user clicks a button in my Android app. Note the link in the word here.
I have the following code inside the button's onClickListener callback:
String msg = "Download my app here";
Intent myIntent = new Intent(Intent.ACTION_SEND);
myIntent.setType("text/plain");
myIntent.putExtra(Intent.EXTRA_TEXT, msg);
startActivity(Intent.createChooser(myIntent, "Share with"));
However, the above code does not create a clikable link on the word here, instead it explicitly shows what I have in the msg variable.
I tried with HTML:
This is an example
...and with markdown:
[This is an example](https://example.com)
Both cases don't work for my.
How to share programmatically a message with a hyperlink from my Android app to Telegram without using bots?
Please, note in my question that I don't want to use Telegram bots, like:
https://api.telegram.org/bot<BOT_TOKEN>/sendMessage?text=%3Ca+href%3D%27url.com%27%3Eword%3C%2Fa%3E&chat_id=<chat_id>&parse_mode=HTML
When a user clicks a button in my app, it's supposed to launch an SMS app. To to this, I simply fired an intent.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", "+234000000000", null));
intent.putExtra("sms_body", "Hello!"));
if (intent.resolveActivity(getActivity().getPackageManager()) != null) startActivity(intent);
This works perfectly fine! The only problem is that Facebook Messenger is among the list of apps that show up and I don't want that.
How can I filter this list and remove specific apps like Messenger?
Yes, you can restrict your app to open just android default messaging app.
Uri uri = Uri.parse("sms:+444498494984");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
//android sms app package name
intent.setPackage("com.google.android.apps.messaging");
intent.putExtra("sms_body", "message to send");
if (intent.resolveActivity(getPackageManager()) != null)
{
startActivity(intent);
}
It is trying to give the user a choice on their favourite SMS app, Don't forget that Facebook Messenger can also manage SMS now that is why it is showing up as a choice. In my experience, Unless the user selects 'always' it can't be avoided. Imagine if the user has other apps to manage SMS we can't force them to use our preferred messaging app.
https://developer.android.com/preview/privacy/background-activity-starts
From this, it results that my payment app, which shows an Activity when a NFC transaction is performed, will not be able anymore to show anything to the user.
Has anyone have a clue what would be the new approach ?
Thanks!
I currently use the NFC service and it starts an Activity intent.
Intent intent = new Intent(mApplicationContext, PaymentActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
mApplicationContext.startActivity(intent);
The Activity should be shown. It works now, but from Android Q, it won't
According to the link, if you are having a HostApduService, then your app should work the same in Android Q.
If that is not your case, the simplest work around is to get "Draw over other apps" permissions. You can open activities if the app has been granted the SYSTEM_ALERT_WINDOW permission by the user. I have tested this and working.
Technically, you are showing something on top of other apps without user's interaction, so this might be the right way to go.
Im having problems with notifications in android. Im making a chat client.
when my client tells me that someone is chatting with me from a previous chat, and I push it, it opens up a new instance of that chat. I want it to work like the facebook mesenger, that is when I push the notification it opens up the chat for the person which is trying to speak to me, instead of an empty chat window.
regards.
In your Notification you can set a Intent:
Notification n;
n.setContentIntent(intent)
In your intent you will set the activity that will be started and also you can put extras, like an ID of the conversation or something that can be identified latter.
Because when you start this new chat activity on onCreate() you need to check if there is extras, take the ID for example and search for your conversation history and write all your logic.
Currently I have a button that when pushed calls the Intent below.
Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { toString });
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,
"New Files from Safe Storage");
sharingIntent.setType("text/*");
startActivity(sharingIntent);
This intent then uses the default share activity to share the email with my attached file (which i took out for this example). When this code goes off it opens the gmail activity for me, but i still need to push the send button even though everything is filled in. Is there a way to make this instead just send automatically without showing the user the activity and having them forced to push "Send"?
Have a look on the following link, there is an answer for your question.
Sending Email in Android using JavaMail API without using the default android app(Builtin Email application)