******这是我的Android manifest.xml中的Activity实现******
<activity
android:name="com.zameen.zameenapp.GizmosActivity"
android:label="@string/title_gizmos" >
<intent-filter android:label="@string/filter_title_viewgizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/gizmos" />
<!-- note that the leading "/" is required for pathPrefix-->
<!-- Accepts URIs that begin with "example://gizmos”
<data android:scheme="example"
android:host="gizmos" />
-->
</intent-filter>
</activity>
这是我的活动课
package com.zameen.zameenapp;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import android.app.Activity;
import android.content.Intent;
import android.drm.DrmStore.Action;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
public class GizmosActivity extends Activity
{
static final Uri APP_URI = Uri.parse("android-app://com.zameen.zameenapp/http/www.example.com/gizmos");
static final Uri WEB_URL = Uri.parse("http://www.example.com/gizmos/");
private GoogleApiClient mClient;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_side_menu);
mClient = new GoogleApiClient.Builder(this).addApi(AppIndex.APP_INDEX_API).build();
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
}
@Override
public void onStart() {
super.onStart();
// Connect your client
mClient.connect();
// Define a title for your current page, shown in autocompletion UI
String title = "App Indexing API Title";
// Construct the Action performed by the user
Action viewAction = Action.newAction(Action.TYPE_VIEW, title, WEB_URL, APP_URI);
// Call the App Indexing API start method after the view has completely rendered
AppIndex.AppIndexApi.start(mClient, viewAction);
}
@Override
public void onStop() {
// Call end() and disconnect the client
String title = "App Indexing API Title";
Action viewAction = Action.newAction(Action.TYPE_VIEW, title, WEB_URL, APP_URI);
AppIndex.AppIndexApi.end(mClient, viewAction);
mClient.disconnect();
super.onStop();
}
}
我正在我的应用程序中实现 Google 索引,我已经在 www.example.com/gizmos 的特定 Url 上进行了检查,我可以使用 adb 命令行轻松启动我的活动。问题是我必须导入动作类库文件import com.google.android.gms.appindexing.Action; 但是每次我尝试添加它时都会出错,并且当按照 Eclipse 的建议导入规定的库文件时,我会在AppIndex.AppIndexApi.end和newAction(Action.TYPE_VIEW, title, WEB_URL, APP_URI);我想在我的 GizmosActivity 中为 Action 类导入库文件,这可以解决这个问题。也有人可以告诉我我的 GizmosActivity 代码和清单是否定义明确?以及如何测试它是否运行良好我将非常感谢该解决方案