Android service not showing logs? - android

I am a bit confused,
it seems that my Service does not print logs,
the service starts regularly (I can debug it), I see all other logs,
but from the service no logs.
Please what am I missing here?
#Override
protected void onHandleIntent(Intent intent) {
Log.e("TAG","Downlaoding devices list");//This should log something!

Chances are your IntentService is not getting called. try using the whole package name of the IntentService. I've seen this somewhere I'll post a link if I find it.
Something like this...
Intent intent = new Intent(this/*Context*/,com.myapp.MyIntentService.class);
//as opposed to
// new Intent(this, MyIntentService.class);
startService(intent);
Edit: I found the link. intentService : why my onHandleIntent is never called?

In Android Studio Logcat.
Before running your code,
1) Select No Filters instead of Show selected applications
2) In the search box, type in your tag.
3) Now Run your code and all your logs will be displayed.
Note: It won't work if you enter your tag after running your code.

My solution was selecting "No filters" in logcat spinner instead of "Show only selected application". Then you can search for TAG or whatever you know it should be shown.

In my case which is Himax M2 Y12 phone, has a peculiarity in that my TAG SensorService is blocked for unknown reason.
I changed the TAG to GeoSensorService and now the logcat is showing.
My guess is they reserve the TAG for internal purposes, but I'd argue they shouldn't use such an innocent naming (they could've prefixed reserved TAGs with __ or something).

Related

ActivityNotFoundException for class extends BroadcastReceiver

My end objective is to learn data flow in contactless card transactions from beginning to end for the reason I am making an android application which will accept contactless cards.
In the first screen I have a text box for entering amount and a button to accept it, which will take it to the next screen.
In the next screen I have a button which displays the amount and a button(Tap) which
should start the broadcast listener( for testing sake I am trying to capture broadcast for AIRPLANE_MODE).
Now my issue is that whenever I press the Tap button, application says - unfortunately app has stopped.
In the debug I can see -
Caused by: android.content.ActivityNotFoundException: Unable to find
explicit activity class
{com.example.myfirstapp/com.example.myfirstapp.AskToTapCard}; have you
declared this activity in your AndroidManifest.xml? .
But the class AskToTapCard extends from BroadcardListener. What I am expecting at this point is the application to wait and I will switch to airlane mode and app to detect it and log.
I made changes to make it extent from AppCompatActivity and show a dummy page, it shows. How to fix this ? In is a complete in house project and I can provide any source file, just let me know which one I need to. Below image may help you access the size of my project.
The error says: ActivityNotFoundException but AskToTapCard is not an Activity, it's a BroadcastReceiver.
So even thou you didn't show your code (and you should, it's one possible reason ppl is downvoting you), I can only assume you have something like this:
Intent intent = new Intent(context, AskToTapCard.class);
context.startActivity(intent);
Which is exactly what the error is telling you. That you're telling the system to run an activity, but you give to the system a BroadcastReceiver. Once understanding the error the solution is simple:
Intent intent = new Intent(context, AskToTapCard.class);
context.sendBroadcast(intent);

Java/Android: passing Intent extras from BroadcastReceiver to Activity

Update: Neither eclipse nor the code did cause these trouble. Genymotion did.
Maybe my approach is completely wrong, since no one else seems to have this problem - if so, i am open to try different ways rather then fix this problem:
I have the following setting.
A BroadcastReceiver is listening for installations of Apps. Whenever a new App is installed, I create a Notification, using a PendingIntent that is based on a normal Intent via
PendingIntent pIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Before the PendingIntent is created, I put some extras in the normal Intent, that shall be passed to the Activity which is triggered, when the notification is clicked.
notificationIntent.putExtra("AppLabel", appLabel); // the installed App
notificationIntent.putStringArrayListExtra("Group", group); // the corresponding group
notificationIntent.putStringArrayListExtra("List", list); // the corresponding list
Now this works fine and the notification is displayed. Debugging I can see, that when pIntent is created, all extras are set correctly and passed.
However, when I try to read the extras in the opened Activity trouble starts. I already had to build a workaround, based on an answer here, to read the extras:
Bundle bundle = getIntent().getExtras();
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
if (key.equals("Group")) {
group = (ArrayList<String>) value;
} ... }
This also worked for a time, but now i am completely lost. For some Reason, the ArrayList extras are empty [] - the appLabel is still set correctly.
Now the real trouble is, that I am not sure if this is code related, or an eclipse issue.
I observed, that after some deployments, the bundle.keySet() returned different keys then I had set in the putExtra call. I also encounter OutOfSync errors often when I search. Refreshing does help some times, regarding the names of the keys, but the values are lost still.
To anyone who has read this: many thanks! now - has somebody a clue, what is going on here? Does anyone know similar eclipse problems? Or is there an error in the code?
Any proposals for a different design are welcome as well. I'd be just glad, if I can exclude some error sources...
Thanks in advance
Update: Manifest Infos: The launched notification Activity is defined like:
<activity
android:theme="#style/Theme.AppCompat.CompactMenu.Dialog"
android:label="Notification Receiver"
android:excludeFromRecents="true">
</activity>
The MainActivity however has just a name and a label. Besides:
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="19" />
I just added a SystemOut at two points: One when the intent is created by the BCR, one when it is read by the Activity.
BroadcastReceiver.getExtras.keyset returns [a,b,c,d]
Activity.getExtras.keyset returns the keys [x,y,z]
Searching in all Projects and all Workspace, x,y,z are nowhere to be found... They were used in a previous version of some days ago, so it seems eclipse stored some invalid old data?
Well, looks like all the technical stuff and all the outOfSync was nasty, but in the end not relevant.
It just covered a very trivial mistake. The answere can be found here:
Incorrect extras received with all intents but the first one
At least for the current implementation, this looks like solving the problems - except for the sync issues of course but that has not occured again.

