Get package name from Intent - android

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);
}

Related

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.

Android: How to get the native Email clients package name

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.

Send file to another application

I'm trying to send one file from my app to another. I don't want to use an "app chooser", I just want to "force" that app to open the file I want.
I've tried:
Uri data = Uri.fromFile( file );
PackageManager pm = getApplicationContext().getPackageManager();
Intent ic = pm.getLaunchIntentForPackage("org.ais.archidroid");
ic.setAction(Intent.ACTION_SEND);
ic.setData(data);
ic.putExtra(Intent.EXTRA_STREAM, data);
startActivity(ic);
But this just opens the other app without the file. I have tried several combinations and googled it and haven't found anything. Maybe it's not supported.
I would suggest trying ACTION_VIEW instead of ACTION_SEND. Something like this:
Uri data = Uri.fromFile( file );
PackageManager pm = getApplicationContext().getPackageManager();
Intent ic = pm.getLaunchIntentForPackage("org.ais.archidroid");
ic.setAction(Intent.ACTION_VIEW);
ic.setData(data);
startActivity(ic);
Try setting also the launcher activity of that app you seek:
Intent intent= new Intent("org.ais.archidroid.launcheractivity");
intent.setClassName("org.ais.archidroid", "launcheractivity");
intent.setData(Uri.parse(yourdata));
startActivity(intent);
But just make sure, you typed its packageName and className right... hope this will help.

How to detect the existence of Android Market on devices?

Some Android devices don't have Android Market, like Korea, etc.
Is it possible to detect the existence of Android Market at runtime?
I know I can try to open a market uri first to see if there is any exception thrown. But I don't think this is a wise approach.
I know I can try to open a market uri
first to see if there is any exception
thrown.
Create the ACTION_VIEW Intent for the Market Uri, then use PackageManager and queryIntentActivities() to see if you get anything back. If that returns an empty list, you know nothing on the device handles Market Uri values.
A complete solution, that also reads the packagename by itself ...
Context context = this;
final PackageManager packageManager = context.getPackageManager();
String packagename = this.getPackageName();
String url = "market://details?id=" + packagename;
Intent i2 = new Intent(Intent.ACTION_VIEW);
i2.setData(Uri.parse(url));
List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(i2,PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfo.size() > 0) startActivity(i2);

Categories

Resources