2016-06-08 2 views
-1

누군가가 백그라운드에서 Google 검색을 통합 안드로이드 응용 프로그램의 개발로 나를 도울 수 있습니까?안드로이드 어플 리케이션 구글 검색

나는 초보자이며 내 나라의 범죄를 자동으로 추적하기 위해 안드로이드 응용 프로그램을 설계하려고합니다. 누군가 내 애플리케이션에서 Google 맞춤 검색을 사용하라고 말했습니다. API 키와 검색 엔진 ID를 얻었지만 원하는 결과를 얻기 위해 구현하는 방법을 모릅니다.

전 인터넷을 통해 검색했지만 아무 소용이 없습니다. 그들이 말하는 모든 것은 Google지도와 다른 사람들이 내 문제와 관련이없는 것입니다.

모든 샘플 코드는 기꺼이 감사하겠습니다. 감사합니다

답변

0

Google 검색 엔진을 사용하여 이미지를 검색하는 데 사용되는 코드가 있습니다. 검색 할 내용에 대한 아이디어를 제공해야합니다.

내가

import com.google.api.client.http.HttpTransport; 
import com.google.api.client.http.javanet.NetHttpTransport; 
import com.google.api.client.json.JsonFactory; 
import com.google.api.client.json.jackson2.JacksonFactory; 
import com.google.api.services.customsearch.Customsearch; 
import com.google.api.services.customsearch.model.Result; 
import com.google.api.services.customsearch.model.Search; 

를 사용하는 주요 수입하고이

public List<Result> getSearchResult(String keyword){ 
    // Set up the HTTP transport and JSON factory 
    HttpTransport httpTransport = new NetHttpTransport(); 
    JsonFactory jsonFactory = new JacksonFactory(); 
    //HttpRequestInitializer initializer = (HttpRequestInitializer)new CommonGoogleClientRequestInitializer(API_KEY); 
    Customsearch customsearch = new Customsearch.Builder(
       new NetHttpTransport(), 
       new JacksonFactory(), 
       null) 
      .setApplicationName("RandomImage") 
      .build(); 

    List<Result> resultList = null; 
    try { 
     Customsearch.Cse.List list = customsearch.cse().list(keyword); 
     list.setKey(API_KEY); 
     list.setCx(SEARCH_ENGINE_ID); 
     list.setSafe("off"); 
     list.setSearchType("image"); 
     list.setImgSize("medium"); 
     list.setNum(3L); 

     Search results = list.execute(); 
     resultList = results.getItems(); 

    }catch (Exception e) { 
     e.printStackTrace(); 
    } 

    if (resultList == null) { 
     return new ArrayList<Result>(); 
    } else { 
     return resultList; 
    } 
} 

은 내가 이런 짓을 할 때 혼동되는 문서를 기억하는 검색 엔진을 사용하는 방법이지만 적어도이 나를 위해 일한 것이지요.

매니페스트

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.stochastic.randomimage" > 

    <uses-permission android:name="android.permission.INTERNET" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.stochastic.randomimage.MainActivity" 
      android:label="Random Image" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

레이아웃

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> 

    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/imageView" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" /> 

</RelativeLayout> 
+0

당신은 나에게 매니페스트 파일과 레이아웃 XML 파일을 표시 할 수 있습니다하시기 바랍니다. 미리 감사드립니다. Edwin –

+0

매니페스트 나 레이아웃에는 특별한 것이 하나도 없습니다. – Edwin

관련 문제