Google image search API

Google image search api not free
https://developers.google.com/custom-search/json-api/v1/overview

https://www.googleapis.com/customsearch/v1?key=(Your_Key_here)&cx=015336050490612329500:p3iuq9ghvuo&q=flower&searchType=image&fileType=jpg&imgSize=small&alt=json

Remember to key a key which is free for 100 queries per day I think. Substitute your key above

(Your_Key_here)

.

Result (In real nice json format)

{
 "kind": "customsearch#search",
 "url": {
  "type": "application/json",
  "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
 },
 "queries": {
  "request": [
   {
    "title": "Google Custom Search - flower",
    "totalResults": "692000000",
    "searchTerms": "flower",
    "count": 10,
    "startIndex": 1,
    "inputEncoding": "utf8",
    "outputEncoding": "utf8",
    "safe": "off",
    "cx": "015336050490612329500:p3iuq9ghvuo",
    "fileType": "jpg",
    "searchType": "image",
    "imgSize": "small"
   }
  ],
  "nextPage": [
   {
    "title": "Google Custom Search - flower",
    "totalResults": "692000000",
    "searchTerms": "flower",
    "count": 10,
    "startIndex": 11,
    "inputEncoding": "utf8",
    "outputEncoding": "utf8",
    "safe": "off",
    "cx": "015336050490612329500:p3iuq9ghvuo",
    "fileType": "jpg",
    "searchType": "image",
    "imgSize": "small"
   }
  ]
 },
 "context": {
  "title": "Google"
 },
 "searchInformation": {
  "searchTime": 2.018194,
  "formattedSearchTime": "2.02",
  "totalResults": "692000000",
  "formattedTotalResults": "692,000,000"
 },
 "items": [
  {
   "kind": "customsearch#result",
   "title": "Origami Flowers and Roses: Give that special someone a flowers ...",
   "htmlTitle": "Origami \u003cb\u003eFlowers\u003c/b\u003e and Roses: Give that special someone a \u003cb\u003eflowers\u003c/b\u003e ...",
   "link": "https://www.origami-resource-center.com/images/xflower-Buttonhole-Jackson.jpg.pagespeed.ic.sKI3keMooQ.jpg",
   "displayLink": "www.origami-resource-center.com",
   "snippet": "Origami Flowers and Roses: Give that special someone a flowers ...",
   "htmlSnippet": "Origami \u003cb\u003eFlowers\u003c/b\u003e and Roses: Give that special someone a \u003cb\u003eflowers\u003c/b\u003e ...",
   "mime": "image/jpeg",
   "image": {
    "contextLink": "https://www.origami-resource-center.com/origami-flowers.html",
    "height": 100,
    "width": 100,
    "byteSize": 2071,
    "thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ-yjmSLkNb9uAk3Obejt8rZDSpkMEreLIcEG-trILXYr7-6g_x-QBKag",
    "thumbnailHeight": 82,
    "thumbnailWidth": 82
   }
  },
  {
   "kind": "customsearch#result",
   "title": "A Plastic Spoon Spring Flower Craft For Kids",
   "htmlTitle": "A Plastic Spoon Spring \u003cb\u003eFlower\u003c/b\u003e Craft For Kids",
   "link": "https://i2.wp.com/kidfriendlythingstodo.com/wp-content/uploads/2016/04/flowers-fb-plastic-spoon-craft.jpg?fit=100%2C100",
   "displayLink": "kidfriendlythingstodo.com",
   "snippet": "A Plastic Spoon Spring Flower Craft For Kids",
   "htmlSnippet": "A Plastic Spoon Spring \u003cb\u003eFlower\u003c/b\u003e Craft For Kids",
   "mime": "image/jpeg",
   "image": {
    "contextLink": "http://kidfriendlythingstodo.com/2016/04/a-plastic-spoon-spring-flower-craft-for-kids/",
    "height": 100,
    "width": 100,
    "byteSize": 14127,
    "thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcREdQcdDxVsiiLluVUZA_dvJXGS3hxsyso3v8b0k9ZJ_wTZKV8a-r00jsE",
    "thumbnailHeight": 82,
    "thumbnailWidth": 82
   }
  },
  {
   "kind": "customsearch#result",
   "title": "Origami Flowers and Roses: Give that special someone a flowers ...",
   "htmlTitle": "Origami \u003cb\u003eFlowers\u003c/b\u003e and Roses: Give that special someone a \u003cb\u003eflowers\u003c/b\u003e ...",
   "link": "https://www.origami-resource-center.com/images/xflower-Buttonhole-Traditional-2.jpg.pagespeed.ic.pI1sdhAHWP.jpg",
   "displayLink": "www.origami-resource-center.com",
   "snippet": "Origami Flowers and Roses: Give that special someone a flowers ...",
   "htmlSnippet": "Origami \u003cb\u003eFlowers\u003c/b\u003e and Roses: Give that special someone a \u003cb\u003eflowers\u003c/b\u003e ...",
   "mime": "image/jpeg",
   "image": {
    "contextLink": "https://www.origami-resource-center.com/origami-flowers.html",
    "height": 100,
    "width": 100,
    "byteSize": 1831,
    "thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQw3kcM5z4JtvO7keB03332pLgCgrQTr0y6_66FgxauA6LGqWmUayk63Q",
    "thumbnailHeight": 82,
    "thumbnailWidth": 82
   }
  },
  {
   "kind": "customsearch#result",
   "title": "Flower Care on the App Store",
   "htmlTitle": "\u003cb\u003eFlower\u003c/b\u003e Care on the App Store",
   "link": "http://is5.mzstatic.com/image/thumb/Purple71/v4/b0/80/62/b0806219-32ec-5f8a-c50b-a9ab95d582c7/source/100x100bb.jpg",
   "displayLink": "itunes.apple.com",
   "snippet": "Flower Care on the App Store",
   "htmlSnippet": "\u003cb\u003eFlower\u003c/b\u003e Care on the App Store",
   "mime": "image/jpeg",
   "image": {
    "contextLink": "https://itunes.apple.com/us/app/flower-care/id1095274672?mt=8",
    "height": 100,
    "width": 100,
    "byteSize": 1919,
    "thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQhVe-_MSndGclkeTXwFthBx_LB_02vG3oMwHJvtYL1vZFJnJaqjdxyOLU",
    "thumbnailHeight": 82,
    "thumbnailWidth": 82
   }
  },
  {
   "kind": "customsearch#result",
   "title": "Origami Flowers and Roses: Give that special someone a flowers ...",
   "htmlTitle": "Origami \u003cb\u003eFlowers\u003c/b\u003e and Roses: Give that special someone a \u003cb\u003eflowers\u003c/b\u003e ...",
   "link": "https://www.origami-resource-center.com/images/xflower-20-Unit-Flower.jpg.pagespeed.ic.-0qtEVtjj_.jpg",
   "displayLink": "www.origami-resource-center.com",
   "snippet": "Origami Flowers and Roses: Give that special someone a flowers ...",
   "htmlSnippet": "Origami \u003cb\u003eFlowers\u003c/b\u003e and Roses: Give that special someone a \u003cb\u003eflowers\u003c/b\u003e ...",
   "mime": "image/jpeg",
   "image": {
    "contextLink": "https://www.origami-resource-center.com/origami-flowers.html",
    "height": 101,
    "width": 100,
    "byteSize": 2702,
    "thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTRXfdkbD8aPS8S-E3i7nE8XrBXnMzBpDvkOmMmj78OLMtAZDQkBpovig",
    "thumbnailHeight": 83,
    "thumbnailWidth": 82
   }
  },
  {
   "kind": "customsearch#result",
   "title": "Stitch and Flower - YouTube",
   "htmlTitle": "Stitch and \u003cb\u003eFlower\u003c/b\u003e - YouTube",
   "link": "https://yt3.ggpht.com/-8lMf8Xmh7nc/AAAAAAAAAAI/AAAAAAAAAAA/_i1B0NGWaHg/s100-c-k-no-mo-rj-c0xffffff/photo.jpg",
   "displayLink": "www.youtube.com",
   "snippet": "Stitch and Flower - YouTube",
   "htmlSnippet": "Stitch and \u003cb\u003eFlower\u003c/b\u003e - YouTube",
   "mime": "image/jpeg",
   "image": {
    "contextLink": "https://www.youtube.com/channel/UCnubdGJNP9CoE1YU7ITAQIw",
    "height": 100,
    "width": 100,
    "byteSize": 7254,
    "thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSUN9bJV6t4Rnjg62NTAzBqEcNXL7c6cf-1o_Nw7yxW8c3QNdp_YYnWeR0",
    "thumbnailHeight": 82,
    "thumbnailWidth": 82
   }
  },
  {
   "kind": "customsearch#result",
   "title": "Flower Dreams - Forget-me-not - Decorations - Swarovski Online Shop",
   "htmlTitle": "\u003cb\u003eFlower\u003c/b\u003e Dreams - Forget-me-not - Decorations - Swarovski Online Shop",
   "link": "https://www.swarovski.com/is-bin/intershop.static/WFS/SCO-Media-Site/-/-/publicimages//CG/B2C/PROD/100/Swarovski-Flower-Dreams-Orchid-5254318-W100.jpg",
   "displayLink": "www.swarovski.com",
   "snippet": "Flower Dreams - Forget-me-not - Decorations - Swarovski Online Shop",
   "htmlSnippet": "\u003cb\u003eFlower\u003c/b\u003e Dreams - Forget-me-not - Decorations - Swarovski Online Shop",
   "mime": "image/jpeg",
   "image": {
    "contextLink": "https://www.swarovski.com/Web_US/en/5254325/product/Flower_Dreams_-_Forget-me-not.html",
    "height": 100,
    "width": 100,
    "byteSize": 2299,
    "thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ_qqixkF9LLgzOIJFRxfwh1ICZhiSUhBHIytboivGuKFtSUnsdq6PeEno",
    "thumbnailHeight": 82,
    "thumbnailWidth": 82
   }
  },
  {
   "kind": "customsearch#result",
   "title": "Punzie Flower - YouTube",
   "htmlTitle": "Punzie \u003cb\u003eFlower\u003c/b\u003e - YouTube",
   "link": "https://yt3.ggpht.com/-c-r0H04wMhQ/AAAAAAAAAAI/AAAAAAAAAAA/10_yPsHJ9lI/s100-c-k-no-mo-rj-c0xffffff/photo.jpg",
   "displayLink": "www.youtube.com",
   "snippet": "Punzie Flower - YouTube",
   "htmlSnippet": "Punzie \u003cb\u003eFlower\u003c/b\u003e - YouTube",
   "mime": "image/jpeg",
   "image": {
    "contextLink": "https://www.youtube.com/channel/UCUiTMhB1TBPHcvkKMo0xShg",
    "height": 100,
    "width": 100,
    "byteSize": 4340,
    "thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTI4EWBxfbfZKV6SI3uKNFELsAC9vlP4Y0GBxcCp_QHxTUlB6w_0OguVA",
    "thumbnailHeight": 82,
    "thumbnailWidth": 82
   }
  },
  {
   "kind": "customsearch#result",
   "title": "Flower Dreams - Daisy - Decorations - Swarovski Online Shop",
   "htmlTitle": "\u003cb\u003eFlower\u003c/b\u003e Dreams - Daisy - Decorations - Swarovski Online Shop",
   "link": "https://www.swarovski.com/is-bin/intershop.static/WFS/SCO-Media-Site/-/-/publicimages//CG/B2C/PROD/100/Swarovski-Flower-Dreams-Daisy-5254328-W100.jpg",
   "displayLink": "www.swarovski.com",
   "snippet": "Flower Dreams - Daisy - Decorations - Swarovski Online Shop",
   "htmlSnippet": "\u003cb\u003eFlower\u003c/b\u003e Dreams - Daisy - Decorations - Swarovski Online Shop",
   "mime": "image/jpeg",
   "image": {
    "contextLink": "https://www.swarovski.com/Web_GB/en/5254328/product/Flower_Dreams_-_Daisy.html",
    "height": 100,
    "width": 100,
    "byteSize": 2868,
    "thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRCYnH-Lc5AK4gamwMZNAInR5nvRrLJVVZUIFdtD9HCF6Y885K9nTWNaVk",
    "thumbnailHeight": 82,
    "thumbnailWidth": 82
   }
  },
  {
   "kind": "customsearch#result",
   "title": "Monthly Flowers Club - Monthly Flower Delivery | Fresh Cut Flower ...",
   "htmlTitle": "Monthly \u003cb\u003eFlowers\u003c/b\u003e Club - Monthly \u003cb\u003eFlower\u003c/b\u003e Delivery | Fresh Cut \u003cb\u003eFlower\u003c/b\u003e ...",
   "link": "https://www.flowermonthclub.com/media/catalog/product/cache/16/small_image/100x100/9df78eab33525d08d6e5fb8d27136e95/e/m/email_flower.jpg",
   "displayLink": "www.flowermonthclub.com",
   "snippet": "Monthly Flowers Club - Monthly Flower Delivery | Fresh Cut Flower ...",
   "htmlSnippet": "Monthly \u003cb\u003eFlowers\u003c/b\u003e Club - Monthly \u003cb\u003eFlower\u003c/b\u003e Delivery | Fresh Cut \u003cb\u003eFlower\u003c/b\u003e ...",
   "mime": "image/jpeg",
   "image": {
    "contextLink": "https://www.flowermonthclub.com/the-fresh-cut-flower-of-the-month-club.htm",
    "height": 100,
    "width": 100,
    "byteSize": 4465,
    "thumbnailLink": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSVqwX3DIJH69bBe4nMLhI7t6-VWtYo7bLJTw_Hdq6CbOtFPhNyDfGAOU4",
    "thumbnailHeight": 82,
    "thumbnailWidth": 82
   }
  }
 ]
}

