Android: How to get the native Email clients package name - android

In Samsung devices com.sec.android.email is the default In-Built Mail client, but in HTC it is com.htc.android.mail.. My question is is there any way to get the default mail client package name in android device irrespective of the different company builds..

This isn't a complete answer, but here is how to get a list of Activities that can send message/rfc822:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
PackageManager pkgManager = context.getPackageManager();
List<ResolveInfo> activities = pkgManager.queryIntentActivities(intent, 0);
You can iterate over the list. See ResolveInfo documentation for fields of interest.

Related

Get package name from Intent

I am trying to get the package name of the default android clock (stock clock).
This is the intent I use to open the stock clock.
Intent i = new Intent(AlarmClock.ACTION_SHOW_ALARMS);
I have tried
i.getPackage();
But this returns null. Is there a way to get the package name of the default clock in android, in any phone?
But this returns null
That is because you have not set the package name in the Intent.
Is there a way to get the package name of the default clock in android, in any phone?
Not really, as there is no concept of a "default clock" in Android.
However, you can use PackageManager and queryIntentActivities() to see what activities will respond to the Intent that you have constructed.
Hope this will help you:
final PackageManager packageManager = this.getPackageManager();
Intent intent = new Intent(AlarmClock.ACTION_SHOW_ALARMS);
List<ResolveInfo> packages = packageManager.queryIntentActivities(intent,0);
for(ResolveInfo res : packages){
String package_name = res.activityInfo.packageName;
Log.w("Package Name: ",package_name);
}

Get browser bookmark uri knowing only package name

A can get all installed web browsers by using this code:
ArrayList<String> allLaunchers = new ArrayList<String>();
Intent allApps = new Intent(Intent.ACTION_MAIN);
List<ResolveInfo> allAppList = getPackageManager().queryIntentActivities(allApps, 0);
for(int i =0;i<allAppList.size();i++) allLaunchers.add(allAppList.get(i).activityInfo.packageName);
Intent myApps = new Intent(Intent.ACTION_VIEW);
myApps.setData(Uri.parse("http://www.google.es"));
List<ResolveInfo> myAppList = getPackageManager().queryIntentActivities(myApps, 0);
for(int i =0;i<myAppList.size();i++){
if(allLaunchers.contains(myAppList.get(i).activityInfo.packageName)){
Log.e("match",myAppList.get(i).activityInfo.packageName+"");
}
}
link: Android Fetch installed and default browser in device
Based on package name, is there a way to get BOOKMARKS URI for each browser?
When I got list of browsers, by package name (via above method), I need to get a link for it's bookmarks (browsing history) database, for example:
On Chrome, package name is com.android.chrome and history URI is content://com.android.chrome.browser/bookmarks, but this case is special one, when only .browser was added to real package name... in most cases it differs totally. Like in FF, where package name is org.mozilla.firefox, and history uri differs: content://org.mozilla.firefox.db.browser/bookmarks (yes, I know that It can't be read in FF), but was only an example.
So basically the question is: Is there a way, knowing this: org.mozilla.firefox, to get this: content://org.mozilla.firefox.db.browser/bookmarks.

how to hide apps from other user in android

i am trying to make launcher in android.i want admin to hide few apps from user.
i have done for admin-user log in. now i want admin to select some apps which should not be seen by user.
so that,when user log in he/she should see only those apps which are allowed by admin.
List<ResolveInfo> availableActivities = manager.queryIntentActivities(i, 0);
for(ResolveInfo ri:availableActivities){
AppDetail app = new AppDetail();
app.label = ri.loadLabel(manager);
app.name = ri.activityInfo.packageName;
app.icon = ri.activityInfo.loadIcon(manager);
apps.add(app);
}
i have got the list of apps..
kindly help.
Use PackageManager to get all the installed apps and then write the following code:
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, package_name); //package_name is the name of the application's package you want to hide
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
That should do it.
You can maintain application information i.e name,package name and icon in SQLite databse.
On the basis of selection , you can show applications to user.

How to get list of installed email programs on android

I'm writing an Android app that emails reports to the user. I've seen apps that launch a list of other installed apps that can be used to send email and I am wondering how to do that.
I've looked at this code and this question.
How would you filter out from the list of installed apps to know which ones are used for email?
You should be able use a similar pattern to the one shown in the answer in your second link. You just need to change the intent:
final Intent sendIntent = new Intent(Intent.ACTION_SEND, null);
final List<ResolveInfo> pkgAppsList
= context.getPackageManager().queryIntentActivities(sendIntent, 0);
You might try this code from this answer:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"xxxxxxxx#gmail.com"});
emailIntent.setType("plain/text");
startActivity(Intent.createChooser(emailIntent, "Send email..."));

how to get list of installed instant messenger apps?

My app should be able to send the text in a TextView via WhatsApp, Email, SMS etc. For that i need a list of installed Messging Applications. I tried it with the PackageManger but i get all apps. How can i get only the Instant Messaging Apps?
This is my code to list the installed apps:
PackageManager packageManager=this.getPackageManager();
List<PackageInfo> applist=packageManager.getInstalledPackages(0);
Iterator<PackageInfo> it=applist.iterator();
while(it.hasNext()){
PackageInfo pk=(PackageInfo)it.next();
if(PackageManager.PERMISSION_GRANTED==(packageManager.checkPermission(Manifest.permission.INTERNET, pk.packageName)& packageManager.checkPermission(Manifest.permission.RECEIVE_SMS, pk.packageName))) //checking if the package is having INTERNET permission
{
myList.add(""+pk.applicationInfo.loadLabel(packageManager));
}
}
Supposed you manage to get the list of the apps you want, then what are you going to do with them?
I think that you need to let android to present a list of apps to your users for them to choose which application they want to handle the text, depending on the action performed. Fortunately this is a build in feature in Android. Here is my function for sending e-mails:
public static void StartEmailIntent (Context cx, String EmailAddress){
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("plain/text");
email.putExtra(Intent.EXTRA_EMAIL, new String[]{EmailAddress});
cx.startActivity(Intent.createChooser(email, cx.getString(R.string.dlg_sendmail_selectortitle)));
}
As you can see I am setting Intent.ACTION_SEND as the action and then with the Intent.createChooser android creates a list of applications capable to handle that action based on the type and the extras of the Intent. It shouldn't be hard to adapt other actions like SMS, Phone calls etc. You can read more about it here Sending Content to Other Apps
Hope this helps...
If you are targeting Ice Cream Sandwich you should go with the ShareActionProvider. There you get your desired list of ways to share whatever you want.
You could also read this android-developer-blogpost where they explain how to share via intent. So for example for your emailsharing:
Intent intent=new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
// Add data to the intent, the receiving app will decide what to do with it.
intent.putExtra(Intent.EXTRA_SUBJECT, “Some Subject Line”);
intent.putExtra(Intent.EXTRA_TEXT, “Body of the message, woot!”);

Categories

Resources