How to use sendintent in google tv remote - android

I'm developer about android in Korea.
Currently, I have developed about Google TV with smart phone.
I have one problem, so I enter this site.
The problem is using AnymoteSender in Google TV remote.
The blackjack project does connect smart TV with smart phone.
So, It project using AnymoteSender library and use sendIntent with component.
for example)
final Intent TVLaunchIntent = new Intent("android.intent.action.MAIN");
TVLaunchIntent.setComponent(new ComponentName(
"com.tvstorm.sportscompanion.tv",
"com.tvstorm.sportscompanion.tv.SportsCompanionGTVActivity"));
anymoteSender.sendIntent(TVLaunchIntent);
anymoteSender have sendIntent function.
but How about Google TV Remote project?
It use DeviceAdapter in AnymoteSender that is user-defined class(DeviceAdapter is library).
for example)
public void click(Action action) {
DeviceAdapter sender = getSender();
if (sender != null) {
sender.sendKeyEvent(Code.BTN_MOUSE, action);
}
}
DeviceAdapter hasn't sendIntent function.
So, I thinked two ways.
one) I implemented clintlistener in activity.
But, It didn't bind to AnymoteSender and made some error.
It didn't use bindService. So, It make some error.
two) I make new AnymoteSender like this AnymoteSender = new AnymoteSender();
but It needs ConnectingTask like new AnymoteSender(ConnectingTask task);
and ConnectingTask need tvDevice and keyStoreManger.
like this,
ConnectingTask task = new ConnectingTask(tvDevice, keyStoreManager, context);
So, I connect AnymoteLibrary with my project, TvDevice and KeyStoreManager.
but, The Keystore manager was different between KeystoreManager in Google TV remote project and in Library.
How to connect AnymoteSender in GoogleTV Anymote project with AnymoteSender Library?
So, I want to solve this problem. anyone know this problem, Please reply my question.
Thank you!!

Related

How to programmatically connect to wifi in Android

I've been searching on this for quite some time, and have found lots of solutions that ultimately use the Android GUI to prompt the end-user for connection/confirmation. We would like to present a user with a form and directly connect to the specified network. I understand from a security perspective why this is necessary, but in our case, it is a system app going on a fully managed Android device. It is not intended for general use in the Play store. We are using Xamarin, but I can adapt any Java/Kotlin code.
The closest I've found thus far is the following (using C#):
public void ConnectToWifi(string ssid, string password = "") {
var wifiNetworkSpecifier = new WifiNetworkSpecifier.Builder().SetSsid(ssid);
if (!string.IsNullOrEmpty(password))
wifiNetworkSpecifier.SetWpa2Passphrase(password);
var networkRequest = new NetworkRequest.Builder().AddTransportType(TransportType.Wifi)?
.SetNetworkSpecifier(wifiNetworkSpecifier.Build())?.Build();
if (networkRequest is null)
return;
var theNetworkCallback = new TheNetworkCallback();
var connectivityManager = (ConnectivityManager?)MainActivity.Current.ApplicationContext?
.GetSystemService(Context.ConnectivityService);
connectivityManager?.RequestNetwork(networkRequest, theNetworkCallback);
}
It sorta works, but does prompt the end-user, and my understanding, this approach is deprecated and doesn't work well in newer versions of Android. We're hoping for a solution that works in Android 11.
I'm even fine if there's a solution to write directly to wifi files on the OS. I've seen various solutions to manually populate entries via ADB, but I'm having a tough time adapting that to Xamarin/Java (can't seem to access the /data/misc/wifi directories). Again, this is intended for use exclusively on our own managed devices.
I have a blog post about this topic here: https://blog.ostebaronen.dk/2020/11/android-11-wifi.html
Android Network API is not the greatest thing to work with as there are pitfals depending on the API level the code runs on.
From Android 10 and up a lot of the Network stuff has been restricted for "privacy" reasons, so you cannot work around not asking the user for input, unless the device is rooted or your App is set up as Device Admin.
For Android 11, there is a new API to present a system dialog and allow the user to save and connect to a network. This will look something like:
You can launch this through an Intent called android.settings.WIFI_ADD_NETWORKS:
var intent = new Intent(
"android.settings.WIFI_ADD_NETWORKS");
var bundle = new Bundle();
bundle.PutParcelableArrayList(
"android.provider.extra.WIFI_NETWORK_LIST",
new List<IParcelable>
{
new WifiNetworkSuggestion.Builder()
.SetSsid(ssid)
.SetWpa2Passphrase(password)
.Build()
});
intent.PutExtras(bundle);
StartActivityForResult(intent, AddWifiSettingsRequestCode);
You can then get the result in your Activity overriding OnActivityResult and fetching the result like so:
if (requestCode == AddWifiSettingsRequestCode)
{
if (data != null && data.HasExtra(
"android.provider.extra.WIFI_NETWORK_RESULT_LIST"))
{
var extras =
data.GetIntegerArrayListExtra(
"android.provider.extra.WIFI_NETWORK_RESULT_LIST")
?.Select(i => i.IntValue()).ToArray() ?? new int[0];
if (extras.Length > 0)
{
var ok = extras
.Select(GetResultFromCode)
.All(r => r == Result.Ok);
// if ok is true, BINGO!
return;
}
}
}
I have a repository here with the full sample: https://github.com/Cheesebaron/Android11WiFi
From using this in the wild, I've found that this API does not work nicely with some OEMs such as OnePlus and Huawei. Some of these either restrict or the System Settings App simply crashes due to a misconfiguration on their part. For those I fall back to the API's introduced in Android 10.

android TV mediacontroller

I try to use android's mediabrowser and sample by google works fine on phones (https://github.com/googlesamples/android-media-controller)
But on android TV it can't find any app which supported this feature
final Intent mediaBrowserIntent =
new Intent(MediaBrowserServiceCompat.SERVICE_INTERFACE);
final List<ResolveInfo> services =
packageManager.queryIntentServices(mediaBrowserIntent,
PackageManager.GET_RESOLVED_FILTER);
in services placed only current app
Could you help me get API to collect last used mediadata? I can't find any description or guide for creating TV launcher (which have access to last used or recommended media by another app)
I just wanna GET metadata like https://developer.android.com/training/tv/playback/now-playing.html
or
http://corochann.com/android-tv-application-hands-on-tutorial-11-277.html
You can query for all active media sessions using the method MediaSessionManager.getActiveSessions(notificationListnerComponentName) which will return a list of alla ctive mediacontrollers with the most active as the first item in the list.
Code sample:
MediaSessionManager mediaSessionManager = context.getSystemService(Context.MEDIA_SESSION_SERVICE);
List<MediaController> activeMediaSessionControllers = mediaSessionManager.getActiveSessions(null);

Xamarin.InAppBilling "Service Intent must be explicit"

I have a working app made with Xamarin.Android, and I'm trying to add in-app purchases with the component Xamarin.InAppBilling v2.2
I use this code with my public key from the Google Play Developer Console.
_serviceConnection = new InAppBillingServiceConnection(activity, InAppBillingPublicKey);
_serviceConnection.OnConnected += LoadProducts;
_serviceConnection.Connect();
It fails with this exception message: "Service Intent must be explicit: Intent { act=com.android.vending.billing.InAppBillingService.BIND }"
I can find others talking about this for plain android development, but not for Xamarin and this component. How do I make the component have the service intent set explicitly? Is there another way to to in-app-purchases in Xamarin.Android?
From other posts, I have found and tried this:
var intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
intent.SetPackage("com.android.vending");
activity.BindService(intent, _serviceConnection, Bind.AutoCreate);
But it still won't work. I get the same error.
The error goes away i I set API level to 19 (was 21). But then I get another error from the linker. But for this case, it solves the problem.

Hello World For Google Glass

I'm trying to build a simple Hello World GDK program for Google Glass. I've looked up everywhere, but all the samples I could find used "Timeline Manager", which was removed by Google after XE 16.
What I'm trying to do is to create a live card that shows texts (Hello world!) in the middle.
I've tried to modify codes from HERE (HuskyHuskie's answer) and HERE (IsabelHM's answer)
However, no matter what I did, no option or voice command appeared on the glass even though the console showed that the program is installed on device.
What I mostly modified was take out the TimelineManager part and replace
mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_ID);
with
mLiveCard = new LiveCard(this,LIVE_CARD_ID);
Also, I'm relatively new to Android. I don't quite understand how R.id.XXXX and R.layout.XXXX are missing from the resource. Do you need to define it in Manifest or what else?
The following is the onStartCommand method:
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
RemoteViews aRV = new RemoteViews(this.getPackageName(),
R.layout.card_text);
if (mLiveCard == null) {
// mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_ID);
mLiveCard = new LiveCard(this,LIVE_CARD_ID);
aRV.setTextViewText(R.id.main_text, INTRO);
mLiveCard.setViews(aRV);
Intent mIntent = new Intent(this, MainActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
mLiveCard.setAction(PendingIntent.getActivity(this, 0, mIntent, 0));
mLiveCard.publish(LiveCard.PublishMode.REVEAL);
}
return START_STICKY;
}
Ok I got it to work following THIS
Note that the Manifest is not entirely correct. You need to add this line in the Manifest after the XE16 update:
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
See the post HERE for reference.
I strongly recommend using our official samples available on GitHub and reading our documentations as all of those caveats are explained and handled.
If you are using the latest version of Android Studio, you can also easily create a new project through our available templates: LiveCard and Immersion.
Open Android Studio
Create a new project
Enter your project information: application name, package name, etc.
Select Glass as the form factor: make sure to unselect all the other form factors unless you want to develop for those devices as well.
Select the Immersion Activity or the Simple Live Card template
Build and run your new Hello World project on Glass!

preparing SMS app for Android KitKat

in agreement with the recent post from Android Developers http://android-developers.blogspot.pt/2013/10/getting-your-sms-apps-ready-for-kitkat.html ,I was trying to prepare my app to the new android version, but encountered a problem with the part they suggest to create a dialog to let the user set the app as the default application to handle SMS's :
Android Developers Post
public class ComposeSmsActivity extends Activity {
#Override
protected void onResume() {
super.onResume();
final String myPackageName = getPackageName();
if (!Telephony.Sms.getDefaultSmsPackage(this).equals(myPackageName)) {
// App is not default.
// Show the "not currently set as the default SMS app" interface
View viewGroup = findViewById(R.id.not_default_app);
viewGroup.setVisibility(View.VISIBLE);
// Set up a button that allows the user to change the default SMS app
Button button = (Button) findViewById(R.id.change_default_app);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent =
new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
myPackageName);
startActivity(intent);
}
});
} else {
// App is the default.
// Hide the "not currently set as the default SMS app" interface
View viewGroup = findViewById(R.id.not_default_app);
viewGroup.setVisibility(View.GONE);
}
}
}
the code itself in pretty much straightforward, but I'm unable to access to Telephony.Sms.getDefaultSmsPackage because it says that Telephony cannot be resolved, and I can't find any import or declaration that would fix that.
Can anyone please help?
android.provider.Telephony simply doesn't exist yet (as of API 18 - 4.3).
This class will be added in 4.4 (presumably API 19), and that blog post is highlighting the changes that you should make once the new API is released so you aren't surprised when the time comes.
From the end of the post:
To help you make the changes, we'll soon be providing the necessary SDK components for Android 4.4 that allow you to compile and test your changes on Android 4.4.
Don't forget that you should wrap this code in an API version check so you don't run into issues with older versions that don't have this class.
this change will break all the SMS blocking apps.
"Note that—beginning with Android 4.4—any attempt by your app to abort the SMS_RECEIVED_ACTION broadcast will be ignored so all apps interested have the chance to receive it."
Do you think there is a way to go around this?!
Maybe at least on Root?
Apparently there is with root access. The latest version Cerberus app claim to be doing this.
Now, if only I knew how they do it :(

Categories

Resources