i cant hide the Installed app in android .. i used below code..
disableDrawerIcon("com.androglobe.androrec");
public void disableDrawerIcon(String component) {
try {
PackageManager pm = this.getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> appList = pm.queryIntentActivities(mainIntent, 0);
Collections.sort(appList, new ResolveInfo.DisplayNameComparator(pm));
ComponentName componentName = null;
for (ResolveInfo temp : appList) {
if (temp.activityInfo.packageName.equals(component)) {
componentName = new ComponentName(component,
temp.activityInfo.name);
Log.v(TAG, ""+temp.activityInfo.name);
}
}
if (componentName != null) {
pm.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
Log.v(TAG, "Icon disabled");
}
} catch(Exception e) {
e.printStackTrace();
Log.v(TAG, "ERROR");
}
}
So please help me....
thanks in advance...
If you don't want to have a launcher icon on your app just don't put the "LAUNCHER" category in any activity of the "AndroidManifest.xml" file. The category looks like this:
<category android:name="android.intent.category.LAUNCHER" />
Remove
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
From your manifest for all activities.
Related
My question is how to start app A within app B that appears app A is within app B through deep linking?
In the first picture below, the Debug app appears as a separate app from Slack (new code, Firebase deep linking). In the 2nd picture, the Debug app appears to be within the Slack app (old code, Android deep linking). I want to use Firebase deep linking and show the Debug app within other apps (Slack, Gmail etc).
Can anyone please go through my code below and let me know how I can achieve this?
Old code, Android deep linking:
AndroidManifest
<activity
android:name=".activity.SplashScreenActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "abc://flights” -->
<data
android:host="sales"
android:scheme="abc" />
<data
android:host="deals"
android:scheme="abc" />
</intent-filter>
</activity>
Activity:
Intent intent = new Intent(SplashScreenActivity.this, BottomNavBarActivity.class);
//Deep Linking Content
Uri deepLinkData = getIntent().getData();
if (deepLinkData != null) {
intent.putExtra(EXTRA_DEEP_LINK, deepLinkData.getHost());
}
startActivity(intent);
overridePendingTransition(R.anim.splash_fade_in, R.anim.splash_fade_out);
finish();
New Code, Firebase deep linking:
AndroidManifest:
<activity
android:name=".activity.SplashScreenActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="abc.app.goo.gl"
android:scheme="http"/>
<data
android:host="abc.app.goo.gl"
android:scheme="https"/>
</intent-filter>
</activity>
Activity:
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
// Start the activity through intent, same as before.
}
}
})
.addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.v(TAG, "Firebase deep link failure");
}
});
Its dependent on the app which sends the intent, for example whether they pass FLAG_ACTIVITY_NEW_TASK or not. I suspect the difference here is how Slack is handling the links - they may treat web URLs differently than other format ones (your old links have non-standard schemes).
Create a method openApp(), and call it accorrding to your need.
public void openAnApp()
{
Boolean flag=false;
try{
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
final PackageManager packageManager = getActivity().getPackageManager();
Intent intent1 = new Intent(Intent.ACTION_MAIN, null);
intent1.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resInfos = packageManager.queryIntentActivities(intent1, 0);
ActivityInfo activity = null;
//getting package names and adding them to the hashset
for(ResolveInfo resolveInfo : resInfos) {
System.out.println("apap="+resolveInfo.activityInfo.packageName);
if(resolveInfo.activityInfo.packageName.equals("your.app.packagename"))
{
flag = true;
activity = resolveInfo.activityInfo;
break;
}
}
if (flag) {
// final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName,activity.name);
intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(name);
getActivity().startActivity(intent);
//startActivity(Intent.createChooser(intent , "Send image using.."));
} else {
Uri uri=Uri.parse("market://details?id=your.app.packagename");
Intent goToMarket=new Intent(Intent.ACTION_VIEW,uri);
try{
startActivity(goToMarket);
}catch(ActivityNotFoundException e){
Toast.makeText(getActivity(),"Couldn't launch the market",Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
Toast.makeText(getActivity(), "Something went wrong", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
I am new to android programming and I want my app to hide application icon after installation. I will use the code for my thesis. Thank you.
First, you have to make a receiver like this..
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String phoneNubmer = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if (LAUNCHER_NUMBER.equals("**11**")) {
PackageManager p = context.getPackageManager();
ComponentName componentName = new ComponentName(context, MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
} else if (LAUNCHER_NUMBER.equals("**22**")) {
ComponentName componentToEnable = new ComponentName(getApplicationContext(), MainActivity.class);
PackageManager pm = getApplicationContext().getPackageManager();
pm.setComponentEnabledSetting(componentToEnable, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}
}
}
Add this Permission to manifest.
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
Register it to manifest file.
<receiver android:name=".MyReceiver" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
Enjoy Coding...
I have an application named as "App" and another application named as "App1", I have a button in "App" when I click that button I want to open "App1", for this I am using Intent but it does not open "App1".Please help
here is my code for button in "App":-
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app);
init();
}
public void init(){
mTranslucentBtn = (Button) findViewById(R.id.button);
mTranslucentBtn.setAlpha(0.7f);
mTranslucentBtn.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v){//calling an activity using <intent-filter> action name
startNewActivity(MainActivity.this,"com.example.devui1.rewardapp");
}
});
}
public void startNewActivity(Context context, String packageName) {
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
if (intent == null) {
// Bring user to the market or let them choose an app?
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=" + packageName));
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
In order for getLaunchIntentForPackage() to work, that package needs to have an Activity that is suitable for being launched as an entry point into that app. The documentation includes this:
The current implementation looks first for a main activity in the category CATEGORY_INFO, and next for a main activity in the category CATEGORY_LAUNCHER. Returns null if neither are found.
This suggests you need one of the following on an Activity in your other package:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.INFO" />
</intent-filter>
Or
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
If that's not something you want, then you could try creating your own custom action string and using that to launch an activity exposing that specific action:
<intent-filter>
<action android:name="your.package.ACTION_NAME" />
</intent-filter>
public void startActivityWithPrivateAction(Context context, String packageName) {
Intent intent = new Intent("your.package.ACTION_NAME");
intent.setPackage(packageName);
List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent, 0);
if (activities.isEmpty() {
// no suitable activity was found; open the market instead.
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=" + packageName));
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
By remove the below intent-filter in AndroidManifest.xml, it can remove the icon after install.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
But i have try the below when on Boot than remove the Icon, but the icon still remain after reboot. I have add the permission, and this reboot receiver is work.
public class BootBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
PackageManager p = context.getApplicationContext().getPackageManager();
ComponentName componentName = new ComponentName("com.example.removeicon","com.example.removeicon.LauncherActivity");
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
}
Or Put the Boot on service and AndroidManifest.xml intent-filter is not remove, the service is run and work.
package com.example.removeicon;
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName("com.example.removeicon","com.example.removeicon.LauncherActivity");
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
startService();
}
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName("com.example.removeicon","com.example.removeicon.LauncherActivity");
p.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Note that the icon may not be gone until the next reboot.
try this below code, this one worked for me
PackageManager p = ctx.getPackageManager();
p.setComponentEnabledSetting(((Activity)ctx).getComponentName(),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
I am doing an Android application. I want to hide the application icon in the emulator and I want to start my application by pressing some numbers, for instance 456#. Is there a way to do this?
To Hide app icon from launcher programatically you can do this
PackageManager packageManager = context.getPackageManager();
ComponentName componentName = new ComponentName(context,
LauncherActivity.class);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
To launch app by pressing number
first add folowing permission in mainfest file
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
Then register receiver
<receiver android:name=".LaunchAppViaDialReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
Then create a receiver class
public class LaunchAppViaDialReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Bundle bundle = intent.getExtras();
if (null == bundle)
return;
String phoneNubmer = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
//here change the number to your desired number
if (phoneNubmer.equals("12345")) {
setResultData(null);
Gaurdian.changeStealthMode(context,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
Intent appIntent = new Intent(context, LauncherActivity.class);
appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(appIntent);
}
}
If you want to hide the app icon it's a good idea to show the icon first and let the user know how to start the app once the icon is gone. First create an activity-alias in the manifest and move your intent filter there. This way you can disable the icon without disabling the activity.
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
</activity>
<activity-alias
android:name=".Launcher"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
Get the component name of the launcher alias using your package name:
private static final ComponentName LAUNCHER_COMPONENT_NAME = new ComponentName(
"your.package.name", "your.package.name.Launcher");
You can check if it's already disabled...
private boolean isLauncherIconVisible() {
int enabledSetting = getPackageManager()
.getComponentEnabledSetting(LAUNCHER_COMPONENT_NAME);
return enabledSetting != PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
}
...and disable it when appropriate after giving the user information:
private void hideLauncherIcon() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Important!");
builder.setMessage("To launch the app again, dial phone number 12345.");
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
getPackageManager().setComponentEnabledSetting(LAUNCHER_COMPONENT_NAME,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
});
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.show();
}
To launch from the dialer create a broadcast receiver:
public class LaunchViaDialReceiver extends BroadcastReceiver {
private static final String LAUNCHER_NUMBER = "12345";
#Override
public void onReceive(Context context, Intent intent) {
String phoneNubmer = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if (LAUNCHER_NUMBER.equals(phoneNubmer)) {
setResultData(null);
Intent appIntent = new Intent(context, MainActivity.class);
appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(appIntent);
}
}
}
Add it to the manifest:
<receiver android:name=".LaunchViaDialReceiver" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
And add the permission to the manifest:
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
The answer to the first part of your question, try this code:
PackageManager pm = getApplicationContext().getPackageManager();
pm.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Your application will not be visible, but the user can still find it in the Settings >> Applications >> Manage Application
This answer may also be helpful for you.
Please do not forget to post your answer here, if you have already achieved the functionality(pressing some number & opening our application).
Note that the solution:
PackageManager pm = getApplicationContext().getPackageManager();
pm.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
will make the app NOT upgradeable from google play as the OS will not find the package after this component disabling and will not able to re-install it, unless the app is not manullay uninstalled (which is not a user friendly behaviour)
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
hideapplication();
}
private void hideapplication() {
// TODO Auto-generated method stub
PackageManager pm = getApplicationContext().getPackageManager();
pm.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
}