package com.railwaycompactionsystemmobileclient;
import com.facebook.react.ReactActivity;
import com.github.mjdev.libaums.UsbMassStorageDevice;
import com.github.mjdev.libaums.fs.FileSystem;
import com.github.mjdev.libaums.fs.UsbFile;
import com.github.mjdev.libaums.fs.UsbFileInputStream;
import com.github.mjdev.libaums.partition.Partition;
import com.ldm.androidudisk.utils.FileUtil;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
import android.content.Intent; // <--- import
import android.content.res.Configuration; // <--- import
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class MainActivity extends ReactActivity {
//自定义U盘读写权限
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
//当前处接U盘列表
private UsbMassStorageDevice[] storageDevices;
//当前U盘所在文件目录
private UsbFile cFolder;
private final static String U_DISK_FILE_NAME = "u_disk.txt";
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this); // here
super.onCreate(savedInstanceState);
registerUDiskReceiver();
}
@Override
protected String getMainComponentName() {
return "RailwayCompactionSystemMobileClient";
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Intent intent = new Intent("onConfigurationChanged");
intent.putExtra("newConfig", newConfig);
this.sendBroadcast(intent);
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 100:
showToastMsg("保存成功");
break;
case 101:
String txt = msg.obj.toString();
if (!TextUtils.isEmpty(txt))
// u_disk_show.setText("读取到的数据是:" + txt);
break;
}
}
};
//从U盘读取文件
private void readFromUDisk() {
UsbFile[] usbFiles = new UsbFile[0];
try {
usbFiles = cFolder.listFiles();
} catch (IOException e) {
e.printStackTrace();
}
if (null != usbFiles && usbFiles.length > 0) {
for (UsbFile usbFile : usbFiles) {
if (usbFile.getName().equals(U_DISK_FILE_NAME)) {
readTxtFromUDisk(usbFile);
}
}
}
}
/**
* @description 保存数据到U盘,目前是保存到根目录的
* @author ldm
* @time 2017/9/1 17:17
*/
private void saveText2UDisk(String content) {
//项目中也把文件保存在了SD卡,其实可以直接把文本读取到U盘指定文件
File file = FileUtil.getSaveFile(getPackageName()
+ File.separator + FileUtil.DEFAULT_BIN_DIR,
U_DISK_FILE_NAME);
try {
FileWriter fw = new FileWriter(file);
fw.write(content);
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
if (null != cFolder) {
FileUtil.saveSDFile2OTG(file, cFolder);
mHandler.sendEmptyMessage(100);
}
}
/**
* @description OTG广播注册
* @author ldm
* @time 2017/9/1 17:19
*/
private void registerUDiskReceiver() {
//监听otg插入 拔出
IntentFilter usbDeviceStateFilter = new IntentFilter();
usbDeviceStateFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
usbDeviceStateFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
registerReceiver(mOtgReceiver, usbDeviceStateFilter);
//注册监听自定义广播
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(mOtgReceiver, filter);
}
/**
* @description OTG广播,监听U盘的插入及拔出
* @author ldm
* @time 2017/9/1 17:20
* @param
*/
private BroadcastReceiver mOtgReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
switch (action) {
case ACTION_USB_PERMISSION://接受到自定义广播
UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
//允许权限申请
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if (usbDevice != null) {
//用户已授权,可以进行读取操作
readDevice(getUsbMass(usbDevice));
} else {
showToastMsg("没有插入U盘");
}
} else {
showToastMsg("未获取到U盘权限");
}
break;
case UsbManager.ACTION_USB_DEVICE_ATTACHED://接收到U盘设备插入广播
UsbDevice device_add = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (device_add != null) {
//接收到U盘插入广播,尝试读取U盘设备数据
redUDiskDevsList();
}
break;
case UsbManager.ACTION_USB_DEVICE_DETACHED://接收到U盘设设备拔出广播
showToastMsg("U盘已拔出");
break;
}
}
};
/**
* @description U盘设备读取
* @author ldm
* @time 2017/9/1 17:20
*/
private void redUDiskDevsList() {
//设备管理器
UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
//获取U盘存储设备
storageDevices = UsbMassStorageDevice.getMassStorageDevices(this);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
//一般手机只有1个OTG插口
for (UsbMassStorageDevice device : storageDevices) {
//读取设备是否有权限
if (usbManager.hasPermission(device.getUsbDevice())) {
readDevice(device);
} else {
//没有权限,进行申请
usbManager.requestPermission(device.getUsbDevice(), pendingIntent);
}
}
if (storageDevices.length == 0) {
showToastMsg("请插入可用的U盘");
}
}
private UsbMassStorageDevice getUsbMass(UsbDevice usbDevice) {
for (UsbMassStorageDevice device : storageDevices) {
if (usbDevice.equals(device.getUsbDevice())) {
return device;
}
}
return null;
}
private void readDevice(UsbMassStorageDevice device) {
try {
device.init();//初始化
//设备分区
Partition partition = device.getPartitions().get(0);
//文件系统
FileSystem currentFs = partition.getFileSystem();
currentFs.getVolumeLabel();//可以获�
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Android 项目是使用 Android 操作系统和相关开发工具开发的一款移动应用程序。Android 平台提供了丰富的功能和接口,开发人员可以使用 Java 或 Kotlin 等编程语言编写 Android 应用程序。Android 项目也可以是针对特定设备或特定需求进行自定义开发的软件解决方案。 以下是 Android 项目的一些主要特点和资料介绍: 1. 开放源代码:Android 是基于 Linux 内核的开源操作系统,开发人员可以自由获取、使用和修改源代码。 2. 多样化的硬件设备支持:Android 支持多种硬件设备和屏幕尺寸,可以运行于手机、平板电脑、电视、手表等多种设备上。 3. 灵活的用户界面:Android 提供了丰富的用户界面控件和布局方式,可以实现漂亮、个性化的用户界面。 4. 响应式设计:Android 应用程序可以根据设备类型、屏幕尺寸等因素调整布局和显示方式,以适应不同的设备和用户需求。 5. 多媒体支持:Android 支持常见的音频、视频、图像等多媒体格式,可以实现各种多媒体应用。 6. 数据存储:Android 提供了多种数据存储方式,包括 SQLite 数据库、文件存储、SharedPreferences 等。 7. 网络通信:Android 支持多种网络通信方式,包括 HTTP、TCP、UDP 等。 8. 社交媒体集成:Android 提供了集成社交媒体的功能,可以实现与 Facebook、Twitter、Google+ 等社交媒体的交互。 # 注意 1. 本资源仅用于开源学习和技术交流。 2. 部分字体以及插图等来自网络,若是侵权请联系删除。 3. 不可商用,一切后果由使用者承担。
资源推荐
资源详情
资源评论
收起资源包目录
铁路压实系统移动客户端(Android).zip (102个子文件)
.babelrc 34B
gradlew.bat 2KB
BUCK 2KB
BUCK 152B
.buckconfig 114B
.flowconfig 1KB
.gitattributes 16B
.gitignore 763B
build.gradle 6KB
settings.gradle 772B
build.gradle 642B
gradlew 5KB
AppDelegate.h 451B
gradle-wrapper.jar 51KB
MainActivity.java 9KB
FileUtil.java 4KB
MainApplication.java 1KB
OthersDrawerNavigatorView.js 86KB
SystemConfiguration.js 47KB
NetworkSettings.js 29KB
HomeDrawerNavigatorView.js 27KB
SatelliteState.js 27KB
App.js 10KB
Constants.js 3KB
ApiServer.js 3KB
webpack.config.js 2KB
ScreenAdaptationUtil.js 1KB
PublicFunction.js 978B
index.web.js 406B
App.js 267B
index.js 152B
package-lock.json 299KB
package.json 1KB
Contents.json 585B
app.json 107B
replay_pid7440.log 595KB
hs_err_pid7440.log 29KB
RailwayCompactionSystemMobileClientTests.m 2KB
AppDelegate.m 1KB
main.m 510B
project.pbxproj 61KB
Info.plist 2KB
Info.plist 2KB
Info.plist 765B
Info.plist 765B
launch_screen.png 1.48MB
launch_screen.png 1.48MB
CompactionValueNight.png 10KB
CompactionValueDay.png 10KB
2.12 白天模式.png 9KB
DaytimeMode.png 9KB
LocateCurrentNight.png 8KB
LocateCurrentDay.png 8KB
ic_launcher.png 8KB
RefreshNight.png 7KB
RefreshDay.png 7KB
TrajectoryNight.png 7KB
TrajectoryDay.png 7KB
NightMode.png 7KB
2.11 夜晚模式 点击.png 7KB
SatelliteStateTwo.png 5KB
SatelliteStateOne.png 5KB
ic_launcher.png 5KB
CompactedEdgeNumberNight.png 5KB
CompactedEdgeNumberDay.png 5KB
CompactionSensorState.png 4KB
SystemConfiguration.png 4KB
EquipmentDiagnosis.png 4KB
SystemUpgrade.png 4KB
NetworkSettings.png 4KB
SlideOn.png 4KB
TodayData.png 4KB
SlideOff.png 4KB
SatelliteState.png 4KB
BackArrow.png 4KB
AlarmSetting.png 4KB
SelectOn.png 4KB
G4State.png 4KB
SelectOff.png 4KB
ic_launcher.png 3KB
DataDownloading.png 3KB
Arrow.png 3KB
SelectOn.png 3KB
SelectDropDownButton.png 3KB
SelectDropDownButtonLong.png 3KB
InputText.png 3KB
SelectOff.png 3KB
cell.png 3KB
ic_launcher.png 2KB
navigationBg.png 2KB
proguard-rules.pro 3KB
gradle.properties 887B
gradle-wrapper.properties 230B
debug.keystore.properties 105B
.watchmanconfig 2B
RailwayCompactionSystemMobileClient-tvOS.xcscheme 5KB
RailwayCompactionSystemMobileClient.xcscheme 5KB
LaunchScreen.xib 4KB
AndroidManifest.xml 1KB
launch_screen.xml 289B
共 102 条
- 1
- 2
资源评论
阿齐Archie
- 粉丝: 1w+
- 资源: 2301
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功