I'm trying to start the preferences activity in the native messenger client from my application. in AOSP Mms.apk does not have an intent filter setup on that activity. Regardless I'm trying to find a work around to launch the user into that screen.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(ComponentName.unflattenFromString("com.android.mms/com.android.mms.ui.MessagingPreferenceActivity"));
intent.addCategory("android.intent.category.LAUNCHER");
try {
startActivity(intent);
} catch (Exception e) {
AppUtils.alertError(this, error);
}
I'm receiving
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.mms/.ui.MessagingPreferenceActivity } from ProcessRecord{406e2738 674:com.handmark.genericapp/10034} (pid=674, uid=10034) requires null
Any thoughts?
What you want is not possible. That activity is not exported (at least in the source code showing in Google Code Search), so you cannot start it, except by rewriting the app as part of your own custom firmware.
Also, bear in mind that this app may or may not exist on any given device.
Related
I'm trying to launch an external shortcut, What i have is only the activity path .
Here's what i did :
try {
view.getContext().startActivity(Intent.getIntentOld(List.getShortcutPath());
} catch (URISyntaxException e) {
e.printStackTrace();
}
Log :
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=com.sonyericsson.music.ArtistShortcutActivity }
The Path I'm trying to launch :
com.sonyericsson.music.ArtistShortcutActivity
How to launch the shortcut ?
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity"));
startActivity(intent);
if you get permission denial error, then add android:exported XML attribute is true in the manifest for the activity you want to launch
Here com.example is the package name of the app your activity that you want to launch is in, and com.example.myexampleactivity the full name of the activity you want to launch
If the intended activity to launch is package private, then you wont be able to launch it from a foreign application activity. This is done for security reasons by Google
I am trying to call VoiceListActivity of VoiceRecorder from my app on samsung S4 but I get following error
08-27 09:35:03.401: E/AndroidRuntime(17313): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.RUN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.sec.android.app.voicerecorder/.VoiceListActivity } from ProcessRecord{449e11c8 17313:com.example.ui_sha/u0a205} (pid=17313, uid=10205) not exported from uid 10193
my code :
Intent intent = new Intent(Intent.ACTION_RUN);
intent.setComponent(ComponentName.unflattenFromString("com.sec.android.app.voicerecorder/com.sec.android.app.voicerecorder.VoiceListActivity"));
intent.addCategory("android.intent.category.LAUNCHER");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
So my question is :
Can i use Intent to call VoiceListActivity from my app? If yes, How I have to do ?
If no, can you show me another way to call it ?
Solution :
I asked some body to solve this problem but it is impossible when code in VoiceList's manifest have android:exported = true. So the only solution is you need to build your own VoiceListActivity and its screen. It could be take some time but it is only solution.
I am trying to open the Google Voice Search Application
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage("com.google.android.voicesearch");
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
}
This does not launch the voice search application,
however if I use com.google.android.apps.maps as the package name then the Google Maps app is opened.
I don't understand why Voice Search is not opening, even though the package name is correct.
Solution
Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
startActivity(intent);
Please see
Launch Preinstalled App from activity (Google Voice Search) Android for more information on the solution.
Thank you.
As you can read here, getLaunchIntentForPackage (String packageName)
Return a "good" intent to launch a front-door activity in a package [...]
The current implementation will look first
for a main activity in the category CATEGORY_INFO, next for a main
activity in the category CATEGORY_LAUNCHER, or return null if neither
are found.
so, in the intent, the category will already be set. If you manually change it, probably you are breaking the intent, since the category could not be the correct one that the manager found.
so, just remove the line
i.addCategory(Intent.CATEGORY_LAUNCHER);
In my Android application, I use the following code to start the messaging app and fill in a default text for a text message:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("sms:"+USERS_PHONE_NUMBER));
intent.putExtra("sms_body", "DUMMY TEXT");
startActivity(intent);
This works in most cases. But unfortunately, on some devices I get the following error message:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=sms:+XXXXXXXXXX (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1510)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
at android.app.Activity.startActivityForResult(Activity.java:3131)
at android.app.Activity.startActivity(Activity.java:3237)
Obviously, the intent that I created cannot be handled.
Is there any mistake in my SMS intent code?
How can I prevent the application from crashing if the intent cannot be handled?
Should I use PackageManager.queryIntentActivities() or is there another way of solving this problem?
Thanks in advance!
I haven't tried this intent specifically, but the simplest way will probably be to add try and catch block
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Display some sort of error message here.
}
Since you can't count on the specific Android device to have the Messaging app (some tablets for example don't have telephony services), you have to be ready.
It is a good practice in general when you're starting external activities, to avoid crashes in your app.
Here is the code that will open the SMS activity pre-populated with the phone number to
which the SMS has to be sent. This works fine on emulator as well as the device.
Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.setData(Uri.parse("sms:" + phoneNumber);
Here is a method I use to safely open activities on Android, and give the user some feedback if the activity is not found.
public static void safeOpenActivityIntent(Context context, Intent activityIntent) {
// Verify that the intent will resolve to an activity
if (activityIntent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(activityIntent);
} else {
Toast.makeText(context, "app not available", Toast.LENGTH_LONG).show();
}
}
(I think I got it from one of the Google Developers videos on youtube, but now I can't find the video...)
I have a strange problem, I am wanting to launch to the marketplace from my app - am doing the following.
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"market://details?id=" + activity.getPackageName()));
try {
activity.startActivity(marketIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(activity, "Could not launch market", Toast.LENGTH_LONG).show();
}
However when there the user can press Open again, when they do that I get :
08-22 15:18:37.510: INFO/ActivityManager(260): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.xyz.appname cmp=com.xyz.appname/.mainapp } from pid 22853
08-22 15:18:37.590: INFO/ActivityManager(260): Starting: Intent { cmp=com.xyz.appname/.secondactivity } from pid 25735
08-22 15:18:37.590: WARN/InputManagerService(260): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#2b49a938
and it never reopens the app , they just stuck there - hitting back does work.
Tracing the code the warning is coming from this in mainapp :
Intent tabActivity = new Intent();
tabActivity.setClass(this, secondactivity.class);
startActivity(tabActivity);
this.finish();
This definitely looks like an issue with how it is restarted - you're on the right track with that last bit of code.
This flag looks like what you need to tell Android to pull the existing activity off of the history stack and re-use it:
FLAG_ACTIVITY_SINGLE_TOP
Alternatively (if you want to restart rather than resume), maybe you could hint to Android to recycle the activity after you move on, by using this with your intent:
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);