Problem when trying to obtain a List from a Parcel object - Android Q&A, Help & Troubleshooting

Hi, I'm italian so I apologize for my bad english...
I have a problem when I use the method
Code:
readList(List outVal, ClassLoader loader)
I use this in this way
Code:
parcel.readList(mylist, null)
I want to put the list that I putted into the parcel object in mylist. But when I try to access to the list I obtain a nullPointerException...
What is wrong?

Related

[Q] Call method from view to activity

hi, how can i call a method that is in a view.java going to my activity.java? is there a command for that?
please help =(
In general, if the classes can "see" each other, and the method you want to call is accessible by the caller class, then just call the method via an instance of the according class. So let's say there were class A in file A.java with the method a() and you want to call it from class B in B.java you need to make sure that a() is not a private method (declared public, protected or not explicitly declared) and also it were good if the classes shared the same package.
Then just create an instance of A accessible by a method of B. (only necessary if a() isn't static!) For example like:
Code:
class B {
B() {
A objectOfTypeA = new A();
objectOfTypeA.a();
// voila
}
}
So as you can see there's no special command necessary to call a method of another class. Also I recommend you to read some tutorials about controlling access to members of a class.

[Q] NullPointerException when trying to access MainActivity from different class

Hi!
I am trying to develop an android app with a google map v2, location service and some control buttons.
But I don't want to put all these things inside one MainActivity class. So I thought I could split all the code into some more classes. The MainActivity shall controll all the GUI things and react on map or location events...
Now I have the following problem. Inside my onCreate I instanziate the additional classes:
Code:
// Preferences as singleton
pref = Prefs.getInstance(this.getApplicationContext());
pref.loadSettings();
// Set up the location
loc = new Locations(pref);
loc.setCallback(this);
map = new MyMap(pref);
It seems to work fine. But inside the MyMap class every time I start the app a null pointer exception is thrown. When I am calling MyMap() the following code will be executed:
Code:
[...]
private Prefs pref;
private GoogleMap mMap;
[...]
public MyMap(Prefs prefs) {
pref = (Prefs) prefs;
if (mMap == null) {
FragmentManager fmanager = getSupportFragmentManager();
mMap = ((SupportMapFragment) fmanager.findFragmentById(R.id.map)).getMap();
[...]
}
The line with the findFragmentById is the one that causes the exception.
If I write
Code:
SupportMapFragment f = ((SupportMapFragment) fmanager.findFragmentById(R.id.map));
f is allways null. But how can I access the fragments and view elements defined within my MainActivity?
It works if I put the code inside my MainAcitivity.
Every class extends "android.support.v4.app.FragmentActivity"
I tried to save the application context within my Prefs() class, so that I can access it from everywhere.
But I don't know how to use it inside my additional classes.
How to share the "R" across all my classes?
Can someone help me please?
Thank you very much!!
Thorsten
Are you having trouble adding a Map to a Fragment? If so, then you may take a look at this tutorial. I haven't tried it myself since I couldn't install Google Play Services on my development device. If it helps, do write back, as I am definitely going to try it myself soon.

Invalid Android ID (aid:0)

Hi guys...
Since few weeks now, i'm facing to an unsolvable trouble that prevent me to access to google play (with the famous error "No Connexion"). I spent hard time to search why, tried some fixes found on the web... Nothing works.
This morning, i found with the Android Device-ID application that my "GSF Device-ID" is set to "null" ! Said differently, i'm pretty sure that my device (Samsung Galaxy S2) can't be recognized and identified on Play store because of this, giving me the "No Connexion" error.
Does anybody here know how i could fix this invalid ID (which is confirmed with the *#*#8255#*#* trick : aid:0 (INVALID AID!!!)
Thanks in advance for your help.
cheers
UP.
Nobody can help ? i can't believe it according to the number of gurus here
I am more and more convinced that the secret of this famous GSF ID is jealously guarded by its creators, and finally how to handle it are not or little known ... And for good reason, since this is for Google one of the only way to identify and thus tracking devices safely and reliably. Make it easily editable would be a disaster for them I guess ...
I still dare to hope that some geniuses who frequent this forum have already faced this problem and had pierced the mystery and how to handle this identifier.
I found the beginning of an answer with the sources code of an app "Android ID" :
Code:
private static final Uri URI = Uri.parse("content://com.google.android.gsf.gservices");
private static final String ID_KEY = "android_id";
String getAndroidId(Context ctx) {
String[] params = { ID_KEY };
Cursor c = ctx.getContentResolver()
.query(URI, null, null, params, null);
if (!c.moveToFirst() || c.getColumnCount() < 2)
return null;
try {
return Long.toHexString(Long.parseLong(c.getString(1)));
} catch (NumberFormatException e) {
return null;
}
}
In my case, i get a "null" for GSFID. That means no columns are found in reply to the query.
I have verified this by installing aSQLiteManager on my SGS2, and opening the gservices.db database.
My problem now is to find what are the key fields
that are supposed to be filled in order to have a GSF value returned.
Maybe some of you could provide me this information by having a look to your own configuration.
Thanks in advance.
I've got same problem
My phone is LG Optimus L5 and after I rooted my phone,I've got same problem and I couldn't connect to Google products and my AID's been null!

adb raw protocol AUTH

Hello,
as the title says, i have some trouble with the A_AUTH packet. I currently write my own implementation of the adb protocol for my AndroidCtrl.dll everything works so far as expected, only the token signing left...
QUESTION:
Can someone kick me in the right direction, how i can successfully sign the A_AUTH token?
My tries [C# .Net 4 Client]
Code:
//Class internal var
RSACryptoServiceProvider _rsaSP = new RSACryptoServiceProvider(2048);
// (my own loader) Load the xml saved RSA-Key
RSALoad()
// generate the signed hash
// (don't work)
byte[] shash = _rsaSP.SignData("20 byte token from A_AUTH", new SHA1CryptoServiceProvider()));
// generate the signed hash
// (don't work)
byte[] shash = _rsaSP.SignData("20 byte token from A_AUTH", new SHA256CryptoServiceProvider()));
I also tried it with "_rsaSP.SignHash()" but no luck... Seems .Net is not capable to sign a adb token... If i send my public key, on the device the adb dialog pops up and ask me to grand access. So the device have the public key. But it sends all the time a new token after i send my signed token...
THX in advance
Sebastian

Getting Place Details with HMS Site Kit

If we briefly talk about what HMS Site Kit is, you can provide users to explore the world faster with Site Kit. You can search for locations by keywords, find places which are close to the specified coordinate point, get detailed information about a place and get suggestions for places by keyword.
We can get detailed information about a place with Place Detail Search, another feature of Site Kit. The only condition for this, we need to know Site model’s id value that belongs to the place we want to search.
Before I explain the use of Place Detail Search, I would like to share with you a function that we can use this feature.
Code:
fun placeDetail(siteId: String){
val searchService = SearchServiceFactory.create(context,
URLEncoder.encode(
"Your-API-KEY",
"utf-8"))
var request = DetailSearchRequest()
request.siteId = siteId
request.language = Locale.getDefault().language // Getting system language
searchService.detailSearch(request, object: SearchResultListener<DetailSearchResponse>{
override fun onSearchError(searchStatus: SearchStatus?) {
Log.e("SITE_KIT","${searchStatus?.errorCode} - ${searchStatus?.errorMessage}")
}
override fun onSearchResult(detailSearchResponse: DetailSearchResponse?) {
var site = detailSearchResponse?.site
site?.let {
Log.i("SITE_KIT", "Name => ${it.name}," +
"Format address => ${it.formatAddress}, " +
"Coordinate => ${it.location.lat} - ${it.location.lng}, " +
"Phone => ${it.poi.phone}, " +
"Photo URLS => ${it.poi.photoUrls}, " +
"Rating => ${it.poi.rating}, " +
"Address Detail => ${it.address.thoroughfare}, ${it.address.subLocality}, " +
"${it.address.locality}, ${it.address.adminArea}, ${it.address.country}")
} ?: kotlin.run {
Log.e("SITE_KIT","Site Place couldn't find with the given site ID")
}
}
})
}
First, we need to create a SearchService object from the SearchServiceFactory class. For this, we can use the create() method of the SearchServiceFactory class. We need to declare two parameters in create() method.
The first of these parameters is context value. It is recommended that Context value should be in Activity type. Otherwise, when HMS Core(APK) needs to be updated, we can not receive any notification about it.
The second parameter is API Key value that we can access via AppGallery Connect. This value is generated automatically by AppGallery Connect when a new app is created. We need to encode API parameter as encodeURI.
After creating our SearchService object as I described above, we can create a DetailSearchRequest object. We will specify the necessary parameters on this object related to the place which we want want to get information.
After creating our DetailSearchRequest object, we can determine parameters for a place that we want to get information. Two parameters are specified here:
SiteId: There is a unique id value for each Site in Site Kit. This parameter is used to specify the id value of the place whose information is to be obtained.
Language: It is used to specify the language that search results have to be returned. If this parameter is not specified, language of the query field we have specified in the query field is accepted by default. In example code snippet in above, language of device has been added automatically in order to get a healthy result.
After entering the id value and language parameter of the place that we want to learn in detail, we can start learning the details. For this, we will use detailSearch() method of the SearchService object. This method takes two parameters.
For the first parameter, we must specify DetailSearchRequest object we have defined above.
For the second parameter, we have to implement SearchResultListener interface. Since this interface has a generic structure, we need to specify class belonging to the values to be returned. We can get the incoming values by specifying DetailSearchResponse object. Two methods should be override with this interface. onSearchError() method is executed if operation fails, and onSearchResult() method is executed if operations is successful. There is one value in DetailSearchResponse. This value is Site object that belongs to the id value. With the Site variable of DetailSearchResponse object, we can access information belong to place we have searched.
sujith.e said:
Hi,Why API key is required?
Click to expand...
Click to collapse
API key is a simple credential for accessing Huawei services. Your API key is creating automatically on the AppGallery Connect when you create an application, and then your app can use the key to call public APIs provided by Huawei.
When an app calls a public API provided by Huawei, we should give this information to API to help Huawei to identify our application.

Categories

Resources