I'm trying get some licensing code from AndroidPit.com working, but I get "Unable to start service Intent". Basically my code looks like this:
Intent licenseIntent = new Intent("de.androidpit.app.services.ILicenseService");
if (mContext.bindService(licenseIntent, this, Context.BIND_AUTO_CREATE))
{
// success
}
else
{
// failure (I get this all the time(
}
I tried passing ILicenseService class explicitly:
Intent licenseIntent = new Intent(mContext, de.androidpit.app.services.ILicenseService.class);
but I still get the same problem.
I managed to get Android Market LVL library working which uses identical code, so I don't really understand why it fails to find "de.androidpit.app.services.ILicenseService", but manages to find "com.android.vending.licensing.ILicensingService".
Most of the answers I found here say that you need to append stuff to your AndroidManifest.xml, but you don't anything for "com.android.vending.licensing.ILicensingService" to work, so I guess I shouldn't need anything "de.androidpit.app.services.ILicenseService" (they both derive from android.os.IInterface).
Thanks in advance.
Most of the answers I found here say that you need to append stuff to your AndroidManifest.xml
Those answers are correct.
but you don't anything for "com.android.vending.licensing.ILicensingService" to work
That is because com.android.vending.licensing.ILicensingService is a remote service, one that is not in your project, but rather in the firmware of the device.
so I guess I shouldn't need anything "de.androidpit.app.services.ILicenseService" (they both derive from android.os.IInterface).
That is flawed reasoning. By your argument, java.util.HashMap does not go in the manifest, and both java.util.HashMap and any implementation of Activity all derive from Object, so therefore you do not need to put your activities in the manifest. If you try this, you will quickly discover that your activities no longer work.
If it is a component (activity, service, content provider, or some implementations of BroadcastReceiver), and the implementation of the component is in your project (directly, via a JAR, via a library project, etc.), you must have an entry in the manifest for it.
Wherever you got the service from should provide you with instructions for adding the service to your manifest, and they should also supply you with instructions for creating the Intent used to bind to it. If they do not provide this documentation, perhaps you should reconsider your use of this product.
The solution in my case was to start a server part on my phone (AppCenter from AndroidPit.com in this case). No entries in AndroidManifest are necessary for the client application.
Related
When using the console of AndroidStudio on my app it shows:
W/System: A resource failed to call release.
Sometimes it is said multiple times. I know what it means but I've checked the almost 2k lines of code multiple times but I'm clueless what I'm missing to close/release.
Is there any way to expand on this information from the console? or how would you do to target what the resource is or when it fails to close? Any ideas are welcome. Thanks.
The answer from #guest works, but you can achieve the exact same thing without resorting to reflection using Strict Mode. Specifically, something like:
StrictMode.setVmPolicy(new VmPolicy.Builder()
.detectLeakedClosableObjects()
.penaltyLog()
.build());
In general, strict mode can do much more for you though (see link above to doc), and all you need to do for a default setup is:
StrictMode.enableDefaults(); # <-- This includes warning on leaked closeables
To enable strict mode "as soon as possible" you can add either of the above code options to the constructor of your application class, e.g.:
public class MyApp extends Application {
public MyApp() {
if(BuildConfig.DEBUG)
StrictMode.enableDefaults();
}
}
Note that in addition to just creating the class above, you need to tell Android that you have created a custom application class in the AndroidManifest.xml (so that an instance of it gets created when your application process starts, instead of Android creating the default Application class). You need to add/modify the android:name attribute of the <application> tag to point to the fully resolved package path of your custom application class (MyApp in this case):
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:name="com.example.app.MyApp" <-- IMPORTANT PART: ADAPT FOR YOUR ACTUAL PROJECT
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
This message comes from dalvik.system.CloseGuard. When debugging, you can set it up to create stack traces as you create resources, so that you can track down what objects aren't being closed.
It's not part of the framework API, so I'm using reflection to turn that on:
try {
Class.forName("dalvik.system.CloseGuard")
.getMethod("setEnabled", boolean.class)
.invoke(null, true);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
more info: https://wh0.github.io/2020/08/12/closeguard.html
I don't think that you can get any more information out of Logcat.
The memory view of the Android Profiler is probably a good place to start. Looking at it while using your app should give you an idea of what actions cause memory to be allocated and not released.
You can also select sections from the timeline and drill down to specific allocations by
class.
Alternatively LeakCanary is a great library to detect memory leaks.
Fixed it by removing a function call that called itself through another function thereby making an infinite loop of calls to itself
Late answer, but it may be useful to someone else:
I faced the same error, but I forgot I had my VPN running in the background. Disconnecting the VPN did the trick for me.
This is to say it may be due to resources unrelated to your app or IDE you may want to check, like an antivirus, VPN, etc.
I want to start the search Activity in shazam. According to this there is no search Activity to shazam, only a <provider> tag.
<provider android:name="com.shazam.android.SearchProvider" android:authorities="shazamSearchEncore" android:syncable="false" />
I tried to launch it in various ways but because this is not an Activity it failed. So how do I start shazam search? Or am i missing something in that manifest xml file?
My tries:
1:
Intent intent = new Intent("com.shazam.android.SearchProvider");
intent.putExtra("query",query);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.context.startActivity(intent);
2:
final Intent shazamIntent = new Intent(Intent.ACTION_SEARCH);
shazamIntent.setPackage("com.shazam.android.SearchProvider");
shazamIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.context.startActivity(shazamIntent );
And so on...
Also I checked these post post 1 and post 2. But found nothing helpful.
A ContentProvider can't be "launched" by intents like an Activity.
A provider is a component, designed for providing an interface to some data. The data can be accessed by a ContentResolver.
Some ContentProviders also allow access from other apps. This is usually documented somewhere, providing the URL that is needed to access the data and details about the data itself. Such an example is the Contacts provider, used to access all the contact information stored on the device.
Judging by the look of the manifest declaration of the provided that you are trying to access, I think it can only be accessed by the Shazam applications itself, so there is no way to access the data it provides.
I'm hosting widgets in my app. They can be picked from a list of all installed widgets and are added to a view. I save their IDs to database and restore them from these saved IDs again after restart of the app.
This works most of the times, but not always. Widgets are not always updated properly. One scenario where that happens for sure is:
"rebooting phone and starting app before boot-process of device has finished."
(if i wait until booting is completed, it works!!!)
There must be another scenario, but i couldnt reproduce that. I restart my app and they are not updated. So i wonder if i am missing something important.
I have basically used this tutorial:
http://leonardofischer.com/hosting-android-widgets-my-appwidgethost-tutorial/#comment-14678
My Code:
onCreate:
mAppWidgetManager = AppWidgetManager.getInstance(this);
mAWH_AppWidgetHost = new MyAppWidgetHost(MyApp.getContext(), R.string.APPWIDGET_HOST_ID);
onStart:
mAWH_AppWidgetHost.startListening();
onStop:
mAWH_AppWidgetHost.stopListening();
restore from id (saved in database):
AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
MyAppWidgetHostView hostView = (MyAppWidgetHostView) mAWH_AppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
hostView.setAppWidget(appWidgetId, appWidgetInfo);
mLL_innerLayout.addView((MyAppWidgetHostView) hostView);
I cannot find any sites in the web that make this clear. Neither does looking at source code of different launcher apps make it more clear to me.
I had the same problem, but then I moved
mAWH_AppWidgetHost.startListening();
in onCreate method and
mAWH_AppWidgetHost.stopListening();
in onDestroy method. This is suggested here
I need some advice for this matter...
I used the facebook android sdk to create an integration with facebook from my application...I followed this tutorial:
http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/
I would need to implement authentication in one activity and the function postToWall in another.... after authentication i want to send post simply by pressing a button but in other activity, different from that where i do authentication.
is it possible? or with the SDK I'm forced to do everything together in the same activity?
thanks in advance
Yes it is possible. You will get a access token which you can send to the next activity. Use getAccessToken() and setAccessToken().
Here is an example that even saves the needed data: Contact-Picture-Sync
you need to install an extension, similar to the core Android SDK, but no, here is what you need to do:
1.) go to github.com/facebook/facebook-android-sdk
2.) download the facebook directory ONLY! The other directories are only examples.
3.) Put the files from the src (you can copy the drawables too, if you want to) in the package, you are currently working with
4.) You are good to go, you can use the facebook "SDK"
see also this example https://github.com/facebook/facebook-android-sdk/tree/master/examples/Hackbook download it , it is working example provided by facebook
just to provide an alternative answer, there's other ways of implementing sharing on Android.
It allows for more sharing options (like Twitter, QR-Barcodes, blogging and whatnot) without having to deal with the facebook android sdk.
What you would use is a "share" intent, like so:
String title = "My thing"; // used if you share through email or channels that require a headline for the content, always include this or some apps might not parse the content right
String wallPost = "Hey - check out this stuff: http://link.com "; // the content of your wallpost
String shareVia = "Share this stuff via"; // the headline for your chooser, where the phones avaliable sharing mechanisms are offered.
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, wallPost);
startActivity(Intent.createChooser(shareIntent, shareVia));
This is by far the preferred solution on Android if you're looking for simple sharing, as it makes your app future-compatible with new services. And more lean and flexible for the user too, as there's little to no friction from hitting the share button to posting content.
It can also be seen in this blog post: http://android-developers.blogspot.com/2012/02/share-with-intents.html
I hope you can use this for your project.
I'm having some problems here with basic Activity starting
I've tried to use the method below:
private void startAC() {
Intent i = new Intent(this, WordSendingActivity.class);
startActivity(i);
}
And while debugging I got some "Source not found" errors which claim that the source attachment does not contain the source for the file: Instrumentation.class, InvocationTargetException.class, Binder.class (in this order)
I got these different class names by trying Run->Step Return
What am I doing wrong here? I just want to preform a basic activity start, how would you do it better?
took me hours to give up my pride and come here :)
I hope my question is clear enough...
It looks like you might be attempting to "Step Return" into built-in classes. Android classes don't have sources available for debugging. They are binary-only classes in the respective android.jar.
The code for starting the activity looks fine. Are you sure you added WordSendingActivity to the AndroidManifest.xml ?