【发布时间】:2018-03-07 13:10:09
【问题描述】:
我正在实现一个隐藏的应用程序。我想在手机中隐藏应用程序,并在我拨打某个号码时启动它。
首先,我在清单上声明了一个别名活动,然后将其隐藏。它是 MainActivity2:
public class Main2Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
PackageManager p = getPackageManager();
ComponentName LAUNCHER_COMPONENT_NAME = new ComponentName(
"com.example.susan.oculta.launcher", "com.example.susan.oculta.launcher.Launcher");
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);...
一些清单行:
<activity-alias
android:name=".launcher.Launcher"
android:targetActivity=".launcher.Main2Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
使用此代码,我可以隐藏图标。
我还有一个广播接收器。这个:
public class LaunchAppViaDialReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
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")) {
Log.i("reciving", "receeeeeeeeeiving");
Intent i = new Intent();
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.setClass(context, MainActivity.class);
context.startActivity(i);
setResultData(null);
Toast.makeText(context, "aaaa", Toast.LENGTH_LONG).show();
}
}
}
问题是,当我拨打“12345”时,Toast 会出现,但 MainActivity 却没有。我已经尝试向意图添加标志并开始通过包查找它的意图。但意图似乎不起作用。 日志“receeeeeeeeeiveing”也会显示出来。
【问题讨论】:
-
我在几部手机上尝试了相同的代码,它有时有效,有时无效。 MIUI OS似乎与此有关。无论如何,我做了一个解决方法。接到电话时我开始通知。从那里,用户可以按下通知并开始主要活动。适用于我的应用
标签: android broadcastreceiver hidden