[Q] Stuck very badly - Windows Phone 7 Q&A, Help & Troubleshooting

Code:
private static string Post(string url, string data)
{
System.Net.WebRequest request1 = WebRequest.Create(url);
request1.Method = "POST";
request1.ContentType = "application/json";
byte[] byteData = Encoding.UTF8.GetBytes(data);
request1.ContentLength = byteData.Length;
using (Stream s = request1.GetRequestStream())
{
s.Write(byteData, 0, byteData.Length);
s.Close();
}
string replyData;
using (HttpWebResponse response = (HttpWebResponse)request1.GetResponse())
{
using (Stream dataStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(dataStream))
{
replyData = reader.ReadToEnd();
}
}
}
I am receiving an error on [request1.ContentLength] and using (Stream s = request1.GetRequestStream())
pls i really need assistance on this

Related

Android - FritzBox VPN

Hello,
i would like to connect my desire with vpn to my fritzxbox.
can someone help me?
what do i have to choose?
L2TP-VPN
L2TP/IPSec PSK-VPN
L2TP/IPSec CRT-VPN
i have this two files vpnuser.cfg and vpnuser.vpn
there should be all necessitate data but don't know what to take.
cpnuser.vpn
Code:
n:version:3
n:network-ike-port:500
n:network-mtu-size:1380
n:client-addr-auto:1
n:network-natt-port:4500
n:network-natt-rate:15
n:network-frag-size:540
n:network-dpd-enable:1
n:client-banner-enable:1
n:network-notify-enable:1
n:client-dns-used:0
n:client-dns-auto:1
n:client-dns-suffix-auto:1
n:client-splitdns-used:1
n:client-splitdns-auto:0
n:client-wins-used:0
n:client-wins-auto:1
n:phase1-dhgroup:2
n:phase1-keylen:256
n:phase1-life-secs:86400
n:phase1-life-kbytes:0
n:vendor-chkpt-enable:0
n:phase2-keylen:256
n:phase2-life-secs:3600
n:phase2-life-kbytes:0
n:policy-nailed:0
n:policy-list-auto:0
s:network-host:dyndns
s:client-auto-mode:pull
s:client-iface:virtual
s:network-natt-mode:enable
s:network-frag-mode:enable
s:auth-method:mutual-psk
s:ident-client-type:ufqdn
s:ident-server-type:address
s:ident-client-data:myusername
b:auth-mutual-psk:long_code
s:phase1-exchange:aggressive
s:phase1-cipher:aes
s:phase1-hash:sha1
s:phase2-transform:esp-aes
s:phase2-hmac:sha1
s:ipcomp-transform:deflate
n:phase2-pfsgroup:2
s:policy-list-include:192.168.178.0 / 255.255.255.0
vpnuser.cfg
Code:
/*
* C:\Users\myname\AppData\Roaming\AVM\FRITZ!Fernzugang\dyndns\user\vpnuser.cfg
* Tue Feb 16 11:18:33 2010
*/
version {
revision = "$Revision: 1.30 $";
creatversion = "1.1";
}
pwcheck {
}
datapipecfg {
security = dpsec_quiet;
icmp {
ignore_echo_requests = no;
destunreach_rate {
burstfactor = 6;
timeout = 1;
}
timeexceeded_rate {
burstfactor = 6;
timeout = 1;
}
echoreply_rate {
burstfactor = 6;
timeout = 1;
}
}
masqtimeouts {
tcp = 15m;
tcp_fin = 2m;
tcp_rst = 3s;
udp = 5m;
icmp = 30s;
got_icmp_error = 15s;
any = 5m;
tcp_connect = 6m;
tcp_listen = 2m;
}
ipfwlow {
input {
}
output {
}
}
ipfwhigh {
input {
}
output {
}
}
NAT_T_keepalive_interval = 20;
}
targets {
policies {
name = "mydyn.dns";
connect_on_channelup = no;
always_renew = no;
reject_not_encrypted = no;
dont_filter_netbios = yes;
localip = 0.0.0.0;
virtualip = 192.168.178.201;
remoteip = 0.0.0.0;
remotehostname = "mydyn.dns";
localid {
user_fqdn = "username";
}
mode = mode_aggressive;
phase1ss = "all/all/all";
keytype = keytype_pre_shared;
key = "long code";
cert_do_server_auth = no;
use_nat_t = yes;
use_xauth = no;
use_cfgmode = no;
phase2localid {
ipaddr = 192.168.178.201;
}
phase2remoteid {
ipnet {
ipaddr = 192.168.178.0;
mask = 255.255.255.0;
}
}
phase2ss = "esp-all-all/ah-none/comp-all/pfs";
accesslist = "permit ip any 192.168.178.0 255.255.255.0";
wakeupremote = no;
}
}
policybindings {
}
// EOF
can someone help me? thanks in advance
..any updates on this ?
I'm facing the same problem
,Wolfgang
never seen anything like that
this may help you
show post#775248 there is a solution for vpnc and fritzbox
mp1405 said:
show post#775248 there is a solution for vpnc and fritzbox
Click to expand...
Click to collapse
Where is this post#775248?
Hello there,
1. It is necessary that your device is rooted.
2. In order to connect via Fritz!VPN you need to use VPNC Widget. If "check prerequisites" states that it should work you are good to go.
3. The config file for FritzBox needs to look like this in order to work with Android devices. You need to change the UPPERCASE values *and IF changed from the 192.168.178.X default also change IP settings* afterwards enter these values in VPNC Widget and it should work.
/*
/*
*C:\Users\tom\AppData\Roaming\AVM\FRITZ!Fernzugang\fritzbox_avmvpn_dyndns_org.cfg
* Mon Mar 07 17:49:59 2011
*/
vpncfg {
connections {
enabled = yes;
conn_type = conntype_user;
name = "NAMEINFRITZGUI";
always_renew = no;
reject_not_encrypted = no;
dont_filter_netbios = yes;
localip = 0.0.0.0;
local_virtualip = 0.0.0.0;
remoteip = 0.0.0.0;
remote_virtualip = 192.168.100.201;
remoteid {
key_id = "USER";
}
mode = phase1_mode_aggressive;
phase1ss = "all/all/all";
keytype = connkeytype_pre_shared;
key = "PASSWORD";
cert_do_server_auth = no;
use_nat_t = yes;
use_xauth = yes;
use_cfgmode = no;
xauth {
valid = yes;
username = "USER1";
passwd = "PASSWORT1";
}
phase2localid {
ipnet {
ipaddr = 0.0.0.0;
mask = 0.0.0.0;
}
}
phase2remoteid {
ipaddr = 192.168.100.201;
}
phase2ss = "esp-all-all/ah-none/comp-all/no-pfs";
accesslist = "permit ip 0.0.0.0 0.0.0.0 192.168.100.201 255.255.255.255";
}
ike_forward_rules = "udp 0.0.0.0:500 0.0.0.0:500",
"udp 0.0.0.0:4500 0.0.0.0:4500";
}
// EOF
Click to expand...
Click to collapse
Greetings
Geniac
@geniac
Thank you
Hello all ...
I'd like to connect my HTC1s via VPN to my Fritzbox 3170.
The connection works, I have access to my homenetwork and a small bandwidth to check my emails, but when I start the browser or speedtest there's no connection.
I use cm9 alpha14 and I tried VPNC Widget and vpncilla as well as onboard vpn.
Do I have to make further modifications to my Fritzbox?
for the cfg - file I used the code posted by geniac
thanks 4 ur help
greetz
Tomcatz

[Q] GPS Console Application in Windows Mobile

Hi.
i tried to create an console application in windows mobile 6.x
here is the code
Code:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Microsoft.WindowsMobile;
using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;
using Microsoft.WindowsMobile.Samples.Location;
using System.IO;
namespace consolegps
{
class Program
{
static void Main(string[] args)
{
Gps lacak = new Gps();
lacak.LocationChanged += new LocationChangedEventHandler(lokasi_gps);
lacak.Open();
}
public static void lokasi_gps(Object sender, LocationChangedEventArgs loc)
{
StreamReader read = new StreamReader("latitude.txt");
string baris = null;
if ((baris = read.ReadLine()) != null)
{
string bujur;
string lintang;
GpsPosition lokasi = loc.Position;
if (lokasi.LatitudeValid)
bujur = lokasi.Latitude.ToString();
if (lokasi.LongitudeValid)
lintang = lokasi.Latitude.ToString();
{
TextWriter lat = new StreamWriter("latitude.txt");
lat.WriteLine(lokasi.Latitude.ToString());
lat.Close();
TextWriter longi = new StreamWriter("longitude.txt");
longi.WriteLine(lokasi.Longitude.ToString());
longi.Close();
}
}
}
}
}
after i run the application, it's seems that
Code:
if ((baris = read.ReadLine()) != null)
is never ending coz gps cant get coordinate.
did i miss something ??

