本文整理汇总了Java中android.hardware.display.DisplayManager.getDisplays方法的典型用法代码示例。如果您正苦于以下问题:Java DisplayManager.getDisplays方法的具体用法?Java DisplayManager.getDisplays怎么用?Java DisplayManager.getDisplays使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.hardware.display.DisplayManager
的用法示例。
在下文中一共展示了DisplayManager.getDisplays方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isScreenOn
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
private boolean isScreenOn() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
boolean screenOn = false;
for (Display display : dm.getDisplays()) {
if (display.getState() != Display.STATE_OFF) {
screenOn = true;
}
}
return screenOn;
} else {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
//noinspection deprecation
return pm.isScreenOn();
}
}
示例2: selectPhoto
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
/**
* Select a picture to show on remote presentation view
*/
private void selectPhoto() {
if (checkSelfPermission("android.permission.READ_EXTERNAL_STORAGE")
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{"android.permission.READ_EXTERNAL_STORAGE"},
REQUEST_STORAGE_PERMISSION);
} else {
DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
Display[] presentationDisplays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
if (presentationDisplays.length > 0) {
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(i,
getString(R.string.select_picture)), SELECT_PHOTO);
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage(getString(R.string.external_display_not_available));
alert.setPositiveButton(android.R.string.ok, null);
alert.show();
}
}
}
示例3: isScreenOn
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
private boolean isScreenOn(Context context) {
if (Build.VERSION.SDK_INT >= 20) {
DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
for (Display display : dm.getDisplays()) {
if (display.getState() != Display.STATE_OFF)
return true;
}
return false;
} else {
PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE);
return (powerManager.isScreenOn());
}
}
示例4: isScreenOn
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
public static boolean isScreenOn(Context context) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
boolean screenOn = false;
for (Display display : dm.getDisplays()) {
if (display.getState() != Display.STATE_OFF) {
screenOn = true;
}
}
return screenOn;
} else {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
//noinspection deprecation
return pm.isScreenOn();
}
}
示例5: onDisplayAdded
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
@Override
public void onDisplayAdded(int displayId) {
Intent intent = new Intent();
intent.setAction(U.SCREEN_CONNECT);
LocalBroadcastManager.getInstance(NotificationService.this).sendBroadcast(intent);
DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE);
Display[] displays = dm.getDisplays();
try {
if(displays[displays.length - 2].getDisplayId() == Display.DEFAULT_DISPLAY) {
Intent serviceIntent = new Intent(NotificationService.this, ScreenOnService.class);
startService(serviceIntent);
}
} catch (ArrayIndexOutOfBoundsException e) { /* Gracefully fail */ }
}
示例6: castScreenActive
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
public static boolean castScreenActive(Context context) {
DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
Display[] displays = dm.getDisplays();
for(Display display : displays) {
try {
if(Class.forName("android.view.Display")
.getMethod("getOwnerPackageName")
.invoke(display)
.equals("com.google.android.gms"))
return true;
} catch (Exception e) { /* Gracefully fail */ }
}
return false;
}
示例7: IsScreenOn
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
public boolean IsScreenOn() {
DisplayManager displayManager = (DisplayManager) _context.getSystemService(Context.DISPLAY_SERVICE);
if (displayManager == null) {
Logger.getInstance().Error(TAG, "displayManager is null!");
return false;
}
for (Display display : displayManager.getDisplays()) {
if (display.getState() != Display.STATE_OFF) {
return true;
}
}
return false;
}
示例8: isScreenOn
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
public static boolean isScreenOn(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
for (Display display : dm.getDisplays()) {
if (display.getState() != Display.STATE_OFF) {
return true;
}
}
return false;
} else {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
return powerManager.isScreenOn();
}
}
示例9: isScreenOn
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
public static boolean isScreenOn(Context context)
{
DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
for (Display display : dm.getDisplays())
{
if (display.getState() != Display.STATE_OFF)
return true;
}
return false;
}
示例10: isScreenOn
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
public static boolean isScreenOn(Context context) {
DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
for (Display display : dm.getDisplays()) {
if (display.getState() == Display.STATE_ON
|| display.getState() == Display.STATE_UNKNOWN) {
return true;
}
}
return false;
}
示例11: IsScreenOn
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
public boolean IsScreenOn() {
DisplayManager displayManager = (DisplayManager) _context.getSystemService(Context.DISPLAY_SERVICE);
for (Display display : displayManager.getDisplays()) {
if (display.getState() != Display.STATE_OFF) {
return true;
}
}
return false;
}
示例12: isScreenOn
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
boolean isScreenOn() {
if (Utils.isAndroidNewerThanL()) {
DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
for (Display display : dm.getDisplays()) {
if (display.getState() != Display.STATE_OFF) {
return true;
}
}
return false;
} else {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
return powerManager.isScreenOn();
}
}
示例13: isDisplayOn
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
private boolean isDisplayOn(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
for (Display display : dm.getDisplays()) {
if (display.getState() != Display.STATE_OFF) {
return true;
}
}
return false;
} else {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
return powerManager.isScreenOn();
}
}
示例14: onClock
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
/** Show a clock on remote presentation view */
private void onClock() {
DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
Display[] presentationDisplays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
if (presentationDisplays.length > 0) {
/**
* If there is more than one suitable presentation display, then we could consider
* giving the user a choice. For this example, we simply choose the first display
* which is the one the system recommends as the preferred presentation display.
*/
Display display = presentationDisplays[0];
try {
/** Clean up previously presentation view */
if (presentation != null) {
presentation.dismiss();
presentation = null;
}
presentation = new ClockActivity(this, display);
presentation.show();
Toast.makeText(this, getString(R.string.presentation_mode), Toast.LENGTH_SHORT).show();
} catch (WindowManager.InvalidDisplayException e) {
e.printStackTrace();
}
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage(getString(R.string.external_display_not_available));
alert.setPositiveButton(android.R.string.ok, null);
alert.show();
}
}
示例15: onPresentation
import android.hardware.display.DisplayManager; //导入方法依赖的package包/类
/** Show a picture on remote presentation view */
private void onPresentation(Uri image) {
DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
Display[] presentationDisplays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
if (presentationDisplays.length > 0) {
/**
* If there is more than one suitable presentation display, then we could consider
* giving the user a choice. For this example, we simply choose the first display
* which is the one the system recommends as the preferred presentation display.
*/
Display display = presentationDisplays[0];
try {
/** Clean up previously presentation view */
if (presentation != null) {
presentation.dismiss();
presentation = null;
}
presentation = new PresentationActivity(this, display, image);
presentation.show();
Toast.makeText(this, getString(R.string.presentation_mode), Toast.LENGTH_SHORT).show();
} catch (WindowManager.InvalidDisplayException e) {
e.printStackTrace();
}
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage(getString(R.string.external_display_not_available));
alert.setPositiveButton(android.R.string.ok, null);
alert.show();
}
}