Advertisements

Locate you IR input device file

cat /proc/bus/input/devices

I: Bus=0019 Vendor=0001 Product=0001 Version=0100
N: Name=”sunxi-ir”
P: Phys=RemoteIR/input1
S: Sysfs=/devices/virtual/input/input2
U: Uniq=
H: Handlers=sysrq kbd event2 cpufreq_interactive
B: PROP=0
B: EV=100003
B: KEY=ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe

Along with other device file you will get IR device file info as above (If it is supported). From above information you will know that event2 is your IR device file.

evtest /dev/input/event2

Sometime if things doesn’t work out as expected you can reinsert the module:

rmmod sunxi_ir_rx
insmod /system/vendor/modules/sunxi-ir-rx.ko

Android app start at bootup

You can write an intent filter and then write a broadcast receiver from where you can start your app.

All this is okay but there is one weird problem. After installing this app you need to start it at least once before it actually starts automatically on BOOT_COMPLETED.

If you just install and think that on reboot it will start automatically. Not gonna happen.

Auto CPU Hotplug

Android was not made for embedded system. It was designed for Mobile phones. You will find many instances where things will not be working as expected, if you are working to make android work for embedded system.

One of the issue was this cpu killing each other to save battery.


<7>[ 154.890391] [rfkill]: rfkill set power 1
<5>[ 158.611398] CPU1: shutdown
<6>[ 158.611431] [hotplug]: cpu(0) try to kill cpu(1)
<6>[ 158.611495] [hotplug]: cpu1 is killed! .
<7>[ 161.110704] CPU1: Booted secondary processor
<7>[ 162.610842] CPU3: Booted secondary processor
<5>[ 163.611427] CPU1: shutdown
<6>[ 163.611454] [hotplug]: cpu(2) try to kill cpu(1)
<6>[ 163.612531] [hotplug]: cpu1 is killed! .

