how i can start application info screen in android? - java

I want to start manage application (Settings -> Application -> manage application -> Application info) screen programmatically. I'm unable to do it. Can anyone please help me?
Thanks in advance.

as per this link
In Android 2.3, you can use startActivity() on an ACTION_APPLICATION_DETAILS_SETTINGS Intent, with a proper Uri, to bring up your app's "manage" screen
or
private static final String SCHEME = "package";
private static final String APP_PKG_NAME_21 = "com.android.settings.ApplicationPkgName";
private static final String APP_PKG_NAME_22 = "pkg";
private static final String APP_DETAILS_PACKAGE_NAME = "com.android.settings";
private static final String APP_DETAILS_CLASS_NAME = "com.android.settings.InstalledAppDetails";
public static void showInstalledAppDetails(Context context, String packageName) {
Intent intent = new Intent();
final int apiLevel = Build.VERSION.SDK_INT;
if (apiLevel >= 9) { // above 2.3
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts(SCHEME, packageName, null);
intent.setData(uri);
} else { // below 2.3
final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22
: APP_PKG_NAME_21);
intent.setAction(Intent.ACTION_VIEW);
intent.setClassName(APP_DETAILS_PACKAGE_NAME,
APP_DETAILS_CLASS_NAME);
intent.putExtra(appPkgName, packageName);
}
context.startActivity(intent);
}

From API Level 9 (Android 2.3) you can start an Intent with android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS. Thus:
packageName = "your.package.name.here"
try {
//Open the specific App Info page:
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);
} catch ( ActivityNotFoundException e ) {
//e.printStackTrace();
//Open the generic Apps page:
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
startActivity(intent);
}

Related

unable to start activity from service class

