mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
bug 47671 -- don't show crashy photo button if no camera present
We were crashing when trying to take a photo if no camera was present on the device, since no activity can be found for the camera intent and an exception is thrown. Work around this by simply checking if the device has a camera via the package manager feature checks, and hiding the menu item if relevant. GitHub: https://github.com/wikimedia/apps-android-commons/pull/13 Change-Id: I635946ed32cf768917db4a8dff0058061e45e6ec
This commit is contained in:
parent
2256c34947
commit
e6ef53429d
2 changed files with 10 additions and 0 deletions
|
|
@ -183,5 +183,10 @@ public class CommonsApplication extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean deviceHasCamera() {
|
||||
PackageManager pm = getPackageManager();
|
||||
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) ||
|
||||
pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,6 +266,11 @@ public class ContributionsListFragment extends SherlockFragment {
|
|||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.clear(); // See http://stackoverflow.com/a/8495697/17865
|
||||
inflater.inflate(R.menu.fragment_contributions_list, menu);
|
||||
|
||||
CommonsApplication app = (CommonsApplication)getActivity().getApplicationContext();
|
||||
if (!app.deviceHasCamera()) {
|
||||
menu.findItem(R.id.menu_from_camera).setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue