本文整理匯總了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();
}
}