Android EditMetadata with RemoteControl Client - android

I'm tring to create a library for phonegap that give me control about remote control client. All phonegap side plus structure of new class is made but i don't know how change metadata.
I've made this function:
public void setMetadata() {
RemoteControlClient.MetadataEditor editor = remoteControlClient.editMetadata(true)
.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "CIAO");
}
but i'm sure that i've missed something like a register function.
Someone can give me an help?
Thanks!

For registering
// register a remote client ===========================================
final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(RemoteControlReceiver);
final PendingIntent mediaPendingIntent = PendingIntent.getBroadcast( getApplicationContext(), 0, mediaButtonIntent, 0);
// create and register the remote control client
myRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
audioManager.registerRemoteControlClient(myRemoteControlClient);
And dont forget to apply the editor after you made your changes.
editor.apply();

Related

AppAuth-Android - Response state param did not match request state

Recently we tried to update the AppAuth-Android version used on our project from version 0.5.1.5 to 0.11.1.
When successfully login from the browser and come back to the app, there is error data and we can't continue the process.
This is how we request:
AuthorizationServiceConfiguration configuration = new AuthorizationServiceConfiguration(Uri.parse(getAuthorizationRequestUrlWithParams(getBaseUrl(), getAuthorizationUrlParameters())), Uri.parse(getAccessTokenUrl()), null);
AuthorizationRequest.Builder authRequestBuilder = new AuthorizationRequest.Builder(
configuration,
mClientId,
"code token id_token",
Uri.parse(getCallbackURI()))
.setScope(getHybridScope());
Intent completionIntent = new Intent(context, tokenActivity);
Intent cancelIntent = getCancelIntent(context, cancelActivity);
CustomTabColorSchemeParams colorSchemeParams = new CustomTabColorSchemeParams.Builder()
.setToolbarColor(ContextCompat.getColor(context,R.color.grey120))
.setSecondaryToolbarColor(ContextCompat.getColor(context,R.color.black))
.build();
int flags = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
flags |= PendingIntent.FLAG_MUTABLE;
}
mAuthService.performAuthorizationRequest(
authRequestBuilder.build(),
PendingIntent.getActivity(context, 0, completionIntent, flags),
PendingIntent.getActivity(context, 0, cancelIntent, flags),
mAuthService.createCustomTabsIntentBuilder()
.setDefaultColorSchemeParams(colorSchemeParams)
.build());
On authorization completed, the responseData has error data with description Response state param did not match request state.
After some debugging, we found out that on AuthorizationResponse.java there is a builder function that failed to get the query parameters from Uri which result in null value although the Uri string already contains all the data.
We also tried to setResponseMode to "form_post" on authRequestBuilder when requesting but it looks like it's still not supported.
Does anyone happen to solved this before?
Thanks in advance.

Sends a text message to a specific number phone

I got App api_id, App api_hash and Production configuration from telegram.org, I need to use from this method messages.sendMessage for Sends a text message to a specific number phone's telegram(for example: +1888888). How can I use from this method. Is there any a simple sample?
I suggest you using a top-layer library over MTProto to make things easier. For example you can use Telethon. You should use SendMessageRequest in order to send message. After creating a client you can call it like this (in newest version of Telethon the phone number is resolved automatically):
from telethon.tl.functions.messages import SendMessageRequest
client(SendMessageRequest('phone_number', 'hello'))
If you're using TDLib, you may use this function (taken from here) or a similar one:
private static void sendMessage(long chatId, String message) {
// initialize reply markup just for testing
TdApi.InlineKeyboardButton[] row = {new TdApi.InlineKeyboardButton("https://telegram.org?1", new TdApi.InlineKeyboardButtonTypeUrl()), new TdApi.InlineKeyboardButton("https://telegram.org?2", new TdApi.InlineKeyboardButtonTypeUrl()), new TdApi.InlineKeyboardButton("https://telegram.org?3", new TdApi.InlineKeyboardButtonTypeUrl())};
TdApi.ReplyMarkup replyMarkup = new TdApi.ReplyMarkupInlineKeyboard(new TdApi.InlineKeyboardButton[][]{row, row, row});
TdApi.InputMessageContent content = new TdApi.InputMessageText(new TdApi.FormattedText(message, null), false, true);
client.send(new TdApi.SendMessage(chatId, 0, false, false, replyMarkup, content), defaultHandler);
}
Don't forget that, you need to add each phone number to user's Telegram contacts first to get the chatId. It can be achieved by passing an array of phone numbers to this function:
---functions---
contacts.importContacts#2c800be5 contacts:Vector<InputContact> = contacts.ImportedContacts

Android Autofill only working with response from onFillRequest but not from Authentication Activity

