Hide the application icon and launch it.

I need to hide the application icon.
And start the program using the dial.
Example: * 12345 #

I cannot start the program that was hidden.

Hide application:

PackageManager p = getPackageManager();
            ComponentName componentName = new ComponentName(this, com.example.broadcastreciver.MainActivity.class); // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
            p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

      


Run MainActivity:

Intent appIntent = new Intent(context, Blank.class);
            appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           context.startActivity(appIntent);

      



this is AndroidManifest.xml

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name=".IncomingSms" >
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
            </intent-filter>
        </receiver>

        <activity
            android:name=".Blank"
            android:label="@string/title_activity_blank" >
        </activity>
    </application>

      

+3


source to share


2 answers


Finally I found an alternative way
AND the problem was solved
I created an intent filter

AndroidManifest.xml

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
<!-- Here is Launcher -->
            </intent-filter>
        </activity>
        <receiver android:name=".IncomingSms" >
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
            </intent-filter>
        </receiver>

        <activity

            android:name=".Blank"
            android:label="@string/title_activity_blank" >
<intent-filter>
     <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
        </activity>
    </application>

      



Hide app icon



ComponentName componentToDisable =
                  new ComponentName("com.example.broadcastreciver",
                  "com.example.broadcastreciver.MainActivity");
                getPackageManager().setComponentEnabledSetting(
                  componentToDisable,
                  PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                  PackageManager.DONT_KILL_APP);

      



and for the Launch app:

String phoneNubmer = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        if (LAUNCHER_NUMBER.equals(phoneNubmer)) {
            setResultData(null);
            Intent appIntent = new Intent(context, Blank.class);
            appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           context.startActivity(appIntent);
        } 

      


I hid my MainActivity I created an Intent filter for the second activity
Launching the application via USSD code (example: * 123456 # etc.)
I named the second activity (Empty)

+1


source


If you disable an action, it cannot be started. What you really want to do is disable or uninstall <intent-filter>

in action. Unfortunately, explicit intent filters cannot be removed or even checked (see this bug ).



What you can do is determine <activity-alias>

which <intent-filter>

s is in and enable / disable that component. When the activity alias is disabled, you can still launch the target activity using the implicit intent, but the app should not appear in the launcher since the disabled component is the one that has an intent filter for the action. MAIN and category.LAUNCHER.

+4


source







All Articles