我正在制作预打包应用程序的品牌,它有一个联系人选择器选项,我需要禁用它,因为它对我们没用。它是使用个人地址进行单个用户搜索的。我在这里找到了一篇关于如何添加它的文章:http://apiminer.org/doc/guide/components/activities.html
他们将代码列为:
private void pickContact() {
// Create an intent to "pick" a contact, as defined by the content provider URI
Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT_REQUEST);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// If the request went well (OK) and the request was PICK_CONTACT_REQUEST
if (resultCode == Activity.RESULT_OK && requestCode == PICK_CONTACT_REQUEST) {
// Perform a query to the contact's content provider for the contact's name
Cursor cursor = getContentResolver().query(data.getData(),
new String[] {Contacts.DISPLAY_NAME}, null, null, null);
if (cursor.moveToFirst()) { // True if the cursor is not empty
int columnIndex = cursor.getColumnIndex(Contacts.DISPLAY_NAME);
String name = cursor.getString(columnIndex);
// Do something with the selected contact's name...
}
}
}
我只是想禁用它。我可以从它正在调用它们的文件夹中删除图像,但这仍然是一个活跃的角落。那就是这样做的可能性很差。我试过在代码中注释并删除这些提及,它只会抛出2-3个错误。
这是我的HomeActivity.java文件,显示代码:
package com.votinginfoproject.VotingInformationProject.activities;
import android.app.LoaderManager;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.votinginfoproject.VotingInformationProject.R;
import com.votinginfoproject.VotingInformationProject.fragments.HomeFragment;
import com.votinginfoproject.VotingInformationProject.models.VIPApp;
import com.votinginfoproject.VotingInformationProject.models.VIPAppContext;
import com.votinginfoproject.VotingInformationProject.models.VoterInfo;
public class HomeActivity extends FragmentActivity implements HomeFragment.OnInteractionListener,
LoaderManager.LoaderCallbacks<Cursor> {
static final int PICK_CONTACT_REQUEST = 1;
VIPApp app;
Uri contactUri;
EditText addressView;
LoaderManager loaderManager;
public String getSelectedParty() {
return selectedParty;
}
public void setSelectedParty(String selectedParty) {
this.selectedParty = selectedParty;
app.setSelectedParty(selectedParty);
}
String selectedParty;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
app = new VIPAppContext((VIPApp) getApplicationContext()).getVIPApp();
loaderManager = getLoaderManager();
selectedParty = "";
contactUri = null;
addressView = (EditText)findViewById(R.id.home_edittext_address);
// Get analytics tracker (should auto-report)
app.getTracker(VIPApp.TrackerName.APP_TRACKER);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
@Override
protected void onStop() {
super.onStop();
//Stop analytics tracking
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
@Override
protected void onStart() {
super.onStart();
//Get an Analytics tracker to report app starts, uncaught exceptions, etc.
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
return id == R.id.action_settings || super.onOptionsItemSelected(item);
}
public void onGoButtonPressed(View view) {
Intent intent = new Intent(this, VIPTabBarActivity.class);
startActivity(intent);
}
public void onSelectContactButtonPressed(View view) {
// contact picker intent to return an address; will only show contacts that have an address
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT_REQUEST);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == PICK_CONTACT_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// The user picked a contact.
// The Intent's data Uri identifies which contact was selected.
// Get the URI that points to the selected contact
contactUri = data.getData();
// restart loader, if a contact was already selected
loaderManager.destroyLoader(PICK_CONTACT_REQUEST);
// start async query to get contact info
loaderManager.initLoader(PICK_CONTACT_REQUEST, null, this);
} else {
// PASS (user didn't pick an address)
}
}
}
public void searchedAddress(VoterInfo voterInfo) {
// set VoterInfo object on app singleton
app.setVoterInfo(voterInfo, selectedParty);
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
if (contactUri == null) {
return null;
}
String[] projection = { ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS };
return new CursorLoader(this, contactUri, projection, null, null, null);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
if (data.getCount() > 0) {
data.moveToFirst();
// get result with single column, named data1
String address = data.getString(0);
Log.d("HomeActivity", "Got cursor result: " + address);
// set address found in view
addressView.setText(address);
// initate search with new address
HomeFragment myFragment = (HomeFragment)getSupportFragmentManager().findFragmentById(R.id.home_fragment);
myFragment.makeElectionQuery();
} else {
Log.e("HomeActivity", "Cursor got no results!");
}
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
// PASS
}
}
有人有解决方案吗?