OK, so I'm not sure how to explain this, but basically what I want to do is when a web/ URL request is passed in a android phone, I want to find out how to get the Intent of that request/action.
For example, when I do this:
MS.FUNCTION("android.content.Intent", new MS.FUNCTION() {
public void classLoaded(Class<?> content) {
Method **SOMETHING**;
try {
open = intent.getMethod("open", Integer.TYPE);
} catch (NoSuchMethodException d)
I want a method (in place of SOMETHING) that passes/uses an Intent when executed, so then I can get extra information. At this point, it is just for web/URL Intents
Thanks so much for any help, and sorry for the probable confusion. I would be glad to answer any other questions regarding clarification.
Also, I have been to the android Intent website, and I have not found what I am looking for. However, this could very easily just be my searching skills.
Related
public void executeApp(ExecuteABCDEvent event) {
PackageManager pm = this.getContext().getPackageManager();
try {
String packageName = "package name here";
Intent launchIntent = pm.getLaunchIntentForPackage(packageName);
this.getContext().startActivity(launchIntent);
} catch (Exception e1) {
Log.d("Exception", e1.getMessage());
}
}
I am opening a 3rd pary application using the above code.
Along with opening of this 3rd party application I also want to populate some text fields.
Solution 1: put and get data from intent.
I cannot user solution 1 as i cannot use the get methods in 3rd party app.
Solution 2: Content provider.I am not sure how content provider of application works and how it helps.
Is there another approach for this.
You have no good way of doing what you want. For obvious security reasons, apps cannot hack into other apps.
You are welcome to create an AccessibilityService and attempt to use that to achieve your ends. I am skeptical that it will work, and even if it does, I am skeptical that many people will install your app, given the large security warnings that are presented when the user goes in to activate your AccessibilityService.
Can someone please provide an example for a real case where I might need to use OnProvideAssistDataListener. I can't seem to wrap my head around it. I look at the source code, and then I look online. Someone online says
Application.OnProvideAssistDataListener allows to place into the
bundle anything you would like to appear in the
Intent.EXTRA_ASSIST_CONTEXT part of the assist Intent
I have also been reading through the Intent Docs.
There is an Now On Tap functionality implemented by Google. By long pressing the Home Button, you will get some information displayed on the screen. The information you get depends on what you're viewing on your screen at that time. (for eg: Music app displays information about music on the screen).
To provide additional information to the assistant, your app provides global application context by registering an app listener using registerOnProvideAssistDataListener() and supplies activity-specific information with activity callbacks by overriding onProvideAssistData() and onProvideAssistContent().
Now when the user activates the assistant, onProvideAssistData() is called to build a full ACTION_ASSIST Intent with all of the context of the current application represented as an instance of the AssistStructure. You can override this method to place anything you like into the bundle to appear in the EXTRA_ASSIST_CONTEXT part of the assist intent.
In the example below, a music app provides structured data to describe the music album that the user is currently viewing:
#Override
public void onProvideAssistContent(AssistContent assistContent) {
super.onProvideAssistContent(assistContent);
String structuredJson = new JSONObject()
.put("#type", "MusicRecording")
.put("#id", "https://example.com/music/recording")
.put("name", "Album Title")
.toString();
assistContent.setStructuredData(structuredJson);
}
For more info refer https://developer.android.com/training/articles/assistant.html
When I create a new Intent in an Activity:
Intent myIntent = new Intent(this, TargetActivity.class);
// apply hacks explained in above stackoverflow answers
System.out.println(myIntent.getExtras())
(this code lays in a default blank activity)
Intent#getExtras() is always null and thus Intent#putExtras(...) leads to immediate NullPointerException. Starting the Intent, however, works without any problems.
I've read all similar stackoverflow posts about this topic:
https://stackoverflow.com/a/6357330
https://stackoverflow.com/a/14288868
https://stackoverflow.com/a/16458878
https://stackoverflow.com/a/16377139
https://stackoverflow.com/a/13596581
https://stackoverflow.com/a/24047080
https://stackoverflow.com/a/3128271
I've tried them all, but none of them seems to have any effect.
Could anyone please provide a solution to simply start an Intent with non-null extras which always works?
Alternatively, is there any other way to provide extra information to an Intent which is clean and not leaky?
OK, I found the problem. Thank you #DanielNugent for pointing to the canonical answer to Intent handling.
The problem was: when I did
myIntent .putExtra("myVar", myVar);
myVar was null!
Stupid of me I didn't double check that and panic, put somehow stupid of Android that this does indeed lead to immediate NullPointerException! Please try it yourself if you don't believe me.
#njzk2: Thank you, I didn't realize that.
whenever we get a call, we do see missed call notification. Is there a way to remove the missed call notification in android programatically?
We see missed calls numbers & its count. Can we remove them via code?
The only "legal" but extremely ugly and usually useless way to achieve what you want is to show Call Log to user. And I mean literally show (becomes visual, gets focus). In case you want to do this, here's how:
public static boolean showCallLog(Context context)
{
try
{
Intent showCallLog = new Intent();
showCallLog.setAction(Intent.ACTION_VIEW);
showCallLog.setType(android.provider.CallLog.Calls.CONTENT_TYPE);
context.startActivity(showCallLog);
return true;
}
catch (Exception e)
{
Log.d("Couldn't show call log.", e.getMessage());
}
return false;
}
The reason behind this mess is the fact that apps authoritatively responsible for call logging and notifying users about missed calls (stock phone apps) use cached values. Why? Because of overall performance. You need to somehow notify those apps that Call Log has changed (seen means changed, as well) and that it should update it. It would be nice if all such apps on all devices would receive a broadcast in order to refresh, but as far as I know, it's not the case.
I hope someone will find a better way to force refresh on stock phone apps.
on Android phones, under Call -> Additional settings -> Caller ID
it is possible to hide your caller ID. I want to do that programatically from my code, but was not able to find a way to do that.
I searched through
android.provider
android.telephony
for 2.1 release and was not able to find it.
Has anybody successfully solved this issue?
Thanks in advance. Best regards.
Here I will describe two approaches I tried.
1.) It is possible to display Additional Call Settings screen from your application. Although it looks like it is part of the Settings application, that is not true. This Activity is part of the Native Phone Application, and it may be approached with the following intent:
Intent additionalCallSettingsIntent = new Intent("android.intent.action.MAIN");
ComponentName distantActivity = new ComponentName("com.android.phone", "com.android.phone.GsmUmtsAdditionalCallOptions");
additionalCallSettingsIntent.setComponent(distantActivity);
startActivity(additionalCallSettingsIntent);
Then user has to manually press on the CallerID preference and gets radio button with 3 options.
This was not actually what I wanted to achieve when I asked this question. I wanted to avoid step where user has to select any further options.
2.) When approach described under 1.) is executed in the Native Phone Application, function setOutgoingCallerIdDisplay() from com.android.internal.telephony.Phone has been used.
This was the basis for the next approach: use Java Reflection on this class and try to invoke the function with appropriate parameters:
try
{
Class <?> phoneFactoryClass = Class.forName("com.android.internal.telephony.PhoneFactory");
try
{
Method getDefaultPhoneMethod = phoneFactoryClass.getDeclaredMethod("getDefaultPhone");
Method makeDefaultPhoneMethod = phoneFactoryClass.getMethod("makeDefaultPhone" , Context.class);
try
{
makeDefaultPhoneMethod.invoke(null, this);
Object defaultPhone = getDefaultPhoneMethod.invoke(null);
Class <?> phoneInterface = Class.forName("com.android.internal.telephony.Phone");
Method getPhoneServiceMethod = phoneInterface.getMethod("setOutgoingCallerIdDisplay", int.class, Message.class);
getPhoneServiceMethod.invoke(defaultPhone, 1, null);
}
catch (InvocationTargetException ex)
{
ex.printStackTrace();
}
catch (IllegalAccessException ex)
{
ex.printStackTrace();
}
}
catch (NoSuchMethodException ex)
{
ex.printStackTrace();
}
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
Firstly I tried just to use getDefaultPhone(), but I get RuntimeException
"PhoneFactory.getDefaultPhone must be called from Looper thread"
Obviously, issue lies in the fact that I tried to call this method from the Message Loop that was not the Native Phone App one.
Tried to avoid this by making own default phone, but this was a security violation:
ERROR/AndroidRuntime(2338): java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.provider.Telephony.SPN_STRINGS_UPDATED from pid=2338, uid=10048
The only way to overcome (both of) this would be to sign your app with the same key as the core systems app, as described under
Run secure API calls as root, android
I'm not sure if this is a global feature, but Australian phones can hide their number by prefixing the caller's number with #31# or 1831. This may not be the perfect solution, but a prefix like this could possibly work for your requirements during coding.