I'm working on the recurring serial number topic to provide a unique id.
I try this :
String serial = null;
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
serial = (String) get.invoke(c, "ro.serialno");
} catch (Exception ignored) {
}
and
StringBuilder sb = new StringBuilder();
sb.append("SERIAL ").append(android.os.Build.SERIAL).append("\n");
textReportAdmin.setText(
sb.toString());
Both gives the same value : C4F12FDD949F22F
On the box and on the sticker of my tab, the serial number is : RF2C202WYME
I work on a tab, no way to use
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imei = telephonyManager.getDeviceId();
IMEI is empty in my case.
SERIAL is what I need, but I need it in clear version as displayed on the sticker upon the barcode behind the tab.
I guess it is possible as, When going in the system app, and looking at the state of the device, it is displayed in clear...
How to convert the value returned by android.os.Build.SERIAL to the human visible one ?
EDITION : I also looked in :
sb.append("PRODUCT ").append(android.os.Build.PRODUCT).append("\n");
sb.append("BOARD ").append(android.os.Build.BOARD).append("\n");
sb.append("BOOTLOADER ").append(android.os.Build.BOOTLOADER).append("\n");
sb.append("BRAND ").append(android.os.Build.BRAND).append("\n");
sb.append("CPU_ABI ").append(android.os.Build.CPU_ABI).append("\n");
sb.append("CPU_ABI2 ").append(android.os.Build.CPU_ABI2).append("\n");
sb.append("DEVICE ").append(android.os.Build.DEVICE).append("\n");
sb.append("DISPLAY ").append(android.os.Build.DISPLAY).append("\n");
sb.append("FINGERPRINT ").append(android.os.Build.FINGERPRINT).append("\n");
sb.append("HARDWARE ").append(android.os.Build.HARDWARE).append("\n");
sb.append("HOST ").append(android.os.Build.HOST).append("\n");
sb.append("ID ").append(android.os.Build.ID).append("\n");
sb.append("MANUFACTURER ").append(android.os.Build.MANUFACTURER).append("\n");
sb.append("MODEL ").append(android.os.Build.MODEL).append("\n");
sb.append("PRODUCT ").append(android.os.Build.PRODUCT).append("\n");
sb.append("RADIO ").append(android.os.Build.RADIO).append("\n");
sb.append("SERIAL ").append(android.os.Build.SERIAL).append("\n");
sb.append("TAGS ").append(android.os.Build.TAGS).append("\n");
sb.append("TIME ").append(android.os.Build.TIME).append("\n");
sb.append("TYPE ").append(android.os.Build.TYPE).append("\n");
sb.append("USER ").append(android.os.Build.USER).append("\n");
nowhere, I get the serialnumber as on the sticker, while it can be possible to be found as ,the system itself is able to display it in "Parameters", "About", "State" (I don't know the words in english, I have a french tab, and it is "Paramètres", "A propos de", "Etat" and then "Serial Number", the clear version, as on the sticker.
Have you tried this?
String serial = null;
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
serial = (String) get.invoke(c, "ril.serialnumber");
} catch (Exception ignored) {
}
If you want to get the serial number as shown on the back of the device and if you are using the Samsung Galaxy Tab then why not use the 'ril.serialnumber' property
Items changed to what your device should show:
$ adb shell getprop | grep serial
[ril.serialnumber]: [RF2C202WYME]
[ro.boot.serialno]: [c4f12fdd949f22f]
[ro.serialno]: [c4f12fdd949f22f]
Pre-jellybean 'ro.boot.serialno' didn't exist
On many devices there is information displayed in the Settings --> About activity that is non-standard and is not available from any standard Android API. For example, the FCC ID is sometimes displayed there but is not available to apps.
Also, there is no requirement that the serial number available through the API's be the product's 'real' serial number (i.e. the one on the package). Just that it be unique.
So, I think there is no way to do what you want (read the serial number that is on the box and in the about activity) other then look through that product's source code (if available) and see if there is a way to get that info for that particular product or manufacturer.
you should use
sys.serialnumber ,some devices have ril.serialnumber and some have sys.serialnumber ,so you should try sys one
Related
Google told me that in order for me to be able to use either TelephonyManager or TelcomManager to read device identifiers I need one of the requirements stated on the documentation for the respective device identifiers such as GetImei or GetLine1Number. I decided to meet the requirement that states The caller needs to be the default SMS Role holder on that device. So I created an app that is listed as an alternative SMS app on my device and then I check if my app holds that role and then try to get the device identifiers. My code reads the IMEI of both sim cards successfully but fails to read the phone number of the device as the method returns null but I did not expect this as the default sms app should be able to access that number for texting purposes. I am using the following code, help me make this work.
try
{
if (roleManager.IsRoleHeld(RoleManager.RoleSms))
{
var manager = (TelephonyManager)GetSystemService(Context.TelephonyService);
new Android.App.AlertDialog.Builder(this).SetTitle("Device Identifiers")
.SetMessage("phone no " + manager.Line1Number + "\n" + "line 1 imei: " + manager.GetImei(0) + "\n" +
"line 2 imei: " + manager.GetImei(1) + "\n" +
"serial no: " + manager.SimSerialNumber
).Show();
//telephonyManager.GetLine1 fails so
//try and use the telecom service to read the number
var telcom = (TelecomManager)GetSystemService(Context.TelecomService);
//get a list of all capable calling accounts
IList<PhoneAccountHandle> handles = telcom.CallCapablePhoneAccounts;
if (handles != null)
{
//Toast the phone capable calling accounts count
Toast.MakeText(this, handles.Count.ToString(), ToastLength.Short).Show();
//get the phone account handle in index 0
PhoneAccountHandle handle1 = handles[0];
//get the phone number associated with that acount
string phone1 = telcom.GetLine1Number(handle1);
if (phone1 != null)
{
new Android.App.AlertDialog.Builder(this).SetTitle("Phone Number")
.SetMessage(phone1).Show();
}
}
string phone = telcom.GetLine1Number(handles[1]);
if (phone != null)
{
Toast.MakeText(this,phone,ToastLength.Short).Show();
}
else
{
Toast.MakeText(this, "GetLine1 is returning null", ToastLength.Short).Show();
}
}
} catch (Java.Lang.SecurityException exc)
{
Toast.MakeText(this, exc.Message, ToastLength.Short).Show();
}
An answer in Android Java is also acceptable, Thank You.
At first, please check the AndroidManifest.xml if you added the <uses-permission android:name="android.permission.READ_PHONE_STATE"/> in it or not.
In addition, there is no reliable way to get the phone number from the SIM card because some telecom operators don't add this information in SIM card and someone did. So sometimes you can get the number and sometimes you will get a null even a phone number you used before.
The most used solution on the SO is using the Google Play Service to get the phone number. You can check this case. And in the Xamarin, you can use the package named Xamarin.GooglePlayServices.Auth to do that.
I'm trying to add push notification to my mobile native chat app. I'm trying to use OneSignal.
I can send manual push notification, so I think gradle part is okay
idsAvaiable method is deprecated, I started to looking for how can I get userId.
OSPermissionSubscriptionState status = OneSignal.getPermissionSubscriptionState();
String userId = status.getSubscriptionStatus().getUserId();
In here, I'm trying to get userId with status, but it's saying:
Cannot resolve symbol 'OSPermissionSubscriptionState'
How can I get userId?
Root cause
From OneSignal API 4.0.0, there are many APIs that have been removed including OSPermissionSubscriptionState.
Solution 1
Use OneSignal.getDeviceState()
OSDeviceState device = OneSignal.getDeviceState();
String userId = device.getUserId();
Solution 2
Use OneSignal.addSubscriptionObserver()
OneSignal.addSubscriptionObserver(new OSSubscriptionObserver() {
#Override
public void onOSSubscriptionChanged(OSSubscriptionStateChanges stateChanges) {
if (!stateChanges.getFrom().isSubscribed() && stateChanges.getTo().isSubscribed()) {
// Get user id
String userId = stateChanges.getTo().getUserId();
}
}
});
For more information, see the change log here.
I am receiving notification payload as
[AnyHashable("jsonData"): {"packageName":"com.company.appName","appName":"AppName","orderId":"0","workflow":"PAGE_OWNER_STATUS_WORKFLOW"}, AnyHashable("aps"): {
alert = {
body = "You have received a new Order! ";
title = Orders;
};
sound = default;
},AnyHashable("google.c.a.e"): 1, AnyHashable("gcm.notification.jsonData"): {"packageName":"com.company.appName","appName":"AppName","orderId":"0","workflow":"PAGE_OWNER_STATUS_WORKFLOW"}, AnyHashable("title"): Orders, AnyHashable("google.c.sender.id"): 34781329473, AnyHashable("body"): You have received a new Order! , AnyHashable("sound"): phone_ringing.caf, AnyHashable("gcm.message_id"): 1597347128946557]
It does not add sound name in aps alert. Will it be done from backend?
We are using JAVA for Backend.
I believe the sound property has to be set as a property of the aps and not of the alert object, like you're receiving now and like it is specified in apple documentation. Apple example:
{
“aps” : {
“badge” : 9
“sound” : “bingbong.aiff”
},
“messageID” : “ABCDEFGHIJ”
}
You should specify the string "default" to play the default notification sound, otherwise a filename must be set and the file needs to exist on the app. These changes would have to be done on the server side.
I've created an address book app, and am trying to add some features to it. What I'm trying to do right now is add the ability to longclick a phone number, and then either call/text/mms the number. This all works fine with phones, but I was wondering how to do this on tablets, since they will not have that same ability. The device I'm debugging on is a tablet, and I use HeyWire for texting. I know there are apps out there for calling via WiFi as well. Here's what I have so far for the texting section of my switch statement:
case 1: //SMS
if(CanCallAndText)
{
CustomSMSDialog SendSMSDialog = new CustomSMSDialog(BrowseListActivity.this, ParsedPhoneNum);
SendSMSDialog.setTitle("Sending text to " + PhoneNum);
SendSMSDialog.setCancelable(false);
SendSMSDialog.show();
}
else
{
try
{
Intent WiFiSMS = new Intent(Intent.ACTION_VIEW);
WiFiSMS.setData(Uri.parse("sms:" + PhoneNum));
WiFiSMS.setType("vnd.android-dir/mms-sms");
startActivityForResult(Intent.createChooser(WiFiSMS, ""), 0);
}//endtry
catch(Exception e)
{
Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}//endcatch
}//endelse
break;
I don't know if I'm doing the create chooser incorrectly or not, but it simply tells me that no apps can handle it. Thank you!
EDIT: Ooh, spotted a slight error that I should fix tomorrow. The URI should include ParsedPhoneNum, instead of PhoneNum. Anything other than a number, like a -, would be included in PhoneNum.
I want to add a telephone number into the contact according to the ID number, but it always being added to the wrong name. Can anyone tell me the reason why this happened. It runs well in virtual device and sony mobile phone , but it come to an error as I said above in a new Samsung moble phone. I can clearly confirm that the ID number is right
These is the source code:
ContentValues values = new ContentValues ();
values.clear();
values.put(ContactsContract.Data.RAW_CONTACT_ID, contactID);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, shortNumber);
values.put(ContactsContract.CommonDataKinds.Phone.TYPE, Phone.TYPE_OTHER);
getContentResolver().insert(Data.CONTENT_URI,values);
values.clear();
The answer here may help: Inserting contacts in Android 2.2.
It seems the code above does not work on all devices as per the comments there. The answer posted by Alok Save https://stackoverflow.com/users/452307/alok-save, suggests using the applyBatch() method as follows:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int rawContactInsertIndex = ops.size();
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, null)
.withValue(RawContacts.ACCOUNT_NAME,null )
.build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
.withValue(Data.MIMETYPE,Phone.CONTENT_ITEM_TYPE)
.withValue(Phone.NUMBER, "9X-XXXXXXXXX")
.build());
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
.withValue(Data.MIMETYPE,StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, "Mike Sullivan")
.build());
ContentProviderResult[] res = getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);