android IntentService what can be wrong when intent is empty? - android

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".

Related

explanation about intent.getStringExtra and intent.putExtra in android studio

I kinda new about using android studio and my teacher asked me to learn about how to use intent.getStringExtra and intent.putExtra.
please help to explain me about those two things.
thanks!
In general, intents are used to move between some android component like (activity, service, broadcast receivers ...etc) some time you need to pass some value between these components so you need to use put extra in the sender component and get extra in the receiver for example :
in the sender :
Intent intent = new Intent(SenderActrivtiy.this, REciverActivity.class);
intent.putExtra("emailKey", "mm#email.com");
startActivity(intent);
in the reciver:
String email =getIntent().getStringExtra("emailKey");
note that you need to pass the same key to retrieve your value

Android service not showing logs?

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).

Which function does intent have? [duplicate]

This question already has answers here:
What is an Intent in Android?
(14 answers)
Closed 8 years ago.
I dont know much about intent (or android) so.. Can someone please explain me what is it exactly? i have search on the internet, A LOT.
Also what does each line of this code do?
Intent intent = new Intent (this, DisplayMessageActivity.class);
intent.putExtra("a", "b");
Thanks in advance
I suggest reading Android Intents
You couldn't have search for very long, since this is very basic topic.
I suggest you read more of Android's API guides.
Line 1 = Create message that describes what to do, in this case start "DisplayMessagActivity"
Line 2 = Add content to the message
Intent intent = new Intent (this, DisplayMessageActivity.class);
For this line, its function is to create a navigation from the current activity/page to the displaymessageactivity page.
it is like from here to there.
For this intent.putExtra("a", "b"); the purpose of this is to put like a temp storage/variable to pass to the next page for retrieval. In this case, you put the value "b" in the variable "a". With this method, you can use the value on the other activity or page.
All the above are just storing of info, it is not executed yet. if you want to execute the intent do the following
startActivity(intent);
The best example to state the behavior of Intent is it behaves like a POSTMAN that delivers message to the stated address.
Whether it may be calling service ,BroadCastRecivers ,Activity they are used in number of occassion.
Intents are asynchronous messages which allow application components
to request functionality from other Android components. Intents allow
you to interact with components from the same applications as well as
with components contributed by other applications. For example, an
activity can start an external activity for taking a picture.
Intents are objects of the android.content.Intent type. Your code can
send them to the Android system defining the components you are
targeting. For example, via the startActivity() method you can define
that the intent should be used to start an activity.
An intent can contain data via a Bundle. This data can be used by the
receiving component.
Intents can be used to start Service, call Activty, call Sub Activity, transfer the data between Activity or retrieve the data from Activity

Open my application from another in android

My boss asked me to prove that my application behaves properly when summoned by another application (dunno why he asked that).
So I have two apps here, one launches a second one. How I launch the specific app I want? Using Intent launch seemly any generic app that reaches a certain goal, not the app I really want.
Give this a try.
Intent secondIntent = new Intent();
secondIntent.setAction(Intent.ACTION_MAIN);
secondIntent.setClassName("com.example", "com.example.YourSecondApp");
startActivity(secondIntent);
I should point out that com.example should be the package of your second application (the one you want to call) and com.example.YourSecondapp is the class name where you have your onCreate() method.
Intent secondApp = new Intent("com.test.SecondApp");
startActivity(secondApp);
Check out for more examples
http://developer.android.com/resources/faq/commontasks.html#opennewscreen
Create one Intent using the following code
Explicit Intent
When you know the particular component(activity/service) to be loaded
Intent intent = new Intent();
intent.setClass("className/package name");
start<Activity/Service>(intent);
Imlicit Intent
When we do not have the idea which class to load and we know the Action to be perform by the launched application we can go with this intent.
Action needs to set, and the Android run time fallows the intent Resolution technique and list out(one or more components) the components to perform the action. from the list out components (if more than one), user will get the chance to launch his chosen application

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