Android Device Admin dialogue not showing up - Auto declined

I'm trying to implement locking the screen with my app.
I've worked my way through google documentation and studied the sample.
When i call this
void getAdmin(){
Intent activateDeviceAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
activateDeviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mPolicy.getPolicyAdmin());
activateDeviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
getResources().getString(R.string.AdminReceiverDescr));
startActivityForResult(activateDeviceAdminIntent, REQ_ACTIVATE_DEVICE_ADMIN);
}
The dialogue doesn't show up (maybe it flashes a little, can't say for sure), it just jumps in my onResult routine and result is "not granted". But my app afterwards shows up in the list in settings/security/device admins and if i enable admin rights manually it locks my screen like a charm.
I've added the permission
uses-permission android:name="android.permission.BIND_DEVICE_ADMIN"
as well as
receiver ... android:permission="android.permission.BIND_DEVICE_ADMIN"
to my manifest.
Does anyone have a clue what i may have missed?
Thx in advance!
Found the problem in my manifest: you have to specify the receiver subclass with a $ sign.
Example:
android:name="com.exampl.PolicyClass$PolicyReceiver"

android IntentService what can be wrong when intent is empty?

hi
After creating intents for month now i suddenly
hit the wall when in my Notification PendingIntent, i did this:
Intent intent = new Intent(getApplicationContext(), SendFileService.class);
intent.putExtra("uuid", "123-456-34");
The SendFileService is an IntentService.
To my surprise in the IntentService onHandleIntent the extras.getString("uuid");
was null.
what can possible be the reason .
I even added an action to test but still the same.
Im clearly did something wrong or missing some knowledge about this.
Any ide?
From the docs
The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

Launching external application from my app

I would like to launch an app the user selects from within my application. However, I'm not sure how I'd go about doing this. I've tried this:
Intent intent = new Intent();
intent.setAction(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
startActivity(intent);
But this seems to throw an error and force close my application. I also tried adding:
<action android:name="Contacts.Intents.SHOW_OR_CREATE_CONTACT"/>
in the AndroidManifest file, but to no avail.
A look at Logcat shows that it's an "IOexception - no such file or directory". A couple of questions arise from this. I read through the Android docs and noticed that the Contact.Intents class is deprecated. However, it's successor, ContactContracts is aimed at API level 5 whereas I'm targeting API level 3. Could this be the problem? Also, I've hardcoded this application into the code. Is there a way to retrieve the intents of any application the user selects so that they can be launched?
You need to pass extra information into the intent to tell Android what you want to show or create. Otherwise Android doesn't know what activity to start and (presumably in your case) throws an ActivityNotFoundException.
For a contact, you use the generic Intent.ACTION_INSERT_OR_EDIT then use the MIME type of an individual contact (Contacts.People.CONTENT_ITEM_TYPE).
For example:
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(People.CONTENT_ITEM_TYPE);
intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");
intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE, Contacts.PhonesColumns.TYPE_MOBILE);
That will bring up the contacts app, prompting you to select an existing contact to add the phone number to, or to create a new contact.
You don't need to add anything special to your manifest to start external activities. Only if you were to directly manipulate the contacts ContentProvider would you need to add the appropriate CONTACT permissions to your manifest.
I use this code for that purpose:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.Settings");
startActivity(intent);
This will launch the Settings app, you can use these also:
intent.setClassName("com.android.music", "com.android.music.MediaPlaybackActivityStarter");
intent.setClassName("com.android.contacts", "com.android.contacts.DialtactsContactsEntryActivity");
intent.setClassName("com.android.contacts", "com.android.contacts.DialtactsActivity");
The first starts the default music app, the second the contacts, and the third the dialer.
Hope this helps.
You need to pass in valid arguments to the apps you start. A lot of apps expect the data URI and / or certain extras to be valid.
Please try the following code:
Intent intent = new Intent(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
this.startActivity(intent);
(sorry if there is something wrong on the syntax, I dont have android in this computer)
And remove the action from the manifest. that is not needed.
The action method is used for something else.
For more info, please look at the android site: http://developer.android.com/reference/android/content/Intent.html
Daniel
The activity you are calling should appear not only in the Manifest for its own package, but in the Manifest for the CALLING package, too.

Categories

Resources