Mobile Hotspot Name and Password - mobile

I have to get the name and password of my mobile hotspot programmatically in android studio. How do I do it?
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Toast.makeText(this,"SSID:"+wifiInfo.getSSID(),Toast.LENGTH_LONG).show();
This code gives me SSID of wifi I am connected to. I need name of my Mobile hotspot.

You can get the wificonfiguration of your hotspot in API<26 using reflection. Its not the recommended way but if you need it bad, then here it is.
private WifiConfiguration currentConfig;
private WifiConfiguration getWifiApConfiguration() {
try {
Method method = wifiManager.getClass().getMethod("getWifiApConfiguration");
return (WifiConfiguration) method.invoke(wifiManager);
} catch (Exception e) {
Log.e(this.getClass().toString(), "", e);
return null;
}
}
And then you can use the WifiConfiguration object to get its details:
currentConfig.SSID
currentConfig.preSharedKey

Related

Unable to get IAM security credentials from EC2 Instance Metadata Service error when using Aws Sdk in UWP

I'm working with Aws Sdk and I'm trying to implement a login UI using UWP. I followed this online tutorial (which is for WPF) and I tried to make it works for the Universal Windows Platform as well.
The core part of the source code is the following (please note that is 90% similar to the one posted in the tutorial. The "only difference" is that I used
InitiateAuthAsync
instead of
AdminInitiateAuthAsync
<!-- language: lang-cs -->
private readonly AmazonCognitoIdentityProviderClient _client;
private readonly string _clientId = "32fsoifj93fjsiispat";
public MainPage()
{
this.InitializeComponent();
var amazonCognitoIdentityProviderConfig = new AmazonCognitoIdentityProviderConfig();
amazonCognitoIdentityProviderConfig.ServiceURL = "https://cognito-idp.eu-central-1.amazonaws.com/";
_client = new AmazonCognitoIdentityProviderClient(amazonCognitoIdentityProviderConfig);
}
private async Task<bool> CheckPasswordAsync(string userName, string password)
{
try
{
List<HttpHeader> httpHeaders = new List<HttpHeader>();
HttpHeader httpHeader = new HttpHeader
{
HeaderName = "X-Amz-Target",
HeaderValue = "AWSCognitoIdentityProviderService.InitiateAuth"
};
httpHeaders.Add(httpHeader);
httpHeader = new HttpHeader
{
HeaderName = "Content-Type",
HeaderValue = "application/x-amz-json-1.1"
};
httpHeaders.Add(httpHeader);
var authReq = new InitiateAuthRequest()
{
ClientId = _clientId,
AuthFlow = AuthFlowType.USER_PASSWORD_AUTH,
};
authReq.AuthParameters.Add("USERNAME", userName);
authReq.AuthParameters.Add("PASSWORD", password);
var authResp = await _client.InitiateAuthAsync(authReq);
return true;
}
catch (Exception ex)
{
return false;
}
}
Please consider that it is working properly with WPF framework. I'm able to get the TokenId and RefreshToken.
But if I try to copy and paste the same code in UWP I get the exception:
'Unable to get IAM security credentials from EC2 Instance Metadata Service.'
And if I try to investigate with Fiddler I get the following error:
[Fiddler] The connection to '169.254.169.254' failed. Error: NetworkUnreachable (0x2743). System.Net.Sockets.SocketException A socket operation was attempted to an unreachable network 169.254.169.254:80
I really can't understand why it tries to connect to the '169.254.169.254' address. Googling around I found other people experiencing the same issue (for example here). Do you have any idea?

how to get Network Status,Operator Name, Signal strength,Service status using j2me?

i need to get the info of
Network Status,Operator Name, Signal strength,Service status
using the j2me API
and need to knew if i can test it over simulator or not
thanks a lot for helping
You can do this on Series 40 devices by querying some Nokia-specific System Properties. This page lists all of them. The ones you are interested are com.nokia.mid.networksignal, com.nokia.mid.networkavailability and com.nokia.mid.networkstatus. For the operator name, com.nokia.mid.networkid contains the short operator name.
To query a property, use
try {
String val = System.getProperty("property name");
// do stuff
} catch (NullPointerException e) {
// property not found
} catch (IllegalArgumentException e) {
// property not found
}

Using Silverlight 4 WebClient OpenReadCompleted throughs Security Exceptions on hosted web server. What's the pronblem?

Seems to be a simple thing using a WebClient object to retrieve content of a text file in a Silverlight web application.
It works in our intranet setup on a local server, but when deployed on a hosted "hostgator" server, WebClient gets a security exception. Following suggestions from numerous web blogs, I tried crossdomain access policy and crossdomain.xml with no result - no wonder, all in on the same domain.
private void LoadCSVFile(string csvFile)
{
try
{
WebClient client = new WebClient();
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
client.OpenReadAsync(new Uri(csvFile, UriKind.Absolute));
}
catch (Exception ex)
{
string errorMessage = String.Format("Ex accessing csv: {0}\n{1}", csvFile,
}
}
//the csvFile is an absolute path: http://myserver.com/myapplication:port/sourcefiles/file.csv
//The sourcefiles is a virtual directory in the same website containing csv files
void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
try
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Result))
{
mainFileData = new List<string>();
string line;
}
}
catch (Exception ex)
{
string errorMessage = ex.InnerException;
}else
{
"here is the place for the exception!!!!!!! so, e.Error is not null"
}
}
The text of the exception reads: System.SecurityException: Security error at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) etc.
Spend 2 days gooogling with no result.
Please help.
V
A couple of things to check:
(1) The format for the URL that you list (http://myserver.com/myapplication:port/sourcefiles/file.csv) looks odd. Shouldn't it be http://myserver.com:port/myapplication/sourcefiles/file.csv? Or is that just a typo?
(2) What's the port number that you're accessing? The Silverlight WebClient will only access ports 80 and 443.
(3) Can you get to the file using a direct URL? Sometimes web servers need to be told about a specific file type before they'll allow it to be served up.

silverlight adaptive steaming, server side encoding?

has anyone used microsoft expression encoder SDK to do server side encoding of videos to preapare it for silverlight adaptive streaming?
What is your experience with it?
I made a windows service for encoding movie files to create Adaptive Streaming files on the fly once uploaded. The downside for me was that I wanted to store the adapative stream files inside a database. The only option to achieve this was to create your own WIN32 File API or some sort of WebDav system which can return the filestreams. You can't create your own extention of SmoothStreamHandler to get your filestream other ways (like from database or whatever).
Beware that it eats up all CPU's you have in your system, so dont run this on your webserver but have a seperate server for it. Also the server doesn't have to have much memory as it doesn't have a 64-bit version so it cant use more as 3,2gb. Just CPU power and some fast disks would be best.
There are also hardware solutions which support Silverlight Adaptive Streaming, like Elemental Server.
The SDK itself is rather easy to use:
Sample:
private void ProcessFile(string filename, string outputFolder)
{
try
{
MediaItem mediaItem;
AdvancedVC1VideoProfile videoProfile = new AdvancedVC1VideoProfile();
videoProfile.SmoothStreaming = true;
videoProfile.AdaptiveGop = false;
videoProfile.Streams.RemoveAt(0);
try
{
mediaItem = new MediaItem(filename);
// Add streams
videoProfile.Streams.Add(new ConstantBitrate(1450), new Size(848, 480));
videoProfile.Streams.Add(new ConstantBitrate(1050), new Size(592, 336));
videoProfile.Streams.Add(new ConstantBitrate(600), new Size(424, 240));
mediaItem.OutputFormat.VideoProfile = videoProfile;
}
catch (InvalidMediaFileException ex)
{
Console.WriteLine(ex.Message);
return;
}
using (Job job = new Job())
{
job.MediaItems.Add(mediaItem);
job.OutputDirectory = outputFolder;
job.CreateSubfolder = false;
job.EncodeProgress += (object sender, EncodeProgressEventArgs e) =>
{
// Trace progress..
};
job.Encode();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return;
}
}

Silverlight communication with XML RPC console server

I want to comunicate with Console XML RPC server from my silvelight application. Is it possibile?
Steps:
1. Start the Console XML RPC server
Code for Console XML RPC server is this:
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using CookComputing.XmlRpc;
public class StateNameServer : MarshalByRefObject, IStateName
{
public string GetStateName(int stateNumber)
{
return "whatever";
}
}
class _
{
static void Main(string[] args)
{
IDictionary props = new Hashtable();
props["name"] = "MyHttpChannel";
props["port"] = 5678;
HttpChannel channel = new HttpChannel(props,null,new XmlRpcServerFormatterSinkProvider());
ChannelServices.RegisterChannel(channel,false);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(StateNameServer),"statename.rem",WellKnownObjectMode.Singleton);
Console.WriteLine("Press <ENTER> to shutdown");
Console.ReadLine();
}
}
Run Silverlight application
I used the code from http://code.google.com/p/xmlrpc-silverlight/
I created new Silverlight application to which I have attached the code from that link. When I start web site (in localhost with port 1139) which executes my SL app happens SecurityException.
void ResponseResponse(IAsyncResult result)
{
XmlRpcHelperRequestState state = result.AsyncState as XmlRpcHelperRequestState;
try
{
state.Response = (HttpWebResponse)state.Request.EndGetResponse(result);
...
}
catch (Exception e)
{
// comes here with SecurityException
}
finally
{
...
}
}
I am using VS2008 Professional,XP Professional, .net 3.5, Silverlight3. I will gladly provide any additional information (or code) which is needed.
I suspect that this is a case of a missing clientaccesspolicy.xml file.
Since your silverlight app will have been launched from another authority it will attempt to access this file the http://localhost:5678/. Since you little test doesn't support that file Silverlight blocks this cross "domain" activity.

Resources