Android에서 getContentResolver ()를 어떻게 호출 할 수 있습니까?
getContentResolver()호출 되는 컨텍스트를 알고 싶습니다 .
다음과 같은 시나리오
가 있습니다. 활동 myFunc()이 아닌 클래스 B 의 메서드를 호출하는 활동 A가 있습니다.
따라서 클래스 BI에서 getContentResolver(). 나는 직접 전화했다 getContentResolver(). 오류를 표시했습니다. 그런 다음 myFunc(Acitivy act)활동에서 전화 act.getContentResolver()를 걸어 문제를 해결했습니다. 이것이를 호출하는 유일한 방법 getContentResolver()입니다. 즉, 활동과 관련하여 사용할 수 있거나 단독으로 사용할 수 있습니다.
getContentResolver()클래스의 메서드 android.content.Context이므로 호출하려면 Context 인스턴스 (예 : Activity 또는 Service)가 필요합니다.
다음과 같이 사용할 수 있습니다.
getApplicationContext().getContentResolver()
적절한 맥락으로.
이 getContentResolver()메서드는 객체를 Contact사용하여 를 쿼리 할 때도 사용됩니다 Cursor. 나는 내 앱에 포함시킬 사람의 전화 번호에서 연락처 정보를 찾고 getContentResolver()Android 전화 Contacts앱 을 쿼리하는 데 사용 했습니다 . 쿼리의 다양한 요소 (아래에 표시됨)는 원하는 연락처 정보의 종류와 주문 여부 등을 나타냅니다. 여기에 또 다른 예가 있습니다.
Android 문서 의 Content Provider Basics 페이지에서.
// Queries the user dictionary and returns results
mCursor = getContentResolver().query(
UserDictionary.Words.CONTENT_URI, // The content URI of the words table
mProjection, // The columns to return for each row
mSelectionClause // Selection criteria
mSelectionArgs, // Selection criteria
mSortOrder); // The sort order for the returned rows
import android.content.Context;
import android.content.ContentResolver;
context = (Context)this;
ContentResolver result = (ContentResolver)context.getContentResolver();
이것은 나를 위해 일했습니다. getBaseContext ();
//create activity object to get activity from Activity class for use to content resolver
private final Activity ActivityObj;
//create constructor with ActivityObj to get activity from Activity class
public RecyclerViewAdapterClass(Activity activityObj) {
this.ActivityObj = activityObj;
}
ActivityObj.getContentResolver(),.....,.....,null);
Kotlin의 contentResolver, 내부 활동, 객체 클래스 및 ...에 액세스합니다.
Application().contentResolver
ContentResolver contentResolver = getContext (). getContentResolver ();
참조 URL : https://stackoverflow.com/questions/3750903/how-can-getcontentresolver-be-called-in-android
'Nice programing' 카테고리의 다른 글
| 다음 개발자가 코드를 더 쉽게 이해할 수 있도록하려면 어떻게해야합니까? (0) | 2020.12.28 |
|---|---|
| SQL 테이블의 기본 키 자동 증가 (0) | 2020.12.28 |
| MessageBox.Show 대화 상자에서 '예'및 '아니요'버튼의 버튼 텍스트를 변경하는 방법은 무엇입니까? (0) | 2020.12.28 |
| OS X의 명령 줄을 통해 활성 사용자의 이름을 어떻게 얻습니까? (0) | 2020.12.27 |
| foreach 루프에서 반복 횟수 계산 (0) | 2020.12.27 |