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>
당신은 나에게 매니페스트 파일과 레이아웃 XML 파일을 표시 할 수 있습니다하시기 바랍니다. 미리 감사드립니다. Edwin –
매니페스트 나 레이아웃에는 특별한 것이 하나도 없습니다. – Edwin