

极力推荐文章:欢迎收藏
阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android
本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:
一、实现效果
一、实现效果
仿华为USB Mode弹窗实现效果如下:

底部USB mode 弹窗实现
二、主要实现思路
主要实现思路如下:USB发送/取消通知的同时,控制弹窗Dialog的显示/消失。
三、主要实现代码
连接USB发送/取消通知主要实现是在UsbDeviceManager.java类中,类路径如下:frameworks\base\services\usb\java\com\android\server\usb\UsbDeviceManager.java,通过查看此类代码,实现想要的功能。
// add start by wj for usb mode
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.view.WindowManager;
import android.view.Gravity;
// add end by wj for usb mode
/**
* UsbDeviceManager manages USB state in device mode.
*/
public class UsbDeviceManager implements ActivityManagerInternal.ScreenObserver {
private static final String TAG = UsbDeviceManager.class.getSimpleName();
... ...
// add start by wj for usb mode
private static UsbHandler mHandler;
private static AlertDialog mServiceDialog = null;
// add end by wj for usb mode
... ...
protected void updateUsbNotification(boolean force) {
if (mNotificationManager == null || !mUseUsbNotification
|| ("0".equals(getSystemProperty("persist.charging.notify", "")))) {
return;
}
// Dont show the notification when connected to a USB peripheral
// and the link does not support PR_SWAP and DR_SWAP
if (mHideUsbNotification && !mSupportsAllCombinations) {
if (mUsbNotificationId != 0) {
mNotificationManager.cancelAsUser(null, mUsbNotificationId,
UserHandle.ALL);
mUsbNotificationId = 0;
Slog.d(TAG, "Clear notification");
}
return;
}
int id = 0;
int titleRes = 0;
Resources r = mContext.getResources();
CharSequence message = r.getText(
com.android.inter


最低0.47元/天 解锁文章
1794

被折叠的 条评论
为什么被折叠?