I have implemented an Android Autofill Service for my password manager app. Users have reported issues with the Paypal app, where the service does not seem to work.
I have investigated this and found that the following code (Xamarin) in onFillRequest does work: ("does work" means the fields are filled after clicking the autofill popup)
var responseBuilder = new FillResponse.Builder();
var autofillIds = FindAutoFillIds(); //gets the autofill ids for each EditText
RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName, "fill data from onFillRequest", AppNames.LauncherIcon);
var datasetBuilder = new Dataset.Builder(presentation);
foreach (AutofillId autofillId in autofillIds)
{
datasetBuilder.SetValue(autofillId, AutofillValue.ForText("some data"));
}
responseBuilder.AddDataset(datasetBuilder.Build());
callback.OnSuccess(responseBuilder.Build());
It basically creates a fill response with a single dataset which has values set for each autofill field.
Now I need to add an authentication activity:
var responseBuilder = new FillResponse.Builder();
var autofillIds = FindAutoFillIds(); //gets the autofill ids for each EditText
Intent intent = new Intent(this, typeof(MyAuthActivity));
var sender = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.CancelCurrent).IntentSender;
RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName, "fill data after auth", AppNames.LauncherIcon);
var datasetBuilder = new Dataset.Builder(presentation);
//Main difference here:
datasetBuilder.SetAuthentication(sender);
foreach (AutofillId autofillId in autofillIds)
{
datasetBuilder.SetValue(autofillId, AutofillValue.ForText("some placeholder data"));
}
responseBuilder.AddDataset(datasetBuilder.Build());
callback.OnSuccess(responseBuilder.Build());
where MyAuthActivity.OnCreate is like this:
RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName, "dataset from auth activity", AppNames.LauncherIcon);
var datasetBuilder = new Dataset.Builder(presentation);
var autofillIds = GetAutofillIds(...); //returns the same autofillIds as in the onFillRequest
foreach (AutofillId autofillId in autofillIds)
{
datasetBuilder.SetValue(autofillId, AutofillValue.ForText("some other data"));
}
var ReplyIntent = new Intent();
bool returnDataset = true; //tried both true and false, neither works
if (returnDataset)
{
ReplyIntent.PutExtra(AutofillManager.ExtraAuthenticationResult, datasetBuilder.Build());
}
else
{
var responseBuilder = new FillResponse.Builder();
responseBuilder.AddDataset(datasetBuilder.Build());
ReplyIntent.PutExtra(AutofillManager.ExtraAuthenticationResult, responseBuilder.Build());
}
SetResult(Result.Ok, ReplyIntent);
Finish();
which basically creates another dataset using the same autofill ids, but neither returning them with a FillResponse nor a Dataset response works: The input fields on the target app remain empty.
I noticed that the same behavior appears in Bitwarden's implementation of their autofill service.
My questions are: Is there anything wrong with the code of the authentication activity? Or does this show an issue with Paypal's app? And is there anything I can do to debug this further?
This is a known WebView issue, which is fixed on Chrome M64.
You can verify it's fixed by installing a newer Chrome and changing the default WebView implementation through Settings -> Developer Options.

Receiving data messages from com.google.cast.media namespace on Android sender app

I created a custom receiver for Chromecast that plays video and I am trying to send messages back to my Android sender app on the same namespace. I'm currently doing it this way in Javascript:
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
window.castReceiverManager.start();
//use namespace urn:x-cast:com.google.cast.media to communicate to VideoCastManager in Android...?
window.customMessageBus = castReceiverManager.getCastMessageBus('urn:x-cast:com.google.cast.media', cast.receiver.CastMessageBus.MessageType.JSON);
//overwrite the onMessage function
var defaultFunction = window.customMessageBus.onMessage;
window.customMessageBus.onMessage = function(event) {
window.senderId = event.senderId;
window.message = event.data;
defaultFunction(event);
};
//send message
window.customMessageBus.send(window.senderId, {message: "test"});
In Android, I am trying to receive the messages in this way:
mCastConsumer = new VideoCastConsumerImpl() {
//removed all the other override functions to save space
#Override
public void onDataMessageReceived(String message) {
System.out.println("CAST RECEIVED MESSAGE:" + message);
}
};
This doesn't work, and I was hoping someone could point me in the right direction?
Thanks
You need to use a custom namespace not the Media namespace.

Send file is done but actually fail in Asmack android

This is how I try to send a file over XMPP using asmack lib (from the GtalkSms project) and a Ejabberd server:
//Configure provider in onCreate()
configure(ProviderManager.getInstance());
// Configure function
private void configure(ProviderManager pm){
pm.addIQProvider("si","http://jabber.org/protocol/si", new StreamInitiationProvider());
pm.addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
pm.addIQProvider("open","http://jabber.org/protocol/ibb", new OpenIQProvider());
pm.addIQProvider("close","http://jabber.org/protocol/ibb", new CloseIQProvider());
pm.addExtensionProvider("data","http://jabber.org/protocol/ibb", new DataPacketProvider());
}
// This is how I send file after login to server (I put everything below in a
function, inside a Thread and call thread.start() at the end of function):
// set the serviceDiscoveryManager
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(xmppConn);
if (sdm == null){
sdm = new ServiceDiscoveryManager(xmppConn);
}
sdm.addFeature("http://jabber.org/protocol/disco#info");
sdm.addFeature("jabber:iq:privacy");
// Create the file transfer manager
FileTransferManager manager = new FileTransferManager(connection);
FileTransferNegotiator.setServiceEnabled(connection, true);
OutgoingFileTransfer transfer = manager
.createOutgoingFileTransfer(Receiver
+ "#MyDomain");
transfer.sendFile(new File(myFilePath), "myDescription");
If I use another client to test the file transfer (http://coccinella.im/), then I can chat and send a file over my Ejarbberd server between (2 coccinella clients). If I use a coccinella client and my client in android, I can chat between them and I can receive file sent from coccinella client to my android client. However, when I try to send file from my android client to the coccinella client, transfer.isDone() always returns true and transfer.getStatus() == Status.error also returns true.
So what's happen to my Android client? Did I use wrong library? Or I missed something?
Edited: This is what I got from debugger: <iq id="QgJIb-29" to="phuocdh#localhost/Smack" from="phuoctest#localhost/Coccinella#phuocdh-pc" type="error"><error code="404" type="CANCEL"><item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><query xmlns="http://jabber.org/protocol/bytestreams"><streamhost></streamhost></query></error></iq>

Categories

Resources