[Q] How to send file Attachment with JavaMail on android device

Hi, I want to create the Camera Application that send file jpg as attachment when I click the screen .
Here my code :
public void onPictureTaken(byte[] data, Camera kamera) {
Uri imageFileUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,new ContentValues());
try
{
String sdcardStorage = Environment.getExternalStorageDirectory().toString();
File f = new File(sdcardStorage + "/HeryMD/"+System.currentTimeMillis()+".jpg");
try{
String fName = f.getAbsolutePath();
GMailSender sender = new GMailSender(" username", "password");
sender.addAttachment("fName");
sender.sendMail("Test",
"body mail",
" sender ",
"recipients");
}
catch (Exception e) {
Log.e("SendMail", e.getMessage(), e);
}
OutputStream os = new FileOutputStream(f);
os.write(data);
os.flush();
os.close();
} catch(FileNotFoundException e)
{
Toast t = Toast.makeText(this,e.getMessage(), Toast.LENGTH_SHORT);
t.show();
}
catch(IOException e)
{
Toast t = Toast.makeText(this,e.getMessage(), Toast.LENGTH_SHORT);
t.show();
}
kamera.startPreview();
}
When I run the application, It can't send the attachment as file jpg.
Please can you help me?
Thanks for your attention

[Completed] Trouble with string encode after decompile APK file

