我想用拨号盘启动一个隐藏的应用程序。由于activity-alias没有java类,因此以下代码无效。开始正常活动工作正常。有人能告诉我如何使用拨号盘启动活动别名吗?
public class MyOutgoingCallHandler extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Extract phone number reformatted by previous receivers
String phoneNumber = getResultData();
if (phoneNumber == null) {
// No reformatted number, use the original
phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
}
if(phoneNumber.equals("1234")){ // DialedNumber checking.
// My app will bring up, so cancel the broadcast
setResultData(null);
// Start my app
Intent i=new Intent(context,MainActivity.class);
i.putExtra("extra_phone", phoneNumber);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
答案 0 :(得分:0)
我现在已经知道了。此代码有效:
public class MyOutgoingCallHandler extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Extract phone number reformatted by previous receivers
String phoneNumber = getResultData();
if (phoneNumber == null) {
// No reformatted number, use the original
phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
}
if(phoneNumber.equals("1234")){ // DialedNumber checking.
// My app will bring up, so cancel the broadcast
setResultData(null);
// Start my app
Intent i = new Intent();
String packageName = context.getPackageName();
ComponentName componentName = new ComponentName(packageName,
packageName + "your_ALIAS_ACTIVITY");
i.setComponent(componentName);
i.putExtra("extra_phone", phoneNumber);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}