Wink detection on Google Glass with XE22 - android

I'm trying to use this library:
https://github.com/thorikawa/EyeGestureLib
but it not works..
When app starts, occurs a NullPointerException on this line of "onStart()" function:
mEyeGestureManager.register(target1, mEyeGestureListener);
mEyeGestureManager.register(target2, mEyeGestureListener);
I've the other code like the appDemo exposed in the github repository and this lines in "onCreate" function:
mEyeGestureManager = EyeGestureManager.from(this);
mEyeGestureListener = new EyeGestureListener();
Any suggestion? Is there an update library?

The library you posted is pretty outdated (last change 11 months ago). There is currently no official way to detect a wink. I had the same problem to detect only the wink and stop glass to take pictures when detecting it. There are several ways to detect such EyeGestures. Here is what worked for me (quoted from this awesome source):
To listen to Intent, you have to extend BroadcastReceiver.
public class EyeGesture extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getStringExtra("gesture").equals("WINK")) {
//Disable Camera Snapshot
abortBroadcast();
Log.e("WINKED ","");
} else {
Log.e("SOMETHING", "is detected " + intent.getStringExtra("gesture"));
}
}
}
You must register the intent in the Manifest as below:
<receiver android:name="com.inno.inno.glassplugin.EyeGesture">
<intent-filter>
<action android:name="com.google.android.glass.action.EYE_GESTURE" />
</intent-filter>
</receiver>
The name specified in the Manifest must match the name of the class listening to the intent which is EyeGesture.
Simple as that. No library required but only WINK can be detected. It also stops Glass from taking picture when wink is detected. You can comment abortBroadcast(); if you want Glass to take picture when event is detected.

Related

Twitter app returns wrong value in onActivityResult

I'm composing a Tweet and then launch Twitter app to tweet it like that:
intent = new TweetComposer.Builder(getFragmentActivity())
.text(viewHolder.etShareText.getText().toString())
.url(contentUrl)
.image(imageUri)
.createIntent();
It worked for a long time, and it still works, I'm able to post a tweet to my profile, but some time ago every action was resulted with RESULT_CANCELED in my onActivityResult() method despite the actual result was successfull.
Maybe something had changed in Twitter API? How to handle results now?
Actually, in this case onActivityResult() usage may not true way. To catch composing result, like vijikumar said, we should use BroadcastReceiver. But this information is not enough for us. Because in many cases, twitter composing ways are confused with each other. Like documentation said ; there are two ways to compose tweets :
Launch the Twitter application’s Tweet Composer
Launch the Twitter Kit Native Composer
If you prefer to use first way, as long as i see, there is not a healthy method to catch composing result using BroadcastReceiver, onActivityResult or etc.
BroadcastReceiver method does not work using first way. But if you prefer to use second way, you can catch composing result using BroadcastReceiver in a healthy position. You shouldn't think that first way is not important. I am going to talk about first way briefly.
To do these above ;
Second Way
Add below repository and dependencies in your app level gradle file
repositories {
jcenter()
}
compile 'com.twitter.sdk.android:twitter-core:3.1.1'
compile 'com.twitter.sdk.android:tweet-composer:3.1.1'
Then add below BroadcastReceiver
public class MyResultReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (TweetUploadService.UPLOAD_SUCCESS.equals(intent.getAction())) {
// success
} else if (TweetUploadService.UPLOAD_FAILURE.equals(intent.getAction())) {
// failure
} else if (TweetUploadService.TWEET_COMPOSE_CANCEL.equals(intent.getAction())) {
// cancel
}
}
}
Then add your BroadcastReceiver to the application manifest file like below
<receiver
android:name=".MyResultReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_SUCCESS"/>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_FAILURE"/>
<action android:name="com.twitter.sdk.android.tweetcomposer.TWEET_COMPOSE_CANCEL"/>
</intent-filter>
</receiver>
As last, to open the composer screen, start ComposerActivity using below code block
final TwitterSession session = TwitterCore.getInstance().getSessionManager()
.getActiveSession();
final Intent intent = new ComposerActivity.Builder(YourActivity.this)
.session(session)
.text("Love where you work")
.hashtags("#twitter")
.createIntent();
startActivity(intent);
When you use this way, you will catch composer result in BroadcastReceiver.
I will not share any code block about First Way. But why can we need the first way ? Actually first way contains very rich content but as long as i see, it does not support to catch result. So second way is enough for us in many cases. however if Twitter app does not exist the device, second way will crash because of session. In this case, we should use first way to open composer screen in internet browser. So we should use both ways but like you see that first one is more effective than second one.
NOTE : Do not forget to add the twitter kit initialization configurations and authentication mechanisms please.
Use BroadcastReceiver.
public class MyResultReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (TweetUploadService.UPLOAD_SUCCESS.equals(intent.getAction())) {
// success
final Long tweetId = intentExtras.getLong(TweetUploadService.EXTRA_TWEET_ID);
} else {
// failure
final Intent retryIntent = intentExtras.getParcelable(TweetUploadService.EXTRA_RETRY_INTENT);
}
}
}
In manifest
<receiver
android:name=".MyResultReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_SUCCESS"/>
<action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_FAILURE"/>
</intent-filter>
</receiver>

