I am trying to get the google ad id (GAID)in android java but I am getting exeception like:
androidx.ads.identifier.AdvertisingIdNotAvailableException: No compatible AndroidX Advertising ID Provider available.
My Code
ListenableFuture<AdvertisingIdInfo> adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
System.out.println("adinfo"+adInfo.toString());
try {
String id = adInfo.get().getId();
System.out.println("adod"+id);
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
And dependienced i added
implementation 'com.google.android.gms:play-services-ads:19.4.0'
implementation 'androidx.ads:ads-identifier:1.0.0-alpha04'
In Manifest I added
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true"/>
I have tried many solutions but it is not useful. Please help me out to solve the issue.
The gaid dependency in androidx seems to be at fault.
Many people (including me) have followed Google's ad ID documentation and have reported the same issue. Also, Google's documentation on this matter appears outdated since the examplatory code snippet is wrong (e.g. function addCallback is missing a parameter).
The solution is to add this dependency in your gradle file instead of the ones you mentioned:
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
You can then fetch the advertising id this way:
AdvertisingIdClient.Info idInfo;
try {
idInfo = AdvertisingIdClient.getAdvertisingIdInfo(context);
String advertisingId = idInfo.getId();
//do sth with the id
} catch (IOException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
}
If you want to use the id only when the user hasn't opted out of personalised ads, you can add this after retrieving the id info:
//if user hasn't opted out of ads in device settings
if(idInfo.isLimitAdTrackingEnabled()) {
//do sth with the id
}
Edit: The mentioned Google's documentation actually has a note that encourages you to use the ads identifier library I mentioned:
Related
Following their guide in usage here I couldn't get started.
The code:
KucoinClientBuilder builder = new KucoinClientBuilder()
.withApiKeyVersion(2)
.withBaseUrl("https://openapi-sandbox.kucoin.com")
.withApiKey("MyKey", "MySecret", "MyPass");
KucoinRestClient kucoinRestClient = builder.buildRestClient();
KucoinPrivateWSClient kucoinPrivateWSClient;
try {
kucoinPrivateWSClient = builder.buildPrivateWSClient();
KucoinPublicWSClient kucoinPublicWSClient = builder.buildPublicWSClient();
} catch (IOException e) {
e.printStackTrace();
}
builder.buildPrivateWSClient() throws an exception with this message:
KucoinApiException{code='400003', message='KC-API-KEY not exists'}
I copied the Api Key and Secret and pass from the api page
What am I missing here? Why the KC-API-KEY does not exist?
The "sandbox" account is different than the original account.
Its domain is different and you need to register in the sandbox version of the website here
i am trying to use JournalArticleServiceUtil class to get web content, but it shows an error and i don't know how to fix it, there's my code
long groupId = themeDisplay.getLayout().getGroupId();
System.out.println("GroupId: " + groupId);
List<JournalArticle> articleList = new ArrayList<>();
List<String> news = new ArrayList<>();
try {
DDMStructure structure = DDMStructureManagerUtil.getStructure(Long.parseLong("94203"));
articleList = JournalArticleServiceUtil.getArticlesByStructureId(groupId, structure.getStructureKey(), 0, 10, null);
for (JournalArticle art: articleList) {
news.add(art.getContent());
}
} catch (SystemException e) {
log.error(e.getMessage());
} catch (NumberFormatException e) {
log.error(e.getMessage());
} catch (PortalException e) {
log.error(e.getMessage());
}
the error says
com.sun.proxy.$Proxy466 cannot be cast to com.liferay.journal.service.JournalArticleService
i hope you can help me with this
This seems related to the implementation version of the service class you are using. If you are using gradle, you could give preference to compileOnly rules and make sure you match the kernel version in you server with the one you are using. Some times you do need to declare implementation versions directly on you bnd.bnd.
Something like:
Import-Package: com.liferay.journal.model;version="[1.0.0,3.0.0)", com.liferay.journal.service; version="[1.0.0,3.0.0)",*
I think you should try using JournalArticleLocalServiceUtil instead of JournalArticleServiceUtil.
I'm developing a maven-plugin to check dependencies' licenses, similar to this one, but I can't found any API for that... what I would like to have is something like
String licence = artifact.getLicence();
mrice on that license-check plugin just try to find the .pom file of that artifact, read it, and try to find the <license></license>.
Do you know how can I do this?
You need to use org.apache.maven.model.License. (See api docs for details).
Something like this:
try {
Reader reader = new FileReader(pomXmlFile);
Model model;
try {
final MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
model = xpp3Reader.read(reader);
} finally {
reader.close();
}
List<License> licenses = model.getLicenses();
} catch (XmlPullParserException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
*Note that many poms do not have a license.
In java RMI i am building a chat application. But i am not able to figure out a way to find out, whether the IP which is hitting my server is from my internal organization network(INTRANET) or from external world(INTERNET).
Right now i am using
try {
System.setProperty("java.rmi.server.hostname",InetAddress.getLocalHost().getHostAddress());
Registry statusRegistry = LocateRegistry.createRegistry(ChatConstants.statusPort);
ChatInterface chat = new ChatImpl(ChatConstants.statusPort) ;
statusRegistry.rebind("statusconnection",chat);
System.out.println("RMIStatusConnection Server is started...");
} catch (RemoteException e) {
System.out.println("RMIStatusConnection failed...");
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
}
Try RemoteServer.getClientHost(), but it may only provide the address of the nearest NAT device.
NB there's not much point in setting java.rmi.server.hostname like that. That's the default. You only need to set it if there's something wrong with the default setting.
I have a strange problem. I have an mp3 stream I am trying to utilize within an application (2.1). Before you say streaming isn't supported here, it seems to be.
I was able to get it working last night by using the following code:
import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Stream extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource("http://ipaddress:8000/");
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
}
}
However, today, it doesn't work. Furthermore, last night -- I was able to use the Internet Browser on my android phone to stream it. Although, last night when I went to the address, it opened the stream in video player. Nonetheless, I am unable to open it today in the browser, either.
In the browser, I keep getting the "page not displayed" page. I have actually verified it is online. I can browse to it from my PC (on the same network), and have confirmed internet connectivity to my android by utilizing other streaming applications and browsing to other web pages.
I am stumped as to why my code (or the stream) suddenly stopped working overnight on the phone. The code even works on a 2.1 emulator (and streams it).
Let me know what you all think, please.
Thanks in advance!
Seems to be a connectivity problem on the network side. Too many connections were opened from the phone on WiFi to the streaming server. This caused an IP blacklist. Today, this seems to have cleared up.