Please be informed, we are trying to start activity from service class, which is fired on clicking push notification addaction intent. The service class contains two actions, one to stop playing ringtone and another to startactivity. But unfortunately the start activity just does not boot in our service class.
Service Class page is as given below:
public class RingtonePlayingService extends Service {
private static final String TAG = RingtonePlayingService.class.getSimpleName();
private static final String URI_BASE = RingtonePlayingService.class.getName() + ".";
public static final String ACTION_DISMISS = URI_BASE + "ACTION_DISMISS";
public static final String ACTION_START = URI_BASE + "ACTION_START";
private MediaPlayer mp;
private Ringtone ringtone;
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "onStartCommand");
int notificationId = intent.getIntExtra("notificationId", 0);
if (intent == null) {
Log.d(TAG, "The intent is null.");
return START_REDELIVER_INTENT;
}
String action = intent.getAction();
if (ACTION_START.equals(action)) {
String uri = String.valueOf(intent.getIntExtra("uri", 0));
Intent intents = new Intent(this, MainActivity.class);
intents.putExtra("uri", uri);
intents.putExtra("notification_id", notificationId);
intents.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
this.startActivity(intents);
}
return START_STICKY;
}
#Override
public void onDestroy() {
super.onDestroy();
mp.reset ();
}}
Firebase (from where service class's intent is fired)
Intent startIntent = new Intent(this, RingtonePlayingService.class);
startIntent.setAction(RingtonePlayingService.ACTION_START);
startIntent.putExtra("uri", uri);
startIntent.putExtra("notification_id", notification_id);
PendingIntent pt = PendingIntent.getService(this,123, startIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action action_n = new NotificationCompat.Action.Builder(R.mipmap.ic_launcher, tag, pt).build();
The objective here is on firing of pending Intent 'pt'. We want to start the activity (that opens the app's url) as well as run the service class (which stops the service and the ringtone).
Please help us find a solution on this never ending issue.
The service class contains two actions, one to stop playing ringtone and another to startactivity. But unfortunately the start activity just does not boot in our service class.
You cannot start an activity from the background on modern versions of Android.
Firebase (from where service class's intent is fired)
That code has problems:
Your Intent is for RingtonePlayingService, which according to your first code snippet is a Service. Yet, you try using it with PendingIntent.getActivity(), rather than PendingIntent.getService().
You are using addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK), which are irrelevant for a Service.

How can I get the value of an Int in an differnet activity? getIntent() doesnt work anymore

Hi I want to recieve my string data in another activity.
I found this code on youtube:
Activity 1:
public static final String FINISHED_LEVELS = "com.example.rexan_snerficonquiz.Quiz_Fragment.FINISHED_LEVELS";
public static final String SKIPPED_LEVELS = "com.example.rexan_snerficonquiz.Quiz_Fragment.SKIPPED_LEVELS";
public static final String FAILED_LEVELS = "com.example.rexan_snerficonquiz.Quiz_Fragment.FAILED_LEVELS";
public static final String USED_HINTS = "com.example.rexan_snerficonquiz.Quiz_Fragment.USED_HINTS";
public void openActifity2(){
Intent intent = new Intent(getActivity().getApplication(), Fragment_score.class);
intent.putExtra(FINISHED_LEVELS, finishedLevels);
intent.putExtra(FAILED_LEVELS, failedLevels);
intent.putExtra(USED_HINTS, usedHints);
intent.putExtra(SKIPPED_LEVELS, skippedLevels);
startActivity(intent);
}
Activity 2:
Intent intent = getIntent();
int finishedLevels = intent.getIntExtra(Quiz_Fragment.FINISHED_LEVELS,0);
int failedLevels = intent.getIntExtra(Quiz_Fragment.FAILED_LEVELS, 0);
int skippedLevels = intent.getIntExtra(Quiz_Fragment.SKIPPED_LEVELS, 0);
int usedHints = intent.getIntExtra(Quiz_Fragment.USED_HINTS, 0);
But getIntent() doesnt work anymore. Can anyone help me?
Use this code it may work
In activity1.java
Intent intent=new Intent(Activity1.this, Activity2.class);
intent.putExtra(Key,Value);
context.startActivity(intent);
get in Activity2.java
int mValue=getIntent().getExtras().getInt(Key);

Launch Telegram app from Android application with message and recipient

I need to open Telegram from my own Android App prepopulating both the message and recipient (and not having to choose betwenn Chrome or Telegram),
I achieved the first one with this code:
final String appName = "org.telegram.messenger";
Intent tIntent = new Intent(Intent.ACTION_SEND);
tIntent.setType("text/plain");
tIntent.setPackage(appName);
tIntent.putExtra(Intent.EXTRA_TEXT, msg);
mUIActivity.startActivity(tIntent);
And the second one with this code:
Intent tIntent = new Intent(Intent.ACTION_VIEW);
tIntent.setData(Uri.parse("http://telegram.me/USERID"));
startActivity(tIntent);
(I removed all checks like isTelegramInstalled for simplicity)
I tried to mix the two methods
adding some intent extra such as msg we get to this code that will open Telegram, in one click, with pre-populated message and recipient:
Intent telegramIntent = new Intent(Intent.ACTION_SEND);
tIntent.setDataAndType(Uri.parse("http://telegram.me/username"), "text/plain");
final String appName = "org.telegram.messenger";
tIntent.setPackage(appName);
tIntent.putExtra(Intent.EXTRA_TEXT, "hello");
startActivity(tIntent);
...aaand it didn't work!
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND dat=http://telegram.me/... flg=0x1 pkg=org.telegram.messenger clip={null T:hello} (has extras) }
Any idea how to achieve this?
Please try below function for open Telegram
public static void openTelegram(Activity activity, String userName) {
Intent general = new Intent(Intent.ACTION_VIEW, Uri.parse("https://t.com/" + userName));
HashSet<String> generalResolvers = new HashSet<>();
List<ResolveInfo> generalResolveInfo = activity.getPackageManager().queryIntentActivities(general, 0);
for (ResolveInfo info : generalResolveInfo) {
if (info.activityInfo.packageName != null) {
generalResolvers.add(info.activityInfo.packageName);
}
}
Intent telegram = new Intent(Intent.ACTION_VIEW, Uri.parse("https://t.me/" + userName));
int goodResolver = 0;
// gets the list of intents that can be loaded.
List<ResolveInfo> resInfo = activity.getPackageManager().queryIntentActivities(telegram, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName != null && !generalResolvers.contains(info.activityInfo.packageName)) {
goodResolver++;
telegram.setPackage(info.activityInfo.packageName);
}
}
}
//TODO: if there are several good resolvers create custom chooser
if (goodResolver != 1) {
telegram.setPackage(null);
}
if (telegram.resolveActivity(activity.getPackageManager()) != null) {
activity.startActivity(telegram);
}
}
I hope this can help You!
Thank You.
In your case
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND dat=http://telegram.me/... flg=0x1 pkg=org.telegram.messenger clip={null T:hello} (has extras) }
Telegram chat activity class has a different name and you pass other activity name.
Find which class use telegram for chat activity and pass it on set package method

Open Application in Android by label name, and unknowing package name.

First of all, I searching for my question many times in Google but I didn't find what I want.
My Question is: Is there any way to open application in Android by "label name" where on the other hand the package name is "knowing" ?
My approach that I used to do this is by creating two ArrayList and store the package name and label name in each one, then, I matching the label name with package name after I converted them to lowercase in order to be the same letters to see if there are matching, if matching , then I launch the application by getting its package name.
the problem that I faced it, the package name sometimes didn't have or matching the same name in label name, based on the application developer what he had write the package name.
for example: if I want to open gmail , based on my method I cannot because the package name is com.google.android.gm and label name is gmail , I apologized to the prolongation ,thanks in advanced.
My code:
private void getAllApps() {
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> activities = getPackageManager()
.queryIntentActivities(mainIntent, 0);
for (ResolveInfo resolveInfo : activities) {
appsName.add(resolveInfo.loadLabel(getPackageManager()).toString()
.toLowerCase());
pkgsName.add(resolveInfo.activityInfo.packageName.toString());
}
}
private void openApplication(String appName) {
String packageName = null, appNameLowerCase = null, pkgNameLowerCase = null;
// matching the package name with label name
if (appsName.contains(appName)) {
appNameLowerCase = appName.trim().replace(" ", "");
for (int i = 0; i < pkgsName.size(); i++) {
pkgNameLowerCase = pkgsName.get(i).trim().toLowerCase();
if (pkgNameLowerCase
.matches("(.*)" + appNameLowerCase + "(.*)")) {
packageName = pkgsName.get(i);
break;
}
}
}
// to launch the application
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage(packageName);
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
}
}
thanks for all replies, i solve it by #CommonsWare solution and it works correctly :
class Applications {
private String packageName;
private String labelName;
}
private void getAllApps() {
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> activities = getPackageManager()
.queryIntentActivities(mainIntent, 0);
for (ResolveInfo resolveInfo : activities) {
Applications applications = new Applications();
applications.labelName = resolveInfo.loadLabel(getPackageManager())
.toString().toLowerCase();
applications.packageName = resolveInfo.activityInfo.packageName
.toString();
applicationsArrayList.add(applications);
}
}
private void openApplication(String appName) {
String packageName = null;
// matching the package name with label name
for (int i = 0; i < applicationsArrayList.size(); i++) {
if (applicationsArrayList.get(i).labelName.trim().equals(
appName.trim())) {
packageName = applicationsArrayList.get(i).packageName;
break;
}
}
// to launch the application
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage(packageName);
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
}
}
Try this
public List<ApplicationInfo> getApplicationList(Context con){
PackageManager p = con.getPackageManager();
List<ApplicationInfo> info = p.getInstalledApplications(0);
String example = info.get(0).packageName.toString();
return info;
}

how to start another application from my application in android

final List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
The above PackageInfo class for get the list of packages then
get package names for :
ViewHendler hendler = new ViewHendler();
hendler.textLable = (TextView)convertView.findViewById(R.id.textView);
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(packageName);
startActivity( LaunchIntent );
then start applicathin using package name call :launchApp(packageName)
void launchApp(String packageName) {
Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
if (mIntent != null) {
try {
startActivity(mIntent);
} catch (ActivityNotFoundException err) {
Toast t = Toast.makeText(getApplicationContext(),
R.string.app_not_found, Toast.LENGTH_SHORT);
t.show();
}
}
}
But didn't get result(start another application from my application).
It's right way to use:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.name");
startActivity(LaunchIntent);
But probably you have no permission, or you don't have application there.
Firstly check your packageName parameter.

Categories