Ask for Camera permission to display video preview on dialer
This commit is contained in:
parent
b28b604bb7
commit
94444a01c5
3 changed files with 41 additions and 3 deletions
|
@ -75,7 +75,7 @@ import org.linphone.utils.PushNotificationUtils;
|
||||||
public abstract class MainActivity extends LinphoneGenericActivity
|
public abstract class MainActivity extends LinphoneGenericActivity
|
||||||
implements StatusBarFragment.MenuClikedListener, SideMenuFragment.QuitClikedListener {
|
implements StatusBarFragment.MenuClikedListener, SideMenuFragment.QuitClikedListener {
|
||||||
private static final int MAIN_PERMISSIONS = 1;
|
private static final int MAIN_PERMISSIONS = 1;
|
||||||
private static final int FRAGMENT_SPECIFIC_PERMISSION = 2;
|
protected static final int FRAGMENT_SPECIFIC_PERMISSION = 2;
|
||||||
|
|
||||||
private TextView mMissedCalls;
|
private TextView mMissedCalls;
|
||||||
private TextView mMissedMessages;
|
private TextView mMissedMessages;
|
||||||
|
@ -467,7 +467,7 @@ public abstract class MainActivity extends LinphoneGenericActivity
|
||||||
|
|
||||||
// Permissions
|
// Permissions
|
||||||
|
|
||||||
private boolean checkPermission(String permission) {
|
public boolean checkPermission(String permission) {
|
||||||
int granted = getPackageManager().checkPermission(permission, getPackageName());
|
int granted = getPackageManager().checkPermission(permission, getPackageName());
|
||||||
Log.i(
|
Log.i(
|
||||||
"[Permission] "
|
"[Permission] "
|
||||||
|
|
|
@ -19,9 +19,11 @@ along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.app.FragmentManager;
|
import android.app.FragmentManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
@ -30,6 +32,7 @@ import org.linphone.R;
|
||||||
import org.linphone.activities.MainActivity;
|
import org.linphone.activities.MainActivity;
|
||||||
import org.linphone.compatibility.Compatibility;
|
import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.core.tools.Log;
|
import org.linphone.core.tools.Log;
|
||||||
|
import org.linphone.utils.LinphoneUtils;
|
||||||
|
|
||||||
public class SettingsActivity extends MainActivity {
|
public class SettingsActivity extends MainActivity {
|
||||||
private static final int PERMISSIONS_REQUEST_OVERLAY = 206;
|
private static final int PERMISSIONS_REQUEST_OVERLAY = 206;
|
||||||
|
@ -108,6 +111,30 @@ public class SettingsActivity extends MainActivity {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(
|
||||||
|
int requestCode, String[] permissions, int[] grantResults) {
|
||||||
|
if (permissions.length <= 0) return;
|
||||||
|
if (requestCode == MainActivity.FRAGMENT_SPECIFIC_PERMISSION) {
|
||||||
|
for (int i = 0; i < permissions.length; i++) {
|
||||||
|
Log.i(
|
||||||
|
"[Permission] "
|
||||||
|
+ permissions[i]
|
||||||
|
+ " is "
|
||||||
|
+ (grantResults[i] == PackageManager.PERMISSION_GRANTED
|
||||||
|
? "granted"
|
||||||
|
: "denied"));
|
||||||
|
if (permissions[i].equals(Manifest.permission.CAMERA)
|
||||||
|
&& grantResults[i] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
LinphoneUtils.reloadVideoDevices();
|
||||||
|
LinphonePreferences.instance().setVideoPreviewEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void handleIntentExtras(Bundle extras) {
|
private void handleIntentExtras(Bundle extras) {
|
||||||
if (extras != null && extras.containsKey("Account")) {
|
if (extras != null && extras.containsKey("Account")) {
|
||||||
int accountIndex = extras.getInt("Account");
|
int accountIndex = extras.getInt("Account");
|
||||||
|
|
|
@ -19,6 +19,7 @@ along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -117,7 +118,17 @@ public class VideoSettingsFragment extends SettingsFragment {
|
||||||
new SettingListenerBase() {
|
new SettingListenerBase() {
|
||||||
@Override
|
@Override
|
||||||
public void onBoolValueChanged(boolean newValue) {
|
public void onBoolValueChanged(boolean newValue) {
|
||||||
mPrefs.setVideoPreviewEnabled(newValue);
|
if (newValue) {
|
||||||
|
if (!((SettingsActivity) getActivity())
|
||||||
|
.checkPermission(Manifest.permission.CAMERA)) {
|
||||||
|
((SettingsActivity) getActivity())
|
||||||
|
.requestPermissionIfNotGranted(Manifest.permission.CAMERA);
|
||||||
|
} else {
|
||||||
|
mPrefs.setVideoPreviewEnabled(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mPrefs.setVideoPreviewEnabled(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue