我有一些代码通过调用createBond()自动与蓝牙设备配对,为android.bluetooth.device.action.PAIRING_REQUEST注册广播接收器,然后手动输入要配对的PIN码.
到目前为止,所有经过测试的设备都可以用到Andoid 4.0,但今天我在Android 4.2.1的Nexus 7上尝试了这个并且出现了以下错误:
java.lang.noSuchMethodException:android.bluetooth.IBluetooth.createBond
他们真的从库中删除了这个功能吗?
UPDATE
实际发生的是我用来调用createBond的IBluetooth接口对象没有被初始化.在下面的代码中,当此进程失败导致BTInterface在结尾处设置为null时,尝试获取名为BTBinder的IBinder的行返回null.所以,我现在的问题是为什么在我的带有Android 4.2.1的Nexus 7上调用绑定器返回null但是在我测试的其他5个设备上正常工作?
public static IBluetooth getBluetoothInterface()
{
//Gets a bluetooth interface from private Android system API
IBluetooth BTInterface = null;
try
{
Class<?> ServiceManager = Class.forName("android.os.ServiceManager");
Method getService = ServiceManager.getDeclaredMethod("getService", String.class);
IBinder BTBinder = (IBinder) getService.invoke(null, "bluetooth");
Class<?> IBluetooth = Class.forName("android.bluetooth.IBluetooth");
Class<?>[] IBluetoothClasses = IBluetooth.getDeclaredClasses();
Class<?> IBluetoothClass0 = IBluetoothClasses[0];
Method asInterface = IBluetoothClass0.getDeclaredMethod("asInterface",IBinder.class);
asInterface.setAccessible(true);
BTInterface = (IBluetooth) asInterface.invoke(null, BTBinder);
}
catch (Exception e)
{
return null;
}
return BTInterface;
}
Run Code Online (Sandbox Code Playgroud) 我有一个生成自定义文件类型(.sor)的应用程序.在应用程序内部,我有一项功能,可以发送附有这些文件之一的电子邮件.我还有一个intent过滤器,允许应用程序显示在可以打开此类文件的应用程序列表中.这允许我(有时)使用应用程序直接从手机上的用户电子邮件客户端打开文件.
但是,这仅在电子邮件来自PC电子邮件客户端时才有效,并且在从电话收到电子邮件时无效.例如,如果我生成其中一个.sor文件,然后使用我的应用程序向我自己的电子邮件帐户发送电子邮件,我将在手机上收到电子邮件,但无法使用我的应用程序打开附件...但是,如果我将电子邮件发送到同一个帐户并在我的电脑上打开(使用Thunderbird),而不是通过电话打开,然后转发或将其作为新电子邮件发送到我的手机,我将能够使用相同的电子邮件应用程序在手机上用我的应用程序打开附件...我只是在这里谈论一个电子邮件帐户,唯一的区别是电子邮件是从我的手机或我的Windows 7 PC发送的.
我唯一能想到的是,当我从手机发送电子邮件时,附件中嵌入了一个不同的mime类型,而不是当我从我的PC上的Thunderbird发送它时......我将mime类型指定为"application/octet-stream"当我从我的应用程序发送电子邮件时,我有一个寻找此mime类型的intent过滤器......但它无法正常工作.
我的意图过滤器:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/octet-stream" />
<data android:scheme="file" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
当我从手机发送电子邮件附件中的文件时,我传递给手机电子邮件客户端的意图:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("application/octet-stream");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + fullPathString));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "FiberDroid OTDR Trace File: \"" + ContextMenuFileName + "\"");
sendIntent.putExtra(Intent.EXTRA_TEXT, "This e-mail was sent from the TTI FiberDroid Android application.");
startActivity(Intent.createChooser(sendIntent, "Select E-Mail Application"));
Run Code Online (Sandbox Code Playgroud)
再一次,附带文件的电子邮件的发送工作正常......如果我从PC电子邮件客户端(例如outlook或thunderbird)将同一文件发回电话,那么我可以用我的应用程序打开文件直接从手机电子邮件应用程序.问题是,如果我在电话上打开电子邮件而不通过我的电脑作为中间人我无法打开附件,我唯一的选择是"保存到SD卡"...
所以回顾一下,我手机上有2封相同的电子邮件,附带相同的文件,最初都是从我的应用程序发送到同一个帐户(也是从同一个帐户收到的),但附件是经过的我的PC作为一个不必要的中间人工作正常,直接从我的手机发送和接收的那个没有.
有任何想法吗?先感谢您.
我正在开发一个使用自定义文件类型的应用程序,我已经找到了如何使用系统注册我的应用程序,因为能够使用intent过滤器打开此类型的文件,我的应用程序也将显示在应用程序列表中在尝试打开此类附件时,可用于从内置电子邮件客户端打开此文件.问题是从文件浏览器传入时处理打开文件的代码在从电子邮件客户端传入时不起作用.在选择正确类型的文件后,从文件浏览器调用Activity时,我使用的代码正常工作:
Intent i = getIntent();
if(i == null) return;
Uri u = i.getData();
if(u == null) return;
String filePath = u.getEncodedPath();
if(filePath == null) return;
Util.loadOTDRFile(filePath);
Run Code Online (Sandbox Code Playgroud)
从文件浏览器加载时,我在"filePath"字符串中获得的内容类似于"mnt/storage/Android/data/com.fiberdroid.001/downloads/filename.trc ...并且工作正常我的应用程序加载它loadOTDRFile()函数成功完成.
但是,当我从电子邮件客户端打开相同类型的文件时,该代码中的filePath变量最终会出现如下情况:"// mail/parts/4217"无法加载,我的加载函数返回找不到的文件错误.
以下是loadOTDRFile()函数的相关代码:
File file = new File(filePath);
InputStream is;
try
{
is = new FileInputStream(filePath);
}
catch(FileNotFoundException e)
{
return D.ERROR_FILENOTFOUND;
}
Run Code Online (Sandbox Code Playgroud)
我想我的问题是什么样的路径是"// mail/parts/4217",为什么我不能打开它?
谢谢.
我有一个带有Android 4.2.1的Nexus 7,我在我的应用程序中注意到我用于某些线性布局的背景图像被错误地绘制.对于具有较旧版本Android OS的其他设备,可以正确绘制9补丁背景,但使用此设备时,边框线在不应拉伸时会拉伸.
正确(Evo 4G v2.3.5):http://i.imgur.com/WDTNr.png
不正确(N7 v4.2.1):http: //i.imgur.com/HntMY.png
知道是什么导致了这个吗?如果没有,有没有其他方法可以在不使用9补丁图像的情况下在这些视图上获得黑色边框?
编辑
9补丁文件:http: //i.imgur.com/LDoBE.png
编辑器工具中的9-patch:http: //i.imgur.com/UoydG.png
使用它布局xml部分(leftbordergraybkg):
<LinearLayout
android:id="@+id/Measurements"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="50"
android:background="@drawable/leftbordergraybkg"
android:orientation="vertical">
Run Code Online (Sandbox Code Playgroud)