If you do


cat /sys/devices/system/cpu/offline

then you will see that some cores are killed not online

 


cat /sys/devices/system/cpu/online

Above will give you which cores are online at this moment.

 

I saw some process named auto_cpu_hotplu but I was not able to kill that process.

Fix was very simple though

echo 0 > /sys/kernel/autohotplug/enable

Done!!

For highest performance you can issue below commands also

 

echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

echo 1 > /sys/devices/system/cpu/cpu0/online

echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor

echo 1 > /sys/devices/system/cpu/cpu1/online

echo 1 > /sys/devices/system/cpu/cpu2/online

echo 1 > /sys/devices/system/cpu/cpu3/online

 

Android check if a particular service is running


public static boolean isAppRunning(final Context context, 
              final String packageName) {

  final ActivityManager activityManager = 
       (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

  final List<ActivityManager.RunningAppProcessInfo> procInfos = 
       activityManager.getRunningAppProcesses();

  if (procInfos != null)
  {
    for (final ActivityManager.RunningAppProcessInfo processInfo : procInfos) {
      if (processInfo.processName.equals(packageName)) {
        return true;
      }
    }
  }
  return false;
}

In my case packageName was` ​com.example.myService:qt`

Android AOSP – Running something at bootup

There will be some .mk file where you need to put code to copy files to the android system.

 

 


# file copy
PRODUCT_COPY_FILES += \
device/softwinner/nanopi-h3/extras/kernelService:system/bin/kernelService \
device/softwinner/nanopi-h3/extras/kernelService.sh:system/bin/kernelService.sh \
device/softwinner/nanopi-h3/extras/usr/share/ac.conf:system/usr/share/config.conf

Now in init.rc
 

#service for kernel commands like

service someName /system/bin/kernelService.sh

class main

oneshot

 

Android – calling Java method from jni (C/C++) even Qt

From C++ to java

Let us first create a method in Java which we will call from C++:


public class MyJavaClass

{

  private final Activity m_MainActivity;

  public MyJavaClass(final Activity MainActivity)

  {

    // Save the main activity pointer

    m_MainActivity = MainActivity;

  }

  public void TestCallMe(int param1, String param2)
  {

  // Do something here

  }

}

Now we want to call TestCallMe which has two params, one integer and one string. Using Qt class is possible to call this method from C++ side as follow:

int Param1;

QString Param2;

MyJavaClass.callMethod<void>("TestCallMe",

"(ILjava/lang/String;)V",

Param1,

QAndroidJniObject::fromString(Param2).object<jstring>()

);

This here is

“(ILjava/lang/String;)V”,

basically method definition.

So in addition to method name, the params accepted using the JNI format specification.

Also you need to convert the data type in specific way before passing to Java method.

Native variable like integer doesn’t need specific conversion but some more complex element, like QString as in example, require a conversion to the JNI native format jstring. Anyway reading the JNI types map it will be possible to exchange the majority of common format available.