Hello,
I have a trouble with a string text encode after decompile an APK file.
I used APK Tool decompile. The origin file http_//file.9app.info/files/tuan/tuan2india/9-apps.apk
The code was encoded here:
Code:
public class API
extends Activity
{
public static String a = "081b11458016006d513b0290cc7be0b39c28626ea506b9ed291b125114f2a38369a42e77a066a7789e5883ed47113fc3";
public static String b = "081b11458016006d513b0290cc7be0b36f01584bcfccde8bd9e2bd628ca804e7056b175ad6a1fa1bf3cf31d8a28b94e9";
public static String c = "081b11458016006d513b0290cc7be0b36f01584bcfccde8bd9e2bd628ca804e7056b175ad6a1fa1bf3cf31d8a28b94e9";
public static JSONObject d = new JSONObject();
public static String e = "";
private static int h = 0;
private boolean f = false;
private ProgressDialog g;
private JSONObject a(JSONObject paramJSONObject)
{
int i = 0;
Iterator localIterator = paramJSONObject.keys();
int[] arrayOfInt = new int[paramJSONObject.length()];
int j = 0;
JSONObject localJSONObject1;
int m;
if (!localIterator.hasNext())
{
Arrays.sort(arrayOfInt);
localJSONObject1 = new JSONObject();
m = arrayOfInt.length;
}
for (;;)
{
if (i >= m)
{
return localJSONObject1;
int k = j + 1;
arrayOfInt[j] = Integer.parseInt(((String)localIterator.next()).toString());
j = k;
break;
}
String str1 = Integer.toString(arrayOfInt[i]);
try
{
JSONObject localJSONObject2 = (JSONObject)paramJSONObject.get(str1);
if (((paramJSONObject.get(str1) instanceof JSONObject)) && (!a(localJSONObject2.get("package").toString())))
{
String str2 = localJSONObject2.get("package").toString();
if (!getApplicationContext().getSharedPreferences("listpacks", 0).getBoolean(str2, false)) {
if (localJSONObject2.get("type").toString().equals("1"))
{
if (!this.f)
{
this.f = true;
d = localJSONObject2;
}
}
else
{
e = e + localJSONObject2.get("package").toString() + "|";
localJSONObject1.put(str1, localJSONObject2);
}
}
}
}
catch (JSONException localJSONException)
{
localJSONException.printStackTrace();
}
i++;
}
}
Anybody can help me decode 3 text string a,b,c please?
Hello,
Try posting your question in the forum linked below.
http://forum.xda-developers.com/android/help
The experts there may be able to help. Good luck.
Hello,
I'm newbie so I don't know where to post right. Thank you for your advice!

Cell Info 5G NR Neighbour Cells Information

Hi all,
I'm developing an application that captures the information of the LTE and 5G NR network information. I have created two different services (Kotlin services that are very similar to pool threads) which captures the information of the LTE and its neighbours in one service and the same for 5G NR in another service. The transformation to obtain the same information is very similar from LTE to 5G, and it is supposed to work. In the LTE service I obtain the information of the LTE serving cell information below (First quote) and the 5G NR service in the other quote. I would like to point out from the 5G service provides me the information of ONLY the serving cell, however, I need the information of all the cells. Does anyone have any clue?
Thanks for anyone who stops for reading this =)
package com.mobilenet.monitoring.services
import android.Manifest
import android.annotation.SuppressLint
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.ConnectivityManager
import android.os.Binder
import android.os.Handler
import android.os.IBinder
import android.telephony.*
import android.util.Log
import androidx.core.app.ActivityCompat
import com.mobilenet.monitoring.R
import com.mobilenet.monitoring.app.preferences
import org.json.JSONObject
import java.text.DateFormat
import java.util.*
import kotlin.collections.HashMap
class ServiceLte : Service() {
val TAG = "TESTING"
private var mBinder: IBinder = MyBinder()
private var mHandler = Handler()
/* Lte Parameters */
var mSignalStrength: SignalStrength? = null
var mListSignalStrength: List<CellSignalStrength>? = null
var mSignalStrengthLte: CellSignalStrengthLte? = null
var mManager: TelephonyManager? = null
/* LteConnection */
private var mLteData: JSONObject = JSONObject()
private var mLteNeighbourData: JSONObject = JSONObject()
var infos: MutableList<CellInfo>? = null
private lateinit var mContext:Context
private var jsonObject:JSONObject = JSONObject()
private var dataNeighbour = HashMap< String, String>()
private var lte:CellSignalStrengthLte? = null
private var identityLte:CellIdentityLte? = null
private var ci:Int = -1
private var MCC:String? = ""
private var MNC:String? = ""
private var PLMN:String? = ""
private var cellidHex: String = ""
private var eNBHex:String = ""
private var eNB: Int = -1
override fun onBind(intent: Intent): IBinder? {
return mBinder
}
@SuppressLint("MissingPermission")
override fun onCreate() {
super.onCreate()
Log.d(TAG, "onCreate")
mContext = this
/* LTE */
mManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
//mManager!!.listen( mListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS or PhoneStateListener.LISTEN_CELL_INFO)
update()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.d(TAG, "onStartCommand")
if(intent?.getStringExtra("action") == "Destroy"){
onDestroy()
}
val CHANNELID = "Foreground Service ID"
val channel = NotificationChannel(
CHANNELID,
CHANNELID,
NotificationManager.IMPORTANCE_LOW
)
getSystemService(NotificationManager::class.java).createNotificationChannel(channel)
val notification: Notification.Builder = Notification.Builder(this, CHANNELID)
.setContentText("Monitoring is running")
.setContentTitle("Monitoring enabled")
.setSmallIcon(R.drawable.ic_launcher_background)
startForeground(1001, notification.build())
return super.onStartCommand(intent, flags, startId)
}
fun getLteData(): JSONObject {
return mLteData
}
fun getNeighbourLteData(): JSONObject {
return mLteNeighbourData
}
// Listener for signal strength.
private val mListener: PhoneStateListener = object : PhoneStateListener() {
override fun onSignalStrengthsChanged(sStrength: SignalStrength) {
mSignalStrength = sStrength
Log.d(TAG,"SignalStrength cambia HOLAA")
if (ActivityCompat.checkSelfPermission(mContext,Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
infos = mManager!!.allCellInfo
}
}
override fun onCellInfoChanged(cellInfo: MutableList<CellInfo>) {
Log.d(TAG,"CellInfo cambia")
infos = cellInfo
}
}
private fun update() {
val runnable = object : Runnable {
@SuppressLint("MissingPermission", "NewApi")
override fun run() {
mLteData = JSONObject()
mLteNeighbourData = JSONObject()
infos = null
jsonObject = JSONObject()
mManager!!.requestCellInfoUpdate( mContext.mainExecutor,
object : TelephonyManager.CellInfoCallback() {
override fun onCellInfo(cellInfo: MutableList<CellInfo>) {
Log.d(TAG, "Requesting cell update")
getData(cellInfo)
}
})
mHandler.postDelayed(this, 500)//preferences.periodicity.toLong())
}
}
mHandler.postDelayed(runnable, 500)//preferences.periodicity.toLong())
}
@SuppressLint("NewApi")
private fun getData(cellInfo: MutableList<CellInfo>){
try {
mSignalStrengthLte = (cellInfo[0] as CellInfoLte).cellSignalStrength
//LTE connected
if (preferences.LteEnable) {
if (preferences.LteCQI) mLteData.put("LteCqi", "${mSignalStrengthLte!!.cqi}")
if (preferences.LteLevel) mLteData.put("LteLevel","${mSignalStrengthLte!!.level}")
if (preferences.LteRSRP) mLteData.put("LteRSRP", "${mSignalStrengthLte!!.rsrp}")
if (preferences.LteRSRQ) mLteData.put("LteRSRQ", "${mSignalStrengthLte!!.rsrq}")
if (preferences.LteRSSI) mLteData.put("LteRSSI", "${mSignalStrengthLte!!.rssi}")
if (preferences.LteRSSNR) mLteData.put("LteRSSNR","${mSignalStrengthLte!!.rssnr}")
if (preferences.LteTA) mLteData.put("LteTimingAdvance", "${mSignalStrengthLte!!.timingAdvance}")
if (preferences.LteDbm) mLteData.put("LteDbm", "${mSignalStrengthLte!!.dbm}")
if (preferences.LteAsuLevel) mLteData.put("LteAsuLevel", "${mSignalStrengthLte!!.asuLevel}")
}
}catch (ex: Exception) {
Log.i(TAG, ex.message)
}
//LTE neighbours
@SuppressLint("MissingPermission")
infos = mManager!!.allCellInfo
jsonObject = JSONObject()
dataNeighbour = HashMap< String, String>()
if (preferences.NeighbourLteEnable){
jsonObject.put("NumberOfSites", "${infos!!.size}")
}
for (i in infos!!.indices) {
try {
val info = infos!!
if (info is CellInfoLte) //if LTE connection
{
//mManager!!.getNetworkOperator()
lte = info.cellSignalStrength
identityLte = info.cellIdentity
ci = identityLte!!.ci
MCC = identityLte!!.mccString
MNC = identityLte!!.mncString
if(MNC == null || MCC == null) PLMN = "XXXX"
else if (MNC!!.length == 3) {
PLMN = "${MCC!![1]}${MCC!![0]}${MNC!![2]}${MCC!![2]}${MNC!![1]}${MNC!![0]}"
} else {
PLMN = "${MCC!![1]}${MCC!![0]}F${MCC!![2]}${MNC!![1]}${MNC!![0]}"
}
cellidHex = String.format("%x", ci)
eNBHex = cellidHex.substring(0, cellidHex.length - 2)
eNB = Integer.parseInt(eNBHex, 16)
//ECI = 256 * eNBId + Cellid
dataNeighbour["Registered"] = "${info!!.isRegistered()}"
if (preferences.NeighbourLteRsrp) dataNeighbour["RSRP"] = "${lte!!.rsrp}"
if (preferences.NeighbourLteRssi) dataNeighbour["RSSI"] = "${lte!!.rssi}" //Unavailable
if (preferences.NeighbourLteCqi) dataNeighbour["CQI"] = "${lte!!.cqi}" //Unavailable
if (preferences.NeighbourLteDbm) dataNeighbour["Dbm"] = "${lte!!.dbm}"
if (preferences.NeighbourLteLevel) dataNeighbour["LevelSignalStrength"] = "${lte!!.level}"
if (preferences.NeighbourLteRsrq) dataNeighbour["RSRQ"] = "${lte!!.rsrq}"
if (preferences.NeighbourLteRssnr) dataNeighbour["RSSNR"] = "${lte!!.rssnr}"
if (preferences.NeighbourLtePci) dataNeighbour["PCI"] = "${identityLte!!.pci}"
if (preferences.NeighbourLteCi) dataNeighbour["CI"] = "${ci}"
if (preferences.NeighbourLteMnc) dataNeighbour["MNC"] = "${MNC}"
if (preferences.NeighbourLteMcc) dataNeighbour["MCC"] = "${MCC}"
if (preferences.NeighbourLtePlmn) dataNeighbour["PLMN"] = "${PLMN}"
if (preferences.NeighbourLteEnb) dataNeighbour["eNB"] = "${eNB}"
if (preferences.NeighbourLteMobileNetworkOperator) dataNeighbour["MobileNetworkOperatorID"] = "${identityLte!!.mobileNetworkOperator}"
if (preferences.NeighbourLteMobileNetworkOperator) dataNeighbour["MobileNetworkOperatorName"] = "${identityLte!!.operatorAlphaLong}"
if (preferences.NeighbourLteTac) dataNeighbour["TAC"] = "${identityLte!!.tac}"
if (preferences.NeighbourLteBandwith) dataNeighbour["Bandwidth"] = "${identityLte!!.bandwidth}"
if (preferences.NeighbourLteEarfcn){
dataNeighbour["EarFCN"] = "${identityLte!!.earfcn}"
dataNeighbour["Band"] = "${getBand(identityLte!!.earfcn)}"
}
}else{
if (info is CellInfoGsm){
var gsm = info.cellSignalStrength
var identityGsm = info.cellIdentity
Log.d(TAG,gsm.toString())
Log.d(TAG,"identityGsm.cid: ${identityGsm.cid}")
Log.d(TAG,identityGsm.toString())
}else if (info is CellInfoCdma){
var gsm = info.cellSignalStrength
var identityGsm = info.cellIdentity
Log.d(TAG,gsm.toString())
Log.d(TAG,"identityCdma.networkId: ${identityGsm.networkId}, identityCdma.systemId: ${identityGsm.systemId}")
Log.d(TAG,identityGsm.toString())
}else if (info is CellInfoWcdma){
var gsm = info.cellSignalStrength
var identityGsm = info.cellIdentity
Log.d(TAG,gsm.toString())
Log.d(TAG,"identityWcdma.cid: ${identityGsm.cid}")
Log.d(TAG,identityGsm.toString())
}else if (info is CellInfoTdscdma){
var gsm = info.cellSignalStrength
var identityGsm = info.cellIdentity
Log.d(TAG,gsm.toString())
Log.d(TAG,"identityTdscdma.cid: ${identityGsm.cid}")
Log.d(TAG,identityGsm.toString())
}
}
} catch (ex: Exception) {
Log.i("TESTING: ", ex.message)
}
jsonObject.putOpt("Site$i", JSONObject(dataNeighbour as Map<*, *>))
}
mLteNeighbourData = jsonObject
}
override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)
stopSelf() //a hard stop for the service (si no queremos que siga en funcionamiento al cerrar)
}
override fun onDestroy() {
Log.d(TAG, "onDestroy")
super.onDestroy()
}
inner class MyBinder : Binder() {
fun getService(): ServiceLte? {
return [email protected]
}
}
private fun getBand(arfcn:Int):Int{
when {
arfcn<600 -> return 1
arfcn<1200 -> return 2
arfcn<1950 -> return 3
arfcn<2400 -> return 4
arfcn<2650 -> return 5
arfcn<2750 -> return 6
arfcn<3450 -> return 7
arfcn<3800 -> return 8
arfcn<4150 -> return 9
arfcn<4750 -> return 10
arfcn<5010 -> return 11
arfcn<5180 -> return 12
arfcn<5280 -> return 13
arfcn<5380 -> return 14
arfcn<5730 -> return -1
arfcn<5850 -> return 17
arfcn<6000 -> return 18
arfcn<6150 -> return 19
arfcn<6450 -> return 20
arfcn<6600 -> return 21
arfcn<7500 -> return 22
arfcn<7700 -> return 23
arfcn<8040 -> return 24
arfcn<8690 -> return 25
arfcn<9040 -> return 26
arfcn<9210 -> return 27
arfcn<9660 -> return 28
arfcn<9770 -> return 29
arfcn<9870 -> return 30
arfcn<9920 -> return 31
else -> return 9999
}
}
}
Click to expand...
Click to collapse
Here I also post the 5G NR service to obtain the information:
package com.mobilenet.monitoring.services
import android.Manifest
import android.annotation.SuppressLint
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Binder
import android.os.Build
import android.os.Handler
import android.os.IBinder
import android.telephony.*
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.app.ActivityCompat
import com.mobilenet.monitoring.R
import com.mobilenet.monitoring.app.preferences
import org.json.JSONObject
class ServiceNr : Service() {
val TAG = "TESTING"
private var mBinder: IBinder = MyBinder()
private var mHandler = Handler()
/* Lte Parameters */
var mSignalStrength: SignalStrength? = null
var mListSignalStrength: List<CellSignalStrength>? = null
var mSignalStrengthNr: CellSignalStrengthNr? = null
var mManager: TelephonyManager? = null
/* LteConnection */
private var mNrData: JSONObject = JSONObject()
private var mNrNeighbourData: JSONObject = JSONObject()
var infos: MutableList<CellInfo>? = null
private lateinit var mContext:Context
private var jsonObject:JSONObject = JSONObject()
private var dataNeighbour = HashMap<String, String>()
private var nr:CellSignalStrengthNr? = null
private var identityNr:CellIdentityNr? = null
private var ci:Int = -1
private var MCC:String? = ""
private var MNC:String? = ""
private var PLMN:String? = ""
private var cellidHex: String = ""
private var eNBHex:String = ""
private var eNB: Int = -1
override fun onBind(intent: Intent): IBinder? {
return mBinder
}
@RequiresApi(Build.VERSION_CODES.Q)
@SuppressLint("MissingPermission")
override fun onCreate() {
super.onCreate()
Log.d(TAG, "onCreate")
mContext = this
/* NR */
mManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
// Register the listener with the telephony manager
// mManager!!.listen( mListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS or PhoneStateListener.LISTEN_CELL_LOCATION)
/*
SSB es el beam
*/
update()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if(intent?.getStringExtra("action") == "Destroy"){
onDestroy()
}
val CHANNELID = "Foreground Service ID"
val channel = NotificationChannel(
CHANNELID,
CHANNELID,
NotificationManager.IMPORTANCE_LOW
)
getSystemService(NotificationManager::class.java).createNotificationChannel(channel)
val notification: Notification.Builder = Notification.Builder(this, CHANNELID)
.setContentText("Monitoring is running")
.setContentTitle("Monitoring enabled")
.setSmallIcon(R.drawable.ic_launcher_background)
startForeground(1001, notification.build())
return super.onStartCommand(intent, flags, startId)
}
fun getNrData(): JSONObject {
return mNrData
}
fun getNeighbourNrData(): JSONObject {
return mNrNeighbourData
}
fun destroy(){
stopSelf();
}
// Listener for signal strength.
private val mListener: PhoneStateListener = object : PhoneStateListener() {
override fun onSignalStrengthsChanged(sStrength: SignalStrength) {
mSignalStrength = sStrength
if (ActivityCompat.checkSelfPermission(
mContext,
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED) {
infos = mManager!!.allCellInfo
}
}
override fun onCellInfoChanged(cellInfo: MutableList<CellInfo>) {
infos = cellInfo
}
}
private fun update() {
val runnable = object : Runnable {
@SuppressLint("MissingPermission", "NewApi")
override fun run() {
mManager!!.requestCellInfoUpdate( mContext.mainExecutor,
object : TelephonyManager.CellInfoCallback() {
override fun onCellInfo(cellInfo: MutableList<CellInfo>) {
mNrData = JSONObject()
mNrNeighbourData = JSONObject()
infos = null
jsonObject = JSONObject()
getData(cellInfo)
}
})
mHandler.postDelayed(this, 500)//preferences.periodicity.toLong())
}
}
mHandler.postDelayed(runnable, 500)//preferences.periodicity.toLong())
}
@SuppressLint("MissingPermission")
@RequiresApi(Build.VERSION_CODES.Q)
private fun getData(cellInfo: MutableList<CellInfo>){
try {
// Log.d(TAG, "$cellInfo") //Pondría esto para ver qué obtengo a ver si hay aquí algo mal
mSignalStrengthNr = (cellInfo[0] as CellInfoNr).cellSignalStrength as CellSignalStrengthNr
//Nr connected
if (preferences.NeighbourNrEnable) {
if (preferences.NeighbourNrRsrp) mNrData.put(
"NrRsrp",
"${mSignalStrengthNr!!.ssRsrp}"
)
if (preferences.NeighbourNrRsrq) mNrData.put(
"NrRsrq",
"${mSignalStrengthNr!!.ssRsrq}"
)
if (preferences.NeighbourNrSinr) mNrData.put(
"NrSinr",
"${mSignalStrengthNr!!.ssSinr}"
)
if (preferences.NeighbourNrAsulevel) mNrData.put(
"NrAsulevel",
"${mSignalStrengthNr!!.asuLevel}"
)
if (preferences.NeighbourNrDbm) mNrData.put(
"NrDbm",
"${mSignalStrengthNr!!.dbm}"
)
if (preferences.NeighbourNrLevel) mNrData.put(
"NrLevel",
"${mSignalStrengthNr!!.level}"
)
}
}catch (ex: Exception) {
Log.i(TAG, ex.message)
}
infos = mManager!!.allCellInfo
// Log.d(TAG, "$infos") //Pondría esto para ver qué obtengo a ver si hay aquí algo mal
jsonObject = JSONObject()
dataNeighbour = HashMap<String, String>()
if (preferences.NeighbourNrEnable){
jsonObject.put("NumberOfSites", "${infos!!.size}")
}
for (i in infos!!.indices) {
try {
val cell = infos!!
nr = (cell as CellInfoNr).cellSignalStrength as CellSignalStrengthNr
identityNr = (cell as CellInfoNr).cellIdentity as CellIdentityNr
// nr = (cellInfo[0] as CellInfoNr).cellSignalStrength as CellSignalStrengthNr
// identityNr = (cellInfo[0] as CellInfoNr).cellIdentity as CellIdentityNr
// Log.d(TAG,"${infos!!.indices}")
// Log.d(TAG,nr.toString())
// Log.d(TAG,identityNr.toString())
ci = identityNr!!.pci
MCC = identityNr!!.mccString
MNC = identityNr!!.mncString
if(MNC == null || MCC == null)
{
PLMN = "XXXX"
}
else if (MNC!!.length == 3) {
PLMN = "${MCC!![1]}${MCC!![0]}${MNC!![2]}${MCC!![2]}${MNC!![1]}${MNC!![0]}"
} else {
PLMN = "${MCC!![1]}${MCC!![0]}F${MCC!![2]}${MNC!![1]}${MNC!![0]}"
}
if (preferences.NeighbourNrRsrp){
var rsrp = nr!!.ssRsrp
dataNeighbour["RSRP"] = "${rsrp}"
}
if (preferences.NeighbourNrRsrq){
var rsrq = nr!!.ssRsrq
dataNeighbour["RSRP"] = "${rsrq}"
}
if (preferences.NeighbourNrSinr){
var sinr = nr!!.ssSinr
dataNeighbour["Sinr"] = "${sinr}"
}
if (preferences.NeighbourNrAsulevel){
var asulevel = nr!!.asuLevel
dataNeighbour["Asulevel"] = "${asulevel}"
}
if (preferences.NeighbourNrDbm){
var dbm = nr!!.dbm
dataNeighbour["Dbm"] = "${dbm}"
}
if (preferences.NeighbourNrLevel){
var level = nr!!.level
dataNeighbour["Level"] = "${level}"
}
dataNeighbour["PCI"] = "${identityNr!!.pci}"
dataNeighbour["CI"] = "${ci}"
dataNeighbour["MNC"] = "${MNC}"
dataNeighbour["MCC"] = "${MCC}"
dataNeighbour["PLMN"] = "${PLMN}"
dataNeighbour["MobileNetworkOperatorName"] = "${identityNr!!.operatorAlphaLong}"
dataNeighbour["TAC"] = "${identityNr!!.tac}"
dataNeighbour["EarFCN"] = "${identityNr!!.nrarfcn}"
} catch (ex: Exception) {
Log.i("TESTING: ", ex.message)
}
jsonObject.putOpt("Site$i", JSONObject(dataNeighbour as Map<*, *>))
}
mNrNeighbourData = jsonObject
}
override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)
stopSelf() //a hard stop for the service (si no queremos que siga en funcionamiento al cerrar)
}
override fun onDestroy() {
Log.d(TAG, "onDestroy")
super.onDestroy()
}
inner class MyBinder : Binder() {
fun getService(): ServiceNr? {
return [email protected]ServiceNr
}
}
private fun getBand(arfcn: Int):Int{
when {
arfcn<600 -> return 1
arfcn<1200 -> return 2
arfcn<1950 -> return 3
arfcn<2400 -> return 4
arfcn<2650 -> return 5
arfcn<2750 -> return 6
arfcn<3450 -> return 7
arfcn<3800 -> return 8
arfcn<4150 -> return 9
arfcn<4750 -> return 10
arfcn<5010 -> return 11
arfcn<5180 -> return 12
arfcn<5280 -> return 13
arfcn<5380 -> return 14
arfcn<5730 -> return -1
arfcn<5850 -> return 17
arfcn<6000 -> return 18
arfcn<6150 -> return 19
arfcn<6450 -> return 20
arfcn<6600 -> return 21
arfcn<7500 -> return 22
arfcn<7700 -> return 23
arfcn<8040 -> return 24
arfcn<8690 -> return 25
arfcn<9040 -> return 26
arfcn<9210 -> return 27
arfcn<9660 -> return 28
arfcn<9770 -> return 29
arfcn<9870 -> return 30
arfcn<9920 -> return 31
else -> return 9999
} //Ya paso de seguir haciendo la tabla https://5g-tools.com/4g-lte-earfcn-calculator/
}
}
Click to expand...
Click to collapse

Categories

Resources