I've managed to send SMS containing verification code from my app using SmsManager and SmsReceiver. But it's just like a normal SMS message. I wonder if I can tell to device that the SMS is containing code, thus user's device will automatically open popup dialog to ask user wether they will copy the code to clipboard or not.
I know several apps also do that. I was never capture the screenshot of the popup dialog I mean, but I hope you get the idea. (the popup is from android/system, not from apk)
Even the button is shown inside the SMS too:
How can we achieve this?
This is my current code in my activity:
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(val_no_hp, null, "Kode verifikasi aplikasi: " + kode_verifikasi, null, null);
kode_otp_rcv = new SmsReceiver(MainActivity.this);
IntentFilter kode_otp_filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(kode_otp_rcv, kode_otp_filter);
And this is my SmsReceiver class:
public class SmsReceiver extends BroadcastReceiver {
private MainActivity act;
private static int PANJANG_KODE_VERIFIKASI = 4;
public SmsReceiver(MainActivity act) {
this.act = act;
}
#Override
public void onReceive(Context context, Intent intent) {
SmsMessage[] msgs = Telephony.Sms.Intents.getMessagesFromIntent(intent);
SmsMessage msg = msgs[0];
String body = msg.getMessageBody();
String kode = body.substring(body.length() - PANJANG_KODE_VERIFIKASI);
// currently my app submit verification automatically when SMS arrived
// act.verifikasiOTP(kode, msg.getOriginatingAddress());
}
}
This is not possible, this functionality is not provided by android and is built by application developers themselves, the logic is private and varies from app to app, some apps may recognise some codes, whilst others may not.
I send my verification SMS like this:
code: 123456 Your code from Example.com
The important text is : code: 1111 at the begining
and in android mobiles, automatic copy is enabled .
I know its a long time from this question but I answer :)
I think it depends on the phone and OS but by the way the thing that I got is that if you write code like this :
:1234
PS: 1234 is a sample code
if the Mobile supports it, it will show the pop up copy code.
Related
My app is using a NotificationListener to read out messages from various 3rd party apps, for example WhatsApp.
So far I was able to send a reply if only one chat is unread, the code is below.
However, in the case with WhatsApp, getNotification().actions returns a null object when more than two chats are unread, as the messages are bundled together. As you can see in the pictures below, if the notifications are extended there is an option to send a direct reply as well, therefore I am certain that it is possible to utilize this, also I think apps like PushBullet are using this method.
How could I access the RemoteInput of that notification?
public static ReplyIntentSender sendReply(StatusBarNotification statusBarNotification, String name) {
Notification.Action actions[] = statusBarNotification.getNotification().actions;
for (Notification.Action act : actions) {
if (act != null && act.getRemoteInputs() != null) {
if (act.title.toString().contains(name)) {
if (act.getRemoteInputs() != null)
return new ReplyIntentSender(act);
}
}
}
return null;
}
public static class ReplyIntentSender {
[...]
public final Notification.Action action;
public ReplyIntentSender(Notification.Action extractedAction) {
action = extractedAction;
[...]
}
private boolean sendNativeIntent(Context context, String message) {
for (android.app.RemoteInput rem : action.getRemoteInputs()) {
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putCharSequence(rem.getResultKey(), message);
android.app.RemoteInput.addResultsToIntent(action.getRemoteInputs(), intent, bundle);
try {
action.actionIntent.send(context, 0, intent);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
return false;
}
}
Some explanation how the above code works: Once a notification is received the app tries to get the actions and checks if the name is in the title of a remoteInput (normally it is in the format of "Reply to $NAME"), if that is found the Action is saved into a ReplyIntentSender class, which, when triggered by sendNativeIntent, cycles through all RemoteInputs of that Action and adds the message to the intent. If more than one chat is unread, getNotification().actions returns null.
Below are two screenshots, the first one where it is working without any problems and the second one where it doesn't.
You can consider this as my suggestion. I have done bit research on this and come up with following conclusions.(Also it looks like you have done plenty of research on this so it might be possible that you aware about what I wrote below)
Numerous apps send Wear specific notifications, and many of those contain actions accessible from an Android Wear device. We can grab those Wear notifications on the device, extracting the actions, finding the reply action (if one exists), populating it with our own response and then executing the PendingIntent which sends our response back the original app for it to send on to the recipient.
To do so you can refer this link (A nice workaround by Rob J). You can also refer this link in this context (Great research work done by Michał Tajchert).(You might need to work around with NotificationCompat.isGroupSummary)
This is what I feel(Might be I am totally wrong)
.actions method returns Array of all Notification.Action
structures attached to current notification by addAction(int,
CharSequence, PendingIntent), Here addAction method is deprecated
one so it might not working as intended.
I am not able to test this at my end otherwise I will love to provide a working solution with code.
Hope this will help you. Happy Coding!!!
I have an Android Wear watch face created, an interactive one. On the face I have a grid area where I listen for an onTapCpmmand:
else if (x >= x6 & x <= x9 & y >= (y5 - (gridYUnit / 2)) & y <= (y8 - (gridYUnit / 2))) {
activityLaunched = new Intent(MyWatchFace.this, ActivityLaunched.class);
activityLaunched .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(activityLaunched );
}
The mew activity then takes over. Within this activity, I have three options, basically ImageButtons, with respective onClickHandlers:
optionOne.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
confirmationIntent = new Intent(ActivityLaunched.this, ConfirmationActivity.class);
confirmationIntent .putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE,
ConfirmationActivity.SEARCH_SERVICE);
confirmationIntent .putExtra(ConfirmationActivity.EXTRA_MESSAGE,
getString(R.string.option_one));
currentOption = "1";
broadcastIntent(currentOption);
startActivity(confirmationIntent );
ActivityLaunched.this.finish();
}
});
With broadcastIntent handling the broadcast:
public void broadcastIntent(String currentOption){
Intent optionUpdated = new Intent();
optionUpdated .setAction("com.example.packagename....");
optionUpdated .putExtra("Option", currentOption);
sendBroadcast(optionUpdated );
}
The users selects an options, the activity closes and the flow of control passes to my broadcastReceiver.
Now, I had set up a broadcastReceiver to make a simple toast when an option has been selected. However, I am unable to do any more with this data, other than show a toast.
Within my broadcastReceiver:
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Option Updated." + intent.getStringExtra("Option"), Toast.LENGTH_LONG).show();
currentOption = intent.getStringExtra("Option");
sendOption .setAction("com.example.packagename....");
sendOption tion.putExtra("Option", currentOption );
context.sendBroadcast(sendOption );
Log.d(TAG, "THIS WORKS : " + currentOption );
}
In my WatchFaceService, I have registered the receiver along with the batteryinforeceivers, and any other system ones, as normal. I am receiving the messages within my broadcastReceiver
Back again to my WatchFaceService, it's where I'm getting issues, I'm not receiving any updates:
optionUpdateReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Bundle results = getResultExtras(true);
String option = results.getString("Option");
Log.d(TAG, " NOTHING SHOWING HERE " + currentOption + option );
}
};
I have tried using setters and getters, which required a second launch of the activity to get the real value.
Any ideas as to what I am doing wrong?
I've tried following some other answers and ideas here, as well as other external sources. But as it's Android Wear I'm working with, as volatile as the OS is, anything I tried, that was suggested that worked for Android, appears to be ineffective for Android Wear.
Thanks, Emmett
Your watch face service is not guaranteed to be running when there another activity on top of it. It might be preserved, but equally likely it might be torn down. You could try to register your receiver in WatchFaceService.onCreate() and WatchFaceService.onDestroy(), but that's not a way that is guaranteed to work.
Instead, inside the Activity save the information into SharedPreferences and then read the information within you watch face. When your watch face is created, read the value from the prefs (you can also have a listener for the preferences, to update on their change when they change while the watch face is already launched).
I've actually managed to solve it.
I created a second broadcastreceiver, passed this back to the watchface, and then overrode the register / unregister methods to handle the transmission.
Initially, when I had registered the second receiver, it was spamming the log files and crashing the watch. The reason I had to override was to handle the passing of a filter, which cannot be done from within a watchfacecanvas.engine for some strange reason.
Anyway, it's working fine now, but thanks for help
second question, what is the WeChat app's package name? (due to i can't find it)
follow main quesition, i use WeChat official android sample code to execute the app.
But i don't know how to assign the specific WeChat user with sending out message .
any friend tell me how to finish it?
this is WeChat Sample code for sening message:
http://dev.wechat.com/download/sdk/WeChat_SDK_sample_android_en.zip
public static final String APP_ID = "wxd930ea5d5a258f4f";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);
}
#Override
public void onClick(View v) {
WXTextObject textObj = new WXTextObject();
textObj.text = text;
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = textObj;
msg.description = text;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("text");
req.message = msg;
req.scene = isTimelineCb.isChecked() ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
api.sendReq(req);
finish();
}
A.how can i know that i should send who?
B.APP_ID = "wxd930ea5d5a258f4f" represent is WeChat chat id?
C.i just run the sample app,then i send out message .it say"發送被拒絕"
that mean refuse to send message.what is the problem?
D.i live in Taiwan,When i register to http://dev.wechat.com/signup
. i input my Taiwan format phone code,but my phone never receive any
WeChat verification code for SMS
In result, i just want to know that how could the custom android app send message to the specific Wechat.Use the sample code to achieve the goal?
I am developing a simple voice chat android application using twilio. I am being able to make outgoing calls and also accept incoming calls using client names. This is my twilio voice url php script :
<?php
header('Content-type: text/xml');
$client= $_REQUEST["userName"];
?>
<Response>
<Dial callerId="<?php echo $client ?>">
<Client><?php echo $number;?></Client>
</Dial>
</Response>
What I need to do is I need to display the name of the calling client to the user receiving the incoming call but I am unable to figure out how to obtain the name of calling client. I even tried doing this,
#Override
public void onResume() {
super.onResume();
Intent intent = getIntent();
Device device = intent.getParcelableExtra(Device.EXTRA_DEVICE);
Connection incoming = intent
.getParcelableExtra(Device.EXTRA_CONNECTION);
incoming.setConnectionListener(this);
String clientName = Connection.getParameters().get(incoming.IncomingParameterFromKey);
Log.i(TAG, "Call from : " + clientName);
}
but I got following logcat output:
12-13 16:17:25.531: E/Voice chat sample app log(16157): Call from : 873797
I am getting a number 873797 instead of client name.
There might be some way to obtain the name of the client. I also went through twilio documentation with no success. Any help would be greatly appreciated.
All you need to do is just go to this link
https://www.twilio.com/user/account/phone-numbers/incoming
1. Click on your twilio number.
2. Enter into the Configure Tab
3. Go into Voice . Check the Url in Configure with:
4. Over there you have a drop down of Caller Name Lookup that is set to disabled. Enable it .
Hope this works for you ! :)
I have solved the problem with this,
Hope it helps
#Override
public void onResume() {
super.onResume();
Intent intent = getIntent();
if (intent != null) {
/*
* Determine if the receiving Intent has an extra for the incoming connection. If so,
* remove it from the Intent to prevent handling it again next time the Activity is resumed
*/
Device device = intent.getParcelableExtra(Device.EXTRA_DEVICE);
Connection incomingConnection = intent.getParcelableExtra(Device.EXTRA_CONNECTION);
if (incomingConnection == null && device == null) {
return;
}
intent.removeExtra(Device.EXTRA_DEVICE);
intent.removeExtra(Device.EXTRA_CONNECTION);
pendingConnection = incomingConnection;
pendingConnection.setConnectionListener(this);
String incomingRecipientCallNumber = pendingConnection.getParameters().get(incomingConnection.IncomingParameterFromKey);
showRecipientNumber.setText(incomingRecipientCallNumber);
showIncomingDialog();
}
}
I am relatively new to Android programming, but have had experience in Java and other coding languages. As part of a program that I am currently making, I want to be able to send a pre-defined email when a button is pressed. I am currently looking at this code:
Sending Email in Android using JavaMail API without using the default/built-in app
I am currently able to start an intent to start the MailSenderActivity.class. However, I am not able to understand how that is able to send an email through the GmailSender.class. I believe that I am misunderstanding how to use the code provided. Am I supposed to create two separate intents that will start both activities up, one after each other, in the code on the home page, as below? If not, how would I do it?
public void SendEmail(View v) {
Intent i = new Intent(getBaseContext(), MailSenderActivity.class);
Intent j = new Intent(getBaseContext(), GMailSender.class);
startActivity(i);
}
Also, I am wondering about the defined spaces for to/from, subject, body and the like in the code. I see that the MailSenderActivity.class has
try {
GMailSender sender = new GMailSender("username#gmail.com", "password");
sender.sendMail("This is Subject",
"This is Body",
"user#gmail.com",
"user#yahoo.com");
Are the user#gmail.com and user#yahoo.com both the recipients of the email? And are there any other places in the code where I am supposed to define the contents of the email?
Thanks for your time.
Scroll down and read the rest of the answer, you'll see that the sendMail() method gives all the clues:
public synchronized void sendMail(String subject, String body, String sender, String recipients)
So:
"user#gmail.com" is the sender (From field).
"user#yahoo.com" is the recipient (To field). You can specify more with commas, eg
"user#yahoo.com,user_2#gmail.com"
You would also see that GMailSender is just a class, not an Activity. Therefore, it does not need an Intent; just instantiate the class. Also, MailSenderActivity is a code sample demonstrating the implementation of GMailSender. You do not have to use it.
Eg
public void SendMail (View v) {
try {
GMailSender sender = new GMailSender("your_username#gmail.com", "password");
sender.sendMail("Subject",
"Email body",
"Fromfield#gmail.com",
"toField#example.com");
} catch (Exception e) {
Log.e("SendMail", e.getMessage(), e);
}
}
Also keep in mind Java naming conventions state that methods should start with a lowercase letter. You should adhere to those conventions and refactor your code appropriately.