我在这里遇到的错误startActivityForResult(意图,REQUEST_CODE_CHAT_FORWARD);
声明如下:
BaseFragmentActivityApi16.startActivityForResult
只能从相同的库组(groupId=com.android.support
)中调用,更少...(Ctrl + F1)
此API已标记为未满足的限制。 API限制示例:*方法只能由子类调用*方法只能从相同的库中访问(由Gradle库组ID定义)*方法只能从测试中访问。您可以使用@RestrictTo注释添加自己的API限制。问题ID:RestrictedApi
private void setupMenu() {
menuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
menuUsersRecyclerAdapter = new MenuUsersRecyclerAdapter(this, myUsers);
menuRecyclerView.setAdapter(menuUsersRecyclerAdapter);
swipeMenuRecyclerView.setColorSchemeResources(R.color.colorAccent);
swipeMenuRecyclerView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
fetchContacts();
}
});
searchContact.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
menuUsersRecyclerAdapter.getFilter().filter(editable.toString());
}
});
}
private void setProfileImage(ImageView imageView) {
if (userMe != null)
Glide.with(this).load(userMe.getImage()).apply(new RequestOptions().placeholder(R.drawable.yoohoo_placeholder)).into(imageView);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case CONTACTS_REQUEST_CODE:
fetchContacts();
break;
}
}
private void fetchContacts() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
if (!FetchMyUsersService.STARTED) {
if (!swipeMenuRecyclerView.isRefreshing())
swipeMenuRecyclerView.setRefreshing(true);
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if (firebaseUser != null) {
firebaseUser.getIdToken(true).addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
@Override
public void onComplete(@NonNull Task<GetTokenResult> task) {
if (task.isSuccessful()) {
String idToken = task.getResult().getToken();
FetchMyUsersService.startMyUsersService(MainActivity.this, userMe.getId(), idToken);
}
}
});
}
}
} else {
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.READ_CONTACTS}, CONTACTS_REQUEST_CODE);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
markOnline(false);
}
@Override
public void onBackPressed() {
if (ElasticDrawer.STATE_CLOSED != drawerLayout.getDrawerState()) {
drawerLayout.closeMenu(true);
} else if (isContextualMode()) {
disableContextualMode();
} else if (viewPager.getCurrentItem() != 0) {
viewPager.post(new Runnable() {
@Override
public void run() {
viewPager.setCurrentItem(0);
}
});
} else {
super.onBackPressed();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case (REQUEST_CODE_CHAT_FORWARD):
if (resultCode == Activity.RESULT_OK) {
//show forward dialog to choose users
messageForwardList.clear();
ArrayList<Message> temp = data.getParcelableArrayListExtra("FORWARD_LIST");
messageForwardList.addAll(temp);
userSelectDialogFragment = UserSelectDialogFragment.newInstance(this, myUsers);
FragmentManager manager = getSupportFragmentManager();
Fragment frag = manager.findFragmentByTag(USER_SELECT_TAG);
if (frag != null) {
manager.beginTransaction().remove(frag).commit();
}
userSelectDialogFragment.show(manager, USER_SELECT_TAG);
}
break;
}
}
private void sortMyGroupsByName() {
Collections.sort(myGroups, new Comparator<Group>() {
@Override
public int compare(Group group1, Group group2) {
return group1.getName().compareToIgnoreCase(group2.getName());
}
});
}
private void sortMyUsersByName() {
Collections.sort(myUsers, new Comparator<User>() {
@Override
public int compare(User user1, User user2) {
return user1.getNameToDisplay().compareToIgnoreCase(user2.getNameToDisplay());
}
});
}
@Override
void userAdded(User value) {
if (value.getId().equals(userMe.getId()))
return;
else if (helper.getCacheMyUsers() != null && helper.getCacheMyUsers().containsKey(value.getId())) {
value.setNameInPhone(helper.getCacheMyUsers().get(value.getId()).getNameToDisplay());
addUser(value);
} else {
for (Contact savedContact : contactsData) {
if (Helper.contactMatches(value.getId(), savedContact.getPhoneNumber())) {
value.setNameInPhone(savedContact.getName());
addUser(value);
helper.setCacheMyUsers(myUsers);
break;
}
}
}
}
@Override
void groupAdded(Group group) {
if (!myGroups.contains(group)) {
myGroups.add(group);
sortMyGroupsByName();
}
}
@Override
void userUpdated(User value) {
if (value.getId().equals(userMe.getId())) {
userMe = value;
setProfileImage(usersImage);
} else if (helper.getCacheMyUsers() != null && helper.getCacheMyUsers().containsKey(value.getId())) {
value.setNameInPhone(helper.getCacheMyUsers().get(value.getId()).getNameToDisplay());
updateUser(value);
} else {
for (Contact savedContact : contactsData) {
if (Helper.contactMatches(value.getId(), savedContact.getPhoneNumber())) {
value.setNameInPhone(savedContact.getName());
updateUser(value);
helper.setCacheMyUsers(myUsers);
break;
}
}
}
}
private void updateUser(User value) {
int existingPos = myUsers.indexOf(value);
if (existingPos != -1) {
myUsers.set(existingPos, value);
menuUsersRecyclerAdapter.notifyItemChanged(existingPos);
refreshUsers(existingPos);
}
}
@Override
void groupUpdated(Group group) {
int existingPos = myGroups.indexOf(group);
if (existingPos != -1) {
myGroups.set(existingPos, group);
//menuUsersRecyclerAdapter.notifyItemChanged(existingPos);
//refreshUsers(existingPos);
}
}
@Override
void onSinchConnected() {
}
@Override
void onSinchDisconnected() {
}
private void addUser(User value) {
if (!myUsers.contains(value)) {
myUsers.add(value);
sortMyUsersByName();
menuUsersRecyclerAdapter.notifyDataSetChanged();
refreshUsers(-1);
}
}
@Override
public void OnUserClick(final User user, int position, View userImage) {
if (ElasticDrawer.STATE_CLOSED != drawerLayout.getDrawerState()) {
drawerLayout.closeMenu(true);
}
if (userImage == null) {
userImage = usersImage;
}
Intent intent = ChatActivity.newIntent(this, messageForwardList, user);
if (Build.VERSION.SDK_INT > 21) {
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, userImage, "backImage");
startActivityForResult(intent, REQUEST_CODE_CHAT_FORWARD, options.toBundle());
}
else {
startActivityForResult(intent, REQUEST_CODE_CHAT_FORWARD);
overridePendingTransition(0, 0);
}
if (userSelectDialogFragment != null)
userSelectDialogFragment.dismiss();
}
@Override
public void OnGroupClick(Group group, int position, View userImage) {
Intent intent = ChatActivity.newIntent(this, messageForwardList, group);
if (userImage == null) {
userImage = usersImage;
}
if (Build.VERSION.SDK_INT > 21) {
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, userImage, "backImage");
startActivityForResult(intent, REQUEST_CODE_CHAT_FORWARD, options.toBundle());
}
else {
startActivityForResult(intent, REQUEST_CODE_CHAT_FORWARD);
overridePendingTransition(0, 0);
}
if (userSelectDialogFragment != null)
userSelectDialogFragment.dismiss();
}
private void refreshUsers(int pos) {
Fragment frag = getSupportFragmentManager().findFragmentByTag(USER_SELECT_TAG);
if (frag != null) {
userSelectDialogFragment.refreshUsers(pos);
}
}
private void markOnline(boolean b) {
//Mark online boolean as b in firebase
usersRef.child(userMe.getId()).child("online").setValue(b);
}