打开一个活动以编辑同步适配器中的联系人
在 Android SampleSyncAdapter 中,有以下一段代码:
/**
* Adds a profile action
*
* @param userId the userId of the sample SyncAdapter user object
* @return instance of ContactOperations
*/
public ContactOperations addProfileAction(long userId) {
mValues.clear();
if (userId != 0) {
mValues.put(SampleSyncAdapterColumns.DATA_PID, userId);
mValues.put(SampleSyncAdapterColumns.DATA_SUMMARY, mContext
.getString(R.string.syncadapter_profile_action));
mValues.put(SampleSyncAdapterColumns.DATA_DETAIL, mContext
.getString(R.string.view_profile));
mValues.put(Data.MIMETYPE, SampleSyncAdapterColumns.MIME_PROFILE);
addInsertOp();
}
return this;
}
我将其添加为我的活动的过滤器
<intent-filter>
<action android:name="@string/syncadapter_profile_action" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/vnd.myapp.profile"
android:host="contacts" />
</intent-filter>
,其中 SampleSyncAdapterColumns.MIME_PROFILE = vnd.android.cursor.item/vnd.myapp.profile
我添加了一个联系人,我可以看到该条目,但是当我点击它什么也没有发生。当用户单击某个活动时,我应该怎么做才能启动该活动? 我试图对预蜂窝设备执行此处的建议: 技巧是插入一个数据行“在 MyApp 中编辑”,这会将用户带到您的应用程序和您的应用程序 然后将提供编辑器活动
In the Android SampleSyncAdapter there is the following piece of code:
/**
* Adds a profile action
*
* @param userId the userId of the sample SyncAdapter user object
* @return instance of ContactOperations
*/
public ContactOperations addProfileAction(long userId) {
mValues.clear();
if (userId != 0) {
mValues.put(SampleSyncAdapterColumns.DATA_PID, userId);
mValues.put(SampleSyncAdapterColumns.DATA_SUMMARY, mContext
.getString(R.string.syncadapter_profile_action));
mValues.put(SampleSyncAdapterColumns.DATA_DETAIL, mContext
.getString(R.string.view_profile));
mValues.put(Data.MIMETYPE, SampleSyncAdapterColumns.MIME_PROFILE);
addInsertOp();
}
return this;
}
I added this as filter for my activity
<intent-filter>
<action android:name="@string/syncadapter_profile_action" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/vnd.myapp.profile"
android:host="contacts" />
</intent-filter>
where SampleSyncAdapterColumns.MIME_PROFILE = vnd.android.cursor.item/vnd.myapp.profile
I added a contact and I can see the entry but when I click on it nothing happens. What should I do to start an activity when the user clicks on it?
I was trying to do what is suggested Here for Pre-honeycomb devices: The trick is to insert a data row, "Edit in MyApp", which would take the user to your app and your app
would then provide an editor activity
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的意图过滤器可能不正确。根据此条目,正确的操作和数据项应该类似于以下内容:
I think your intent filter might be incorrect. According to this entry, the correct action and data items should be something like the following:
这就是我所做的。
在清单文件中,我为我的一个活动添加了这些意图过滤器。
当用户单击我使用示例同步适配器中的代码添加到我的同步适配器帐户中的配置文件操作时,将广播第一个意图过滤器(见上文)
第二个一种允许您在用户想要编辑联系人时处理由本机地址簿广播的意图。
考虑在第一种情况下,因为 mimetype 是您的同步适配器之一,您的活动将被直接调用。
在第二种情况下,将显示一个对话框,其中包含已注册的应用程序列表,用于处理 android:mimeType="vnd.android.cursor.item/person", android:mimeType="vnd.android 的 android.intent.action.EDIT .cursor.item/contact" 等
在我的活动中我有这样的方法:
This is what I did.
In the manifest file I added these intent filters for one of my activity
The first one will be broadcasted when the user clicks on the profile action that I added in my sync adapter accounts using the code in the sample sync adapter (see above)
The second one allows you to handle the intent that is boradcasted by the native address book when the user wants to edit the contact.
Consider that in the first case because the mimetype is that one of your syncadapter your activity will be called directly.
In the second case a dialog will be shown with the list of applications registered to handle the android.intent.action.EDIT for android:mimeType="vnd.android.cursor.item/person", android:mimeType="vnd.android.cursor.item/contact" etc
In my activity I have a method like this: