Read custom Information Elements from WiFi Beacon on Android 12 - java

please, I am working on new app, which should read Information Elements from WiFi beacon in scan. I have Android 12 and using something like this:
ScanResult r = results.get(i);
List<ScanResult.InformationElement> ie = getWiFiInformationElement(r);
I see in the ie array. There is SSID and more, but I don't see my extra IE item with data from my device with ID 0xDD. I checked by another device, and my extra IE is visible on the air, but not visible by my Android phone with my app.
Please, could you help me?

Related

Android Badge number on launcher icon for all mobile manufacturer

I need a badge counter on my application launcher icon.
I know the solution to get Badge counter inside the app, using TextView, But I need a solution to get the badge counter external to the app on the launcher icon.
In iOS we get the badge number count by
UIApplication.sharedApplication().applicationIconBadgeNumber
I am wondering why Android has not included anything like this with their SDK which every developer need.
Try 1 : Working only on sony mobiiles :
Intent badgeIntent = new Intent();
badgeIntent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
badgeIntent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", this.getPackageName());
badgeIntent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", this.getClass().getName());
badgeIntent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", ShwMsgBulVar);
badgeIntent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", "10");
context.sendBroadcast(badgeIntent);
Try 2 :
I tried the library :
https://github.com/leolin310148/ShortcutBadger
It works only for few manufacturers and not common for all android mobiles.
ShortCutBadger is not working on OPPO, VIVO, Xiomi, Reliance LYF default launchers.
After couple of research, I came to know that, badge number depends on launcher manufacturer and listed as below :
ShortCutBadger Suported :
Samsung : "com.sec.android.app.launcher"
Sony : "com.sonyericsson.home"
HTC : "com.htc.launcher"
Asus : "com.asus.launcher"
ShortCutBadger not Suported :
Oppo :"com.oppo.launcher"
Xiomi : "com.miui.home"
Vivo : "com.bbk.launcher2"
Lyf : "com.android.launcher3"
Go Launcher : "com.gau.go.launcherex"
So is there any other general method which can work on all manufacturer mobiles?
Read so many posts and did lot of search but Many tell there is no such generic solution which is applicable for all launchers.
But I feel there is a solution because whatsapp and facebook app display the badge number in all the above mentioned launcher.
There is no such function in Android as badge numbers are not a part of the platform.
A few libraries exist that try to achieve this such as https://github.com/leolin310148/ShortcutBadger but you should understand that it does not work for every manufacturer's device. Also as far as I understand the badges only appear over the icon when it is on a home screen and not in the app drawer.

Java set MIDI Out receiver

Hey I am trying to send MIDI data from a Java class to a MIDI device connected via USB. I did this once like 2 years ago and it worked, but I somehow can't find the project anymore.
The example Java code runs fine;
myMsg = new ShortMessage();
myMsg.setMessage(ShortMessage.NOTE_ON, 0, 60, 93);
timeStamp = -1;
Receiver rcvr = MidiSystem.getReceiver();
rcvr.send(myMsg, timeStamp);
Simple stuff. 5 lines of code and the message appears on the device. The problem is, that this way, only the standard device is set up and ready to receive MIDI. I can't ask my users to set the device of desire as standard device every time they want to use my application. (the Receiver acts as output destination/port to the input of the physical device I am connected to)
I am now trying to set up the Receiver by doing the following:
MidiDevice.Info[] infoA=MidiSystem.getMidiDeviceInfo();//array where all the device info goes
for (int x=0;x<infoA.length;x++){
System.out.println("in "+infoA[x]); //this displays all the devices
}
MidiSystem.getMidiDevice(infoA[d]); //d is set to an integer that represents the item number on the device list of the device I wanna send MIDI to
System.out.println(infoA[d]);//last check if the correct device is selected
MidiDevice MidiOutDevice = MidiSystem.getMidiDevice(infoA[d]); //setting this to "my" device in order to set the Receiver
maschineReceiver= MidiOutDevice.getReceiver();
Sequencer MidiOutSequencer = MidiSystem.getSequencer();
MidiOutSequencer.getTransmitter().setReceiver(maschineReceiver); //probably unnecessary last 2 line but I gave this a try in case it helps
if I now do maschineReceiver.send(myMsg, timeStamp);, nothing happens at all. I also tried different devices but it didn't get any better. I am sure it can't be a very hard difficult thing to do as it something I actually achieved 2 years ago when my coding skills were awful but I just can't find the mistake right now, no matter how often I reread the Java documentation, it just won't work whatever I do.
Thanks in advance
To actually reserve a device for your program, you need to use the MidiDevice method open:
if (!(device.isOpen())) {
try {
device.open();
} catch (MidiUnavailableException e) {
// Handle or throw exception...
}
}

scan qr code link to particular page in the android app

I am creating an android app that have some page with information read from the sqlite database and a qr code reader built in the app, but i have question to ask
This is my question :
when i read the qr code which contain some IDs, is it possible to link/bring to a particular page that have that IDs ?
I try to google for information about this, but i did not find any sample code or tutorial that teach how to link from qr code to particular part in the android app. From all the google information i found, i only know that i need a url, then how can i generate a url to link to the android app? does it mean that i have to create a website?
MY MAIN IDEA:
in my android app have information:
Page 1:
Apple
cost 1 dollar
Page 2:
Pear
cost 1.50 dollar
What i want to do:
Scan qr code from my android, reader retrieve Page 1 as ID, then link/go to Page 1 in the android app
I just want go to or link to that particular activity1(page1) after scan the qr code that contain 1 within that same app
To open url from android app use this:
String url = "http://www.example.com/YOUR-ID-GENERATED_PAGE";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
source page here on StackOverflow
You can use TEXT format of QR code to return a text rather than a URL. In your case, the returned text could be an ID. Map your IDs with the Activities you are intended to awake after scanning.Then check the ID and start your mapped Activity manually in your application.

Android - Get a contact's Facebook picture

Android platform is really fun to work with especially when it comes to resolving issues. Indeed, there is possibly everything there is to know about Android development on the internet.
Alright, I've been searching for about a week and haven't found anything that was close from working. Let's dive into it.
We are building an Android Application that requires a read/write access to existing Contacts on a device. It has become really easy to read a contact's set photo using this method :
// Returns a stream reading a contact thumbnail
public InputStream getContactThumbnail(int id) {
// Stream reading contact image
InputStream stream = ContactsContract.Contacts.openContactPhotoInputStream(
context.getContentResolver(),
ContentUris.withAppendedId(
ContactsContract.Contacts.CONTENT_URI, id
)
);
// If image is null, try to read Facebook image
if (stream == null) {
stream = new ByteArrayInputStream(getFacebookPhoto(id));
}
return stream;
}
Now, the previous method receives an id as a parameter and returns a Stream making it possible to read the contact's thumbnail. It is needed to be a stream because the phone acts like a web server and has multiple threads running. If a thumbnail is requested several times in the same short time lapse, an OutOfMemoryException will be thrown for sure.
I need to correctly implement the getFacebookPhoto(int) method so that it returns whatever stream reading the Facebook profile picture of a contact that has his or her contact linked with his or her respective Facebook profile. I've tried and failed so many times.
Hypothesis #1
If a contact is linked with a Facebook profile, it has to have the Facebook ID saved somewhere. If this information is accessible, it would make it easy to get a Facebook profile picture using graph. Problem is an internet connection is needed to do so.
Hypothesis #2
Facebook thumbnails are saved somewhere on the SD card. Maybe there's a link between a Contact and those files that can be found through an SQLite request?
Hypothesis #3
sigh, I look desperate. Okay, if I understood correctly, a phone Contact and a Facebook Contact are not the same things in the database. If you query all the contacts from the following URI :
*ContactsContract.Contacts.CONTENT_URI*
you only get contacts that you created and nothing regarding Facebook links. Is there a way to find all linked contacts and get their respective photos?
Conclusion
Yeah, that's about is. To sum it up, I need to read all contacts information. For each contact, I have to find its photo. If the user has not set a picture to a contact that is linked to a Facebook profile, the profile picture which it was linked too must be read.
Up until now, the StackOverflow community has been of a great help and saved my life and job countless times. It is possible, I've seen it in other apps.
Thank you for spending of your time, it is truly appreciated.
EDIT
Let's not give up! I will start a 100pts bounty as soon as I can.
Your hypothesises are right to a certain extend. In contact application this things are handled as folows -
Device's Contact & its Facebook account are mapped by Contact's _ID & Facebook's id, this is one-to-one mapping. So from this mapping first you have to find out the Facebook id
of the conserned contact. But in which table this info is stored & wheather that table is eposed to you or not, URL to that table completely dependent on vendors.
From Facebook Id we can get corresponding profile image either from Facebook's server or from Media DB, if it is also cached in.
But this is not supported by all OEMs. And implementation varies from OEM to OEM as Google don't enforce for any common standard implementation of it.
So there is no garantee that a single implementation will work for all devices from different OEMs.
You should really go and play around with Graph Explorer on the Facebook Developers site it will help you a lot in figuring out what you need to do to get certain things. In order to get the picture for an person you just have to do is do a simple GET HTTPRequest with the graph path of /ID?fields=picture (where ID is the facebook id of the contact) which will return a JSON object that contains the link to that person's profile picture. From there it should be fairly simple for you to get the image.
You can also do the same thing to get all of a person's friends with the picture information by sending a GET request to /me/friends?fields=picture. It seems like you are trying to avoid a web connection but if the android contacts do not store the facebook id then you will have to get the ids yourself I'm afraid.
Hope that helps.
Why don't you use FQL, for Android you can use -
String query = "SELECT uid, name, pic, pic_small, pic_big FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
Bundle params = new Bundle();
params.putString("method", "fql.query");
params.putString("query", query);
mAsyncFacebookRunner.request(null, params, new CustomRequestListener());
where CustomRequestListener() extends RequestListener in the Facebook Android SDK.

How does Facebook add badge numbers on app icon in Android?

I know there are several Qs here that ask if its possible to add badges to an android app and they all end up with a NO answer...
But somehow the latest Facebook beta version for Android seems to do something which at least look like a badge even if it is not technically exactly that.
In that post one of the commenters says that it is somehow related to TouchWiz.
And also here they mention it as a feature of the "S3 TouchWiz Jelly Bean Addon".
I still would appreciate information on how does this can be done and if there is some API for this that I can use in my own app (when running in an appropriate environment - i.e. the same device where FB demonstrates this behavior) ?
Hi you can use this lib simply.
Support : Sony,Samsung,LG,HTC,Xiaomi,ASUS,ADW,APEX,NOVA,Huawei,ZUK,OPPO
ShortcutBadger
Add :
int badgeCount = 1;
ShortcutBadger.applyCount(context, badgeCount);
Remove :
ShortcutBadger.applyCount(context, 0);
I have figured out how this is done for Sony devices.
I've blogged about it here. I've also posted a seperate SO question about this here.
Sony devices use a class named BadgeReciever.
Declare the com.sonyericsson.home.permission.BROADCAST_BADGE permission in your manifest file:
Broadcast an Intent to the BadgeReceiver:
Intent intent = new Intent();
intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", "com.yourdomain.yourapp.MainActivity");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", "99");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", "com.yourdomain.yourapp");
sendBroadcast(intent);
Done. Once this Intent is broadcast the launcher should show a badge on your application icon.
To remove the badge again, simply send a new broadcast, this time with SHOW_MESSAGE set to false:
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", false);
I've excluded details on how I found this to keep the answer short, but it's all available in the blog. Might be an interesting read for someone.
There is not a standard way to achieve this; Many makers such as Sony or Samsung have implemented it in their own Android customization.
For example in Samsung, you have to broadcast an intent with BADGE_COUNT_UPDATE action, let MainActivity be your main activity class and count be the number you want to display in your app icon, note that 0 will hide the badge:
Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
intent.putExtra("badge_count", count);
intent.putExtra("badge_count_package_name", context.getPackageName());
intent.putExtra("badge_count_class_name", MainActivity.class.getName());
context.sendBroadcast(intent);
Sony devices uses "com.sonyericsson.home.action.UPDATE_BADGE" action with their custom extras as #Marcus Answered, so you have to add "com.sonyericsson.home.permission.BROADCAST_BADGE" permission to your app manifest and:
Intent intent = new Intent("com.sonyericsson.home.action.UPDATE_BADGE");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", MainActivity.class.getName());
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", String.valueOf(count));
intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", context.getPackageName());
context.sendBroadcast(intent);
Note: it's desirable to query your app's data (context.getPackageName(), MainActivity.class.getName()) rather than hardcode it just in case you do some refactoring in the future.
But somehow the latest Facebook beta version for android does just that...
Not according to the forum thread that contains the screenshot that you linked to. Quoting vakama94:
Well, that's actually TouchWiz and not just the app. I have a Galaxy S II running JellyBean 4.1.2 and it makes the same thing but with some other applications
Whether Samsung has a public API to allow apps to publish numbers to be used as badges, I cannot say. This could be something that they did privately with a few firms.
You are welcome to provide evidence of seeing these badges on a stock Android home screen, such as one of the Nexus series devices.
I answer to this assuming that some flutter dev can search this...
In Flutter, you can achieve this by using
Flutter app badger library.
It is as simple as
FlutterAppBadger.updateBadgeCount(1); // show
FlutterAppBadger.removeBadge(); // hide

Categories

Resources