I have written an Application, which checks when you receive a new SMS and if its from a certain number, the app plays the ringtone. Now, the App should check if there is a new SMS even if it isn´t lauchned, and so my question is: How can I launch my App by receiving a new SMS?
I tryed to upload my existing code but it didn´t worked, I am sorry.
To start an activity from almost everywhere you can simply call:
Intent myIntent = new Intent(CurrentActivity.this, NewActivity.class);
CurrentActivity.this.startActivity(myIntent);
That should also work from your BroadcastReceiver which is triggered while receiving the sms.
Related
I'm trying to manage phone calls on my app.
I have managed to find this code which starts a phone call
Intent i = new Intent(Intent.ACTION_CALL);
i.setData(Uri.parse("tel:"+et.getText().toString()));
startActivity(i);
but no luck in finding how to reject / end a call.
something like a button on my app which will end the current if there is one.
Thanks so much in advance!
I am developing a video player app and I want my app to Prompt for the permission to be the default Video Player to be the default handler of video play.
I know it has to be something like the default handler:
Intent setSmsAppIntent =
new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
setSmsAppIntent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
getPackageName());
startActivityForResult(setSmsAppIntent, your-result-code);`
source: Android Docs
But I don't know the Action I have to give to the Intent as action. Can someone please help me?
Thanks in advance.
It's not possible, developers can't call intent to change default Video player only users can do that on their device. Its only possible for SMS service.
However, for video player you can register app for video player in AndroidManifest.xml and call the function which opens settings to change default apps using the following code:
Intent intent = new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
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