问题
I have an app that its installed in the user's phone and remains hidden from the Applications Drawer, to achieve this it was only a matter of removing the intent-filter tags, this work fine for everything below ICS 4.0, any help to get it working in ICS?
This works fine in gingerbread and froyo, starts my activity and keeps hidden the App Icon from the drawer,
<activity
android:label="@string/app_name"
android:name=".DashboardActivity" >
</activity>
but not working in ICS, if i remove this lines the activity wont start, any ideas why?
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
This is the code for my Dialpad listener
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class DialpadLauncher extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Bundle bundle = intent.getExtras();
if (null == bundle)
return;
// outgoingNumber=intent.getStringExtra(Intent.ACTION_NEW_OUTGOING_CALL);
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if (phoneNumber.equals("#00008#")){
//START APPLICATION HERE
//Toast.makeText(context,"DIALED: " + phoneNumber, Toast.LENGTH_LONG).show();
try {
Intent activity = new Intent(context, DashboardActivity.class);
activity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(activity);
setResultData(null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// catch not found (only works on HTC phones)*/
}
}
}
回答1:
In case that anyone bumps into this in the future, i found a way to hide App Icon from the drawer programmatically in case it doesnt do it by removing the intent-filter:
//Disable Launcher icon from drawer if higher than Android 2.3
try {
ComponentName componentToDisable = new ComponentName("com.your.packagename", "com.your.packagename.ActivityName");
getPackageManager().setComponentEnabledSetting(componentToDisable, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
来源:https://stackoverflow.com/questions/16802786/remove-app-icon-from-drawer-not-working-in-android-4-1