对于想了解如何检查Android和iOS上的网络是否可用(DelphiXE5)的读者,本文将是一篇不可错过的文章,我们将详细介绍android判断网络是否可用,并且为您提供关于android–发送电子
对于想了解如何检查Android和iOS上的网络是否可用(Delphi XE5)的读者,本文将是一篇不可错过的文章,我们将详细介绍android 判断网络是否可用,并且为您提供关于android – 发送电子邮件Delphi XE5、android – 如何检查Uri指向的资源是否可用?、android 判断网络是否可用与连接的网络是否能上网、Android 检测网络状态,判断当前网络是否可用的有价值信息。
本文目录一览:- 如何检查Android和iOS上的网络是否可用(Delphi XE5)(android 判断网络是否可用)
- android – 发送电子邮件Delphi XE5
- android – 如何检查Uri指向的资源是否可用?
- android 判断网络是否可用与连接的网络是否能上网
- Android 检测网络状态,判断当前网络是否可用
如何检查Android和iOS上的网络是否可用(Delphi XE5)(android 判断网络是否可用)
解决方法
unit Network; interface function IsConnected: Boolean; function IsWiFiConnected: Boolean; function IsMobileConnected: Boolean; implementation uses System.SysUtils,Androidapi.JNIBridge,Androidapi.JNI.GraphicsContentViewText,Androidapi.JNI.JavaTypes,FMX.Helpers.Android,Androidapi.Helpers,Misc; type JConnectivityManager = interface; JNetworkInfo = interface; JNetworkInfoClass = interface(JObjectClass) ['{E92E86E8-0BDE-4D5F-B44E-3148BD63A14C}'] end; [JavaSignature('android/net/NetworkInfo')] JNetworkInfo = interface(JObject) ['{6DF61A40-8D17-4E51-8EF2-32CDC81AC372}'] {Methods} function isAvailable: Boolean; cdecl; function isConnected: Boolean; cdecl; function isConnectedOrConnecting: Boolean; cdecl; end; TJNetworkInfo = class(TJavaGenericImport<JNetworkInfoClass,JNetworkInfo>) end; JConnectivityManagerClass = interface(JObjectClass) ['{E03A261F-59A4-4236-8CDF-0068FC6C5FA1}'] {Property methods} function _GetTYPE_WIFI: Integer; cdecl; function _GetTYPE_WIMAX: Integer; cdecl; function _GetTYPE_MOBILE: Integer; cdecl; {Properties} property TYPE_WIFI: Integer read _GetTYPE_WIFI; property TYPE_WIMAX: Integer read _GetTYPE_WIMAX; property TYPE_MOBILE: Integer read _GetTYPE_MOBILE; end; [JavaSignature('android/net/ConnectivityManager')] JConnectivityManager = interface(JObject) ['{1C4C1873-65AE-4722-8EEF-36BBF423C9C5}'] {Methods} function getActiveNetworkInfo: JNetworkInfo; cdecl; function getNetworkInfo(networkType: Integer): JNetworkInfo; cdecl; end; TJConnectivityManager = class(TJavaGenericImport<JConnectivityManagerClass,JConnectivityManager>) end; function GetConnectivityManager: JConnectivityManager; var ConnectivityServiceNative: JObject; begin ConnectivityServiceNative := SharedActivityContext.getSystemService(TJContext.JavaClass.CONNECTIVITY_SERVICE); if not Assigned(ConnectivityServiceNative) then raise Exception.Create('Could not locate Connectivity Service'); Result := TJConnectivityManager.Wrap( (ConnectivityServiceNative as ILocalObject).GetobjectID); if not Assigned(Result) then raise Exception.Create('Could not access Connectivity Manager'); end; function IsConnected: Boolean; var ConnectivityManager: JConnectivityManager; ActiveNetwork: JNetworkInfo; begin ConnectivityManager := GetConnectivityManager; ActiveNetwork := ConnectivityManager.getActiveNetworkInfo; Result := Assigned(ActiveNetwork) and ActiveNetwork.isConnected; end; function IsWiFiConnected: Boolean; var ConnectivityManager: JConnectivityManager; WiFiNetwork: JNetworkInfo; begin ConnectivityManager := GetConnectivityManager; WiFiNetwork := ConnectivityManager.getNetworkInfo(TJConnectivityManager.JavaClass.TYPE_WIFI); Result := WiFiNetwork.isConnected; end; function IsMobileConnected: Boolean; var ConnectivityManager: JConnectivityManager; MobileNetwork: JNetworkInfo; begin ConnectivityManager := GetConnectivityManager; MobileNetwork := ConnectivityManager.getNetworkInfo(TJConnectivityManager.JavaClass.TYPE_MOBILE); Result := MobileNetwork.isConnected; end; end.
android – 发送电子邮件Delphi XE5
我正在尝试使用Indy组件从Delphi XE5(android)发送电子邮件:
在表单中,我有一个TIdSMTP和一个TIDMessage.
创建表单时:
testform:=Ttestform.create(self);
testform.show;
应用程序暂停,我不知道有什么问题…我认为Indy组件在Android中不兼容…
IdSMTP1.Heloname:='test';
IdSMTP1.Host:='smtp.gmail.com';
IdSMTP1.Username:='umail@gmail.com';
IdSMTP1.Port:=465;
IdSMTP1.Password:='pass';
if IdSMTP1.Connected=True then IdSMTP1.disconnect;
IdMessage1.clear;
IdMessage1.From.Text :='Testing';
IdMessage1.Bcclist.EMailAddresses :='umail@gmail.com';
IdMessage1.Priority := mpHigh;
IdMessage1.Sender.Text:='Umail';
IdMessage1.Subject := 'Subject';
IdMessage1.Body.Add('test');
IdSMTP1.Connect;
Try
IdSMTP1.Send(IdMessage1);
except
End;
有人用这个吗?!
Form Dont SHOW应用程序暂停…
请在这里查看完整的来源http://pastebin.com/iGtJrHHs
解决方法:
这不是Indy问题的直接答案,但如果您考虑在Android上使用内置电子邮件创建选项进行切换,您可以使用以下代码:
uses
FMX.Helpers.Android,
Androidapi.JNIBridge,
Androidapi.JNI.JavaTypes,
Androidapi.JNI.GraphicsContentViewText;
...
procedure CreateEmail(const Recipient, Subject, Content: string);
var
Intent: JIntent;
Recipients: TJavaObjectArray<JString>;
begin
Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_SEND);
Recipients := TJavaObjectArray<JString>.Create(1);
Recipients.Items[0] := StringToJString(Recipient);
Intent.putExtra(TJIntent.JavaClass.EXTRA_EMAIL, Recipients);
Intent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString(Subject));
Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString(Content));
Intent.setType(StringToJString('plain/text'));
SharedActivity.startActivity(TJIntent.JavaClass.createChooser(Intent,
StrToJCharSequence('Which email app?')));
end;
我会把它交给其他人来解决Indy问题.
android – 如何检查Uri指向的资源是否可用?
它的Uri存储在数据库中,所以当文件被删除或卸载的外部存储器时,我只是在调用MediaPlayer.prepare()时收到异常.
在上述情况下,我想播放系统默认的铃声.我当然可以做到这一点,我抓住以上例外,但也许有一些更优雅的解决方案?
编辑:
我忘了提到音乐文件Uri实际上是通过使用铃声优先购买的.这意味着我可以让Uri指向内部存储,外部存储或默认系统铃声的铃声.
Uri的例子是:
>内容://设置/系统/铃声 – 用于选择默认铃声
> content:// media / internal / audio / media / 60 – 用于内部存储上的铃声
> content:// media / external / audio / media / 192 – 用于外接存储器上的铃声
我很高兴提出“新的File(路径).exists()方法,因为它救了我从提到的异常,但一段时间后,我注意到它为所有的铃声选项返回false
任何其他想法?
解决方法
假设String contentUri等于内容URI,如content:// media / external / audio / media / 192
ContentResolver cr = getContentResolver(); String[] projection = {MediaStore.MediaColumns.DATA} Cursor cur = cr.query(Uri.parse(contentUri),projection,null,null); if (cur != null) { if (cur.movetoFirst()) { String filePath = cur.getString(0); if (new File(filePath).exists()) { // do something if it exists } else { // File was not found } } else { // Uri was ok but no entry found. } cur.close(); } else { // content Uri was invalid or some other error occurred }
我没有使用这种方法与声音文件或内部存储,但它应该工作.该查询应该将单个行直接返回到您的文件.
android 判断网络是否可用与连接的网络是否能上网
网络状态获取
上传与下载都需要先查看当前手机的网络状态,需要获取ConnectionManager
/** * 判断当前是否有网络连接,但是如果该连接的网络无法上网,也会返回true * @param mContext * @return */ public static boolean isNetConnection(Context mContext) { if (mContext!=null){ ConnectivityManager connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); boolean connected = networkInfo.isConnected(); if (networkInfo!=null&&connected){ if (networkInfo.getState()== NetworkInfo.State.CONNECTED){ return true; }else{ return false; } } } return false; }
网络能否正常上网
当有网络连接时,如果想要检测当前连接的网络能否上网,需要能否打开网址来做判断
/** * 在子线程里开启该方法,可检测当前网络是否能打开网页 * true是可以上网,false是不能上网 * */ public static boolean isOnline(){ URL url; try { url = new URL("https://www.baidu.com"); InputStream stream = url.openStream(); return true; } catch (MalformedURLException e) { e.printstacktrace(); } catch (IOException e) { e.printstacktrace(); } return false; }
以上这篇android 判断网络是否可用与连接的网络是否能上网就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程小技巧。
您可能感兴趣的文章:
- Android编程判断网络连接是否可用的方法
- Android中判断网络连接是否可用的方法总结
- Android中判断网络连接是否可用及监控网络状态
- Android中判断网络是否可用的代码分享
- Android 判断当前网络是否可用简单实例
Android 检测网络状态,判断当前网络是否可用
public boolean isNetworkAvailable(Activity activity) { Context context = activity.getApplicationContext(); // 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理) ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { return false; } else { // 获取NetworkInfo对象 NetworkInfo[] networkInfo = connectivityManager.getAllNetworkInfo(); if (networkInfo != null && networkInfo.length > 0) { for (int i = 0; i < networkInfo.length; i++) { System.out.println(i + "===状态===" + networkInfo[i].getState()); System.out.println(i + "===类型===" + networkInfo[i].getTypeName()); // 判断当前网络状态是否为连接状态 if (networkInfo[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } } } return false; }
// if (isNetworkAvailable(MainActivity.this)) // { // Toast.makeText(getApplicationContext(), "当前有可用网络!", Toast.LENGTH_LONG).show(); // } // else // { // Toast.makeText(getApplicationContext(), "当前没有可用网络!", Toast.LENGTH_LONG).show(); // }
今天关于如何检查Android和iOS上的网络是否可用(Delphi XE5)和android 判断网络是否可用的分享就到这里,希望大家有所收获,若想了解更多关于android – 发送电子邮件Delphi XE5、android – 如何检查Uri指向的资源是否可用?、android 判断网络是否可用与连接的网络是否能上网、Android 检测网络状态,判断当前网络是否可用等相关知识,可以在本站进行查询。
本文标签: