【问题标题】:Hide application icon and lauch app on particular key press in android在android中的特定按键上隐藏应用程序图标并启动应用程序
【发布时间】:2014-12-23 11:34:51
【问题描述】:

我想隐藏应用程序图标并想在特定数字组合上启动 Activity。如何做到这一点?

我曾尝试使用广播接收器在特定号码上启动应用程序:

public class ApplicationLauncherReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    String number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
    String compare_num="1369";
    if(number.equals(compare_num))
    {
        Intent myintent=new Intent(context,LauchActivity.class);
        myintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(myintent);
        abortBroadcast();
    }
}

}

使用这个我可以在拨打 1369 号码后启动应用程序。对于隐藏应用程序图标,我在 LauchActivity 类 onCreate() 中编写了以下代码

PackageManager p = getPackageManager();
    ComponentName componentName = new ComponentName(this, AndroidGPSTrackingActivity.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);

使用此应用程序图标是不可见的,但是当我尝试调用 1369 no 来启动应用程序时,它会崩溃并通过错误作为

错误:活动类不存在。

如何隐藏应用程序图标和启动应用程序在特定的无组合。任何建议将不胜感激。提前致谢

【问题讨论】:

    标签: android android-activity broadcastreceiver


    【解决方案1】:

    对我有用的是在清单中创建一个活动别名

     <activity-alias
            android:name=".Launcher"
            android:targetActivity="com.packagename.activity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity-alias>
    

    android:targetActivity 是您的启动器活动的名称,并从清单中的任何其他活动中删除 android.intent.category.LAUNCHER

    【讨论】:

      【解决方案2】:

      您的一个活动将具有以下意图过滤器

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

      如果您从活动中删除该过滤器,您将不再看到启动图标。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-13
        • 2014-03-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多