Hello World For Google Glass - android

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!

Related

How to enable Android Open Application voice interaction

According to the system voice command docs, you can open an application with a voice command. e.g. OK Google - open foobar. Also according to the docs, this Works by default; no specific intent.
In my sample development app, this isn't working. I've tried adding a few combinations of action and category permutations to the intent-filter, but no luck so far.
I'm targeting a minimum SDK of 23, testing on a device with 6.0.1.
Should this work, and if so, what are the changes to a new empty activity project I need to enable it?
As far as I am aware, Google simply iterates over a list of installed applications and opens the corresponding application if it finds an exact match.
To test this, use the following Intent
final String PACKAGE_NAME_GOOGLE_NOW = "com.google.android.googlequicksearchbox";
final String GOOGLE_NOW_SEARCH_ACTIVITY = ".SearchActivity";
final String APP_NAME = "Open " +getString(R.string.app_name);
final Intent startMyAppIntent = new Intent(Intent.ACTION_WEB_SEARCH);
startMyAppIntent.setComponent(new ComponentName(PACKAGE_NAME_GOOGLE_NOW,
PACKAGE_NAME_GOOGLE_NOW + GOOGLE_NOW_SEARCH_ACTIVITY));
startMyAppIntent.putExtra(SearchManager.QUERY, APP_NAME);
startMyAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(startMyAppIntent);
} catch (final ActivityNotFoundException e) {
e.printStackTrace();
}
If this opens your application, then it is simply a case of the phonetics of your application name, or how Google interprets your pronunciation of it.
I do think that there should be an option to add a 'phonetic app label' to the application's manifest (or some other globally available configuration file), so Google could open your application if the unique name is not common enough to generate a voice search result.
If this doesn't open your application, check that you are correctly defining your application name in the manifest as follows:
<application
android:label="#string/app_name"

Why don't app shortcuts' icons get updated when installing new versions?

Background
I have an app-manager app (here), which, amongst other features, can create shortcuts to other apps on the launcher.
The problem
It seems that shortcuts that were created by my app don't get their icons updated when installing new versions of those apps.
I've noticed it on multiple devices and multiple launchers.
Not only that, but even icons that the play store creates don't get updated.
Not only that, but on some launchers, when trying to create a shortcut, if there is already one, it fails to create a new one.
What I've tried
I've tested it not only with normal apps, but also on my own signed APKs, via both ADB and via normal opening of the APK files (while also making sure the versions is increased.
There are 3 ways to create a shortcut, but all failed for me in getting updated:
adding a shortcut with an icon res id:
Intent shortcutIntent;
shortcutIntent=new Intent();
// shortcutIntent.putExtra("duplicate",false); //optional
shortcutIntent.setClassName(packageName,fullPathToActivity);
shortcutIntent.setAction(Intent.ACTION_MAIN);
final Intent putShortCutIntent=new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent);
putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,title);
Resources resources=pm.getResourcesForApplication(packageName);
final Intent launchIntentForPackage=pm.getLaunchIntentForPackage(packageName);
if(TextUtils.equals(launchIntentForPackage.getComponent().getClassName(),fullPathToActivity))
iconRes=applicationInfo.icon;
else
iconRes=pm.getActivityInfo(new ComponentName(packageName,fullPathToActivity),0).icon;
if(iconRes==0)
iconRes=applicationInfo.icon;
String iconResourceName=resources.getResourceName(iconRes);
putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconRes);
same as the above, but using a bitmap for the icon:
...
Bitmap appIcon=...
putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON,appIcon);
same as the above, but using ShortcutIconResource instead:
...
ShortcutIconResource shortcutIconResource=new Intent.ShortcutIconResource();
shortcutIconResource.packageName=packageName;
shortcutIconResource.resourceName=iconResourceName;
putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,shortcutIconResource);
The question
Why is it that launchers don't update my shortcuts, and some of them (or all) don't even update when they were created from the Play Store ?
What is the correct way to create shortcuts, that will get updated upon replacing/updating of apps?
Also, why do most launchers ignore adding a shortcut if it's already shown?

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.

make getSystemService() recognize our new system service

I'm using the book "Embedded Android".
I'm making a new System Service using AOSP(4.0.3_r1).
I want my system service to be registered in frameworks/base/core/java/android/content/app/ContextImpl.java so that I can use it through getSystemService() method.
The problem is, I can't find the app folder under content:androidroot/frameworks/base/core/java/android/content/app/ContextImpl.java
But, I found it in:androidroot/frameworks/base/core/java/android/app/ContextImpl.java
Are these 2 files the same? or is it just missing(the content/app folder)?
Any idea on what to do?
Karim wrote his book mostly orienting on Android 2.3.4 version. Something can be changed from this time. This is an example what has been changed.
Are these 2 files the same? or is it just missing(the content/app folder)?
These are the same files.
Any idea on what to do?
As I said the implementation has been changed. I looked into the code and here what you can change to make your code working (I can only suppose because I did not actually build my code). In the static block of ContextImpl class you need to add the following code:
registerService(ACCOUNT_SERVICE, new ServiceFetcher() {
public Object createService(ContextImpl ctx) {
IBinder b = ServiceManager.getService(OPERSYS_SERVICE);
IOpersysService service = IOpersysService.Stub.asInterface(b);
return new OpersysManager(service);
}});
You need to use SystemServer which holds all system services' names.
You should check this link out:
http://processors.wiki.ti.com/index.php/Android-Adding_SystemService

Unknown sources settings android

The issue is that I need to install an apk(non market app) and for this, the user need to activate the unknown source setting, so i send him (if he didn't have it activated) to the settings so he can turn on the option, the issue is that i tested it in different phones and in samsung that option is on applications while in htcs phones is on security. i want send the user to that option but i don't know how to do it
I read about this and no one knows exactly how to do it
this is my code
int canInstallFromOtherSources = Settings.Secure.getInt(ctx2,Settings.Secure.INSTALL_NON_MARKET_APPS);
if(canInstallFromOtherSources == 0)
{
Intent intentSettings = new Intent();
intentSettings.setAction(android.provider.Settings.ACTION_APPLICATION_SETTINGS);
startActivity(intentSettings);
}
You can do it with the following line (changing to the corresponding action):
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), REQUEST_CODE_ENABLE_LOCATION_PROVIDERS);
Check Android Settings documentation.
I think you should use ACTION_SECURITY_SETTINGS and one of ACTION_APPLICATION_SETTINGS or ACTION_APPLICATION_DEVELOPMENT_SETTINGS.
And here (line 304), you've got a working example of one of my apps: Tureame

Categories

Resources