Android lock screen : activity started first when mobile on

I develop one apps mobile number lock, i want whenever mobile on,or restart or switch on ,or on from the top/left/right button placed on mobile in short whenever mobile screen on my lock activity call, i have no idea to how to call activity at time of mobile on please any one give some related example to start activity at first when mobile on. so my lock dispay to user and then enter number password and lock open ...thanks in advance..
Following is working for me :
enter code here :
public class BootReciever extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null) {
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
Intent s = new Intent(context,ViewPagerMainActivity.class);
s.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(s);
}
}
}
}
and in menifist file add follwing:
enter code here :
<receiver android:name=".BootReciever">
<intent-filter android:enabled="true" android:exported="true">
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
There are multiple ways, to achieve this. One way is you can go through Broadcasting a message for your app, after the boot of your mobile. Try reading:
http://developer.android.com/reference/android/content/BroadcastReceiver.html
Also have look at this thread, this will solve your problem.
How to launch activity on BroadcastReceiver when boot complete on Android

how can I pass data to android Market using the new scheme on chrome?

so I noticed according to here, you can put a link on the site and have user to click on it. If user had the app installed, app will be launched. If the app wasn't installed, Google Play Store will be launched and search for the particular package, which is a great feature!! but from my understanding, this will loose the ability to pass referral string to play store.
According to here, you can have a link like market://details?id=your.package.name&referrer=YourReferrerString. If a broadcast receiver is set in the app, you'll be able to catch the referrer string, but how can I achieve the same goal if I used the first method which is from here?
here is the only thread I can find that talks about the new (?) feature on Chrome, but it didn't seem to answer my question.
Thanks!!
Turns out to be quite simple. The default referrer from Chrome is 'com.android.chrome'. Override this by putting &referrer= after package in your intent:// URI, for example:
var g_intent = "intent://" + code +
"/#Intent;scheme=yourscheme;package=com.your.app&referrer=code%3D" +
code + ";launchFlags=268435456;end";
Here's a gist that explains the javascript part of the solution more fully and also falls back to a normal market link if the intent:// scheme doesn't work: https://gist.github.com/akent/dec1b4b7383436b4623e
And in your Java code:
public static class InstallReferrerReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String referrer = intent.getStringExtra("referrer");
// Do things with your referrer here
}
}
And in AndroidManifest.xml:
<receiver android:name=".YourActivity$InstallReferrerReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>

How do I access the user calls to mobile?

I want my application to be activated when the user make a specific call. Is there any way to take information which call is making by user in the same time ( not afterwords ) in order to activate the app at the right time ?
Ok i wrote this code for my case and it works:
public class OutgoingCallReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(null == bundle) return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if( phonenumber.equals("11111111") ) {
Intent myactivity = new Intent(context, MyKeyboard.class);
myactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myactivity);
}
}
}
In the Manifest i add this:
<receiver
android:name=".OutgoingCallReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
I don't really know, but I think that's a really dangerous practice. It all depends on what you intend to do with your app. If it's a recording app, I think you can't even think of developping it, or don't post on the internet about it because it would be illegal in many countries. That's how I see and how I feel your question. About Android there is not 15k places to search, have a look at the android API.
http://developer.android.com/reference/android/provider/CallLog.Calls.html
This, for example, I don't know if it's a real time log, or if it's filled after the call is terminated. But you can search in that direction.

How I can receive hardware key events in sleep mode?

I'm writing an application that allows people in danger to call 911.
This is how it should work:
He (or she) feels danger.
He pushes the volume-down key three times.
My app calls 911.
But I'm facing the following problem: how can I receive a hardward key event in sleep mode?
I've searched Google and other search engines, but can't find anything related.
public class YourBoardcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_CAMERA_BUTTON.equals(intent.getAction())) {
Intent main = new Intent();//
}
}
}
And in your Manifest :
<receiver android:name="YourBoardcastReceiver">
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON" />
</intent-filter>
</receiver>
The only way I think you could do that is with a BroadcastReceiver, but it seems that the volume buttons do not generate an Intent when the screen is off (see here). The closest thing you might be able to do is use the camera button to do something similar.
Perhaps it is better this way, anyway, though. I imagine it would annoy users if their phone called 911 while in their pocket because of the volume buttons, or the camera button too for that matter. Also, it's not something I would expect to happen.

Categories

Resources