如何以编程方式扩展三星棒棒糖设备上的状态栏?
How can I programmatically expand status bar on samsung lollipop devices?
我用这段代码来展开状态栏:
Object sbservice = getSystemService( "statusbar" );
Class<?> statusbarManager = Class.forName( "android.app.StatusBarManager" );
Method showsb;
if (Build.VERSION.SDK_INT >= 17) {
showsb = statusbarManager.getMethod("expandNotificationsPanel");
}
else {
showsb = statusbarManager.getMethod("expand");
}
showsb.invoke( sbservice );
经许可:
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
除了三星棒棒糖设备没有任何反应外,它运行良好。
有谁知道如何在三星棒棒糖设备上扩展状态栏?
谢谢!
终于找到了,但我需要使用无障碍服务:
public class MyAccessibilityService extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.e("MyAccessibilityService", "get event");
if (event.getEventType() == AccessibilityEvent.TYPE_TOUCH_INTERACTION_END) {
switch (event.getAction()) {
case 1:
Log.e("MyAccessibilityService ", "home");
performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME);
break;
case 2:
Log.e("MyAccessibilityService ", "back");
performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
break;
case 3:
Log.e("MyAccessibilityService ", "power");
performGlobalAction(AccessibilityService.GLOBAL_ACTION_POWER_DIALOG);
break;
case 4:
Log.e("MyAccessibilityService ", "noti");
performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
break;
}
}
}
连火:
AccessibilityEvent event1 = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END);
event1.setClassName(className);
event1.getText().add("noti");
event1.setAction(4);
event1.setPackageName(packageName);
event1.setEnabled(true);
AccessibilityManager manager = (AccessibilityManager)context.getSystemService(Context.ACCESSIBILITY_SERVICE);
AccessibilityRecordCompat recordCompat = AccessibilityEventCompat.asRecord(event1);
recordCompat.setSource(v);
if (Utility.isAccessibilityEnable(context)) {
manager.sendAccessibilityEvent(event1);
}
我用这段代码来展开状态栏:
Object sbservice = getSystemService( "statusbar" );
Class<?> statusbarManager = Class.forName( "android.app.StatusBarManager" );
Method showsb;
if (Build.VERSION.SDK_INT >= 17) {
showsb = statusbarManager.getMethod("expandNotificationsPanel");
}
else {
showsb = statusbarManager.getMethod("expand");
}
showsb.invoke( sbservice );
经许可:
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
除了三星棒棒糖设备没有任何反应外,它运行良好。 有谁知道如何在三星棒棒糖设备上扩展状态栏? 谢谢!
终于找到了,但我需要使用无障碍服务:
public class MyAccessibilityService extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.e("MyAccessibilityService", "get event");
if (event.getEventType() == AccessibilityEvent.TYPE_TOUCH_INTERACTION_END) {
switch (event.getAction()) {
case 1:
Log.e("MyAccessibilityService ", "home");
performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME);
break;
case 2:
Log.e("MyAccessibilityService ", "back");
performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
break;
case 3:
Log.e("MyAccessibilityService ", "power");
performGlobalAction(AccessibilityService.GLOBAL_ACTION_POWER_DIALOG);
break;
case 4:
Log.e("MyAccessibilityService ", "noti");
performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
break;
}
}
}
连火:
AccessibilityEvent event1 = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END);
event1.setClassName(className);
event1.getText().add("noti");
event1.setAction(4);
event1.setPackageName(packageName);
event1.setEnabled(true);
AccessibilityManager manager = (AccessibilityManager)context.getSystemService(Context.ACCESSIBILITY_SERVICE);
AccessibilityRecordCompat recordCompat = AccessibilityEventCompat.asRecord(event1);
recordCompat.setSource(v);
if (Utility.isAccessibilityEnable(context)) {
manager.sendAccessibilityEvent(event1);
}