I can't find anything on this on google, nor here? But I am trying to create a notification and retrieve the value of an EditText field that has been set as a custom view for the notification
Is there anyway to retrieve this value? As notification's (as far as I'm aware) can just be set and/or updated.. but there must be some way!
That's not possible. The actual EditText view inside your notification is not even owned by your process - it's instantiated by the system using the RemoteViews object you are providing. The only way of communicating with it is by sending back predefined intents, for example via setOnClickPendingIntent. You cannot retrieve a content of EditText that way, though.
As a solution I'd recommend to display a dialog or activity with your EditText when user taps the notification, and handle their input there.
In your notification Intent
Intent notificationIntent = new Intent(this, FlightActivity.class);
Bundle bundle = new Bundle();
bundle.putString("whatever",YOUR_STRING_VALUE);
notificationIntent.putExtras(bundle);
When the application starts, you can get it using the intent
Is this what you want?
Related
I'm having a slightly different purpose, but, I think I'm putting it wrong as no one from multiple forums is able to answer it. The original question is here: Pass URL data from AppLink to WebView
Basically, suppose I'm creating a web browser app with a splash screen and I want to accept the URL intents from other apps, receive them in my splash screen, pass them on to my WebView activity and load it there, how can I do that?
For example, if a user has my app installed, and he/she taps https://www.google.com/ as a link in some app, how can I load the URL in my app after showing my splash screen? I think, the intent receiver will be in the splash screen activity, and the WebView is in another activity. So, basically, I want to receive the URL in my splash screen activity and then, pass it on to my WebView. How to achieve this?
I think what youre trying to do is to recieve data from other apps
That way, you can recieve data in a Splash Screen Activity and then show it in a Web View Activity
You can do this through putExtra method.
You can use intents, which are messages sent between activities. In an intent you can put all sort of data, String, int, etc.
In your case, in Splash Screen(say SplashActivity), before going to next activity(say MainActivity), you need to store a String message this way :
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
intent.putExtra("message", message);
startActivity(intent);
In MainActivity, in onCreate(), you can get the String message by retrieving a Bundle (which contains all the messages sent by the calling activity) and call getString() on it :
Bundle bundle = getIntent().getExtras();
String message = bundle.getString("message");
Then you can use message variable as url.:
Hope this helps !
I have a class that listens to SMS broadcast and, it then open an activity in the same application to display the message. This is part of a larger project.
Since the broadcast class does not extend the activity class, calling an Activity with intent requires that I flag it with Intent.FLAG_ACTIVITY_NEW_TASK.
Now the Intent has an extra (the SMS message and some parameters as a single string) which i want to send with the intent. All went well but the Extras are not sent with the intent.
Here are my code
From the broadcast class
//After getting the message into String S and doing some process
Intent inte = new Intent(context.getApplicationContext(), StartApp.class);
inte.putExtra("messageAsString", S.toString()); //Where S is declared somewhere
inte.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(inte);
From the activity recieving the Intent in the onCreate() method
if(getIntent().hasExtra("messageAsString")) {
String message = getIntent().getStringExtra("messageAsString").toString();
Toast toast = Toast.makeText(this, "Received SMS: " + message , Toast.LENGTH_LONG);
toast.show();
}
The application may have already running, the home button has been pressed. Either way, what I want to achieve is that as the registered reciever receives the message, I want to start an activity automatically and pass the message and its meta data to it.
I know I'm missing something somewhere but will appreciate your swift help
You also need to handle onNewIntent(), which may be called if the activity already exists and startActivity() brings an existing instance back to the foreground. Your extra is probably in there.
I have an Android app with a working push notification set up. It works currently like this:
User gets a push notification
When the user taps on the push notification, he is taken to a screen which has the list of all the notifications. It is basically a list view which has all the notifications.
Now, want to implement the following:
a. When a new notification comes to the user, it has to be displayed on the list view, irrespective of whether a user taps on it.
b. I have to indicate the number of notifications that user has received on the app icon. For instance, if you get a message in whats app, it displays the number of messages on the app icon.
Could anybody let me know what is the best possible way to implement these functionality? If anybody could point me to tutorials/references, it would be very helpful.
Thanks!
a. Launch an activity from the receiver(GCM/C2DM receiver) when the push notification arrives
// Your C2DM receiver (for GCM check the Android Documentation)
public void onReceive(final Context context, final Intent intent)
{
if (intent.getAction().equals(com.google.android.c2dm.intent.RECEIVE))
{
//start your list view activity of notifications
Intent i = new Intent();
i.setClassName("com.test", "com.test.NotificationsActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
b. Check this.
I have integrated the Zxing API and use this code:
Intent data = new Intent("com.google.zxing.client.android.SCAN");
And getting the result with this code:
String contents = data.getStringExtra("SCAN_RESULT");
String format = data.getStringExtra("SCAN_RESULT_FORMAT");
But when I run this code, the app will ask to force close.
When sending an Intent to startActivity(), you must always check if the user has any apps that can handle the intent:
Caution: It's possible that a user won't have any apps that handle the implicit intent you send to startActivity(). If that happens, the call will fail and your app will crash. To verify that an activity will receive the intent, call resolveActivity() on your Intent object. If the result is non-null, then there is at least one app that can handle the intent and it's safe to call startActivity(). If the result is null, you should not use the intent and, if possible, you should disable the feature that issues the intent.
Go through this. App is crashing because Zxing app is not installed in the mobile. I gave a detailed answer in the same link.
Here is the code snippet from our app now.
public void onClick(View v) {
// TODO Auto-generated method stub
Intent sms = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" ));
sms.putExtra("sms_body", text);
startActivity(sms);
}
This works with the stock SMS app, however a tester reported that with handcent SMS they get a blank message. This prompted me to try it with Google Voice, also get a blank message there.
Is there some way I can get my message text to work with all of these other SMS apps?
We have a clipboard functionality, so a poor workaround at least would be having user push clipboard button, then use their messaging app of choice.
Android tries to reuse Intents as much as possible. In some cases when you start an intent, android doesn't create a new Intent and reuse previous intents. To avoid this set this flag of Intent:
smsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
This flag forces Android to create a new Task with the intent's Activity on top of stack.
When you pass this intent , this will be delivered to all those apps which have registered an activity to receive it. In otherwords you have to use the intent that is registered by the application that u intent to handle your intent