Android 如何";禁用";外部应用程序';意图过滤器?
我正在编写一个使用od NFC标记的应用程序。我希望NFC标签成为我申请的入口点——包含电话标签的关闭卡应该开始我的活动。然后,当活动运行时,我想禁用所有可以使用NFC标记的意图过滤器,这样另一个特写镜头就什么也做不了(我不想让我的活动重新开始)。我知道如何使用活动别名“禁用”我的意图过滤器:Android 如何";禁用";外部应用程序';意图过滤器?,android,android-intent,Android,Android Intent,我正在编写一个使用od NFC标记的应用程序。我希望NFC标签成为我申请的入口点——包含电话标签的关闭卡应该开始我的活动。然后,当活动运行时,我想禁用所有可以使用NFC标记的意图过滤器,这样另一个特写镜头就什么也做不了(我不想让我的活动重新开始)。我知道如何使用活动别名“禁用”我的意图过滤器: <activity-alias android:enabled="true" android:name=".alias.NFCEntryPoint"
<activity-alias android:enabled="true"
android:name=".alias.NFCEntryPoint"
android:targetActivity="pl.mitrue.safedb.NFCEntryPoint"
android:exported="true"
android:icon="@drawable/ic_launcher"
android:label="@string/alias.pl.mitrue.safedb.NFCEntryPoint" >
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity-alias>
现在问题来了:我的设备上安装了其他使用这种过滤器的应用程序。现在,当我的应用程序正在运行并且我禁用了意图过滤器(通过禁用活动别名)时,会出现一个对话框,要求我选择要使用的应用程序。有没有办法避免这种情况?在最简单的情况下,一旦我的应用程序启动,我不想在关闭NFC标签时采取任何行动。有没有办法让我的应用程序成为唯一一个可以接收外部意图的应用程序
作为记录:我不想完全关闭NFC(我不知道这是否可能),因为我可能想在以后的其他活动中使用它
我希望我已经把我的观点讲清楚了。我是新来的,请谅解
谢谢 我遇到了类似的问题,其中: 1) 如果我在手机的开始屏幕上(所有应用程序关闭),当传递mifare classic卡时,自动打开我的应用程序,而无需询问如果有许多应用程序也阅读mifare classic,则要打开哪个应用程序 2) 如果我的应用程序是打开的,并且传递了一张卡片,不要关闭我的应用程序,并询问我是否有许多同样阅读mifare classic的应用程序使用哪个应用程序。 解决方案:使用 在我的主要活动中:
private IntentFilter[] intentFiltersArray;
private String[][] techListsArray;
private PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
try {
ndef.addDataType("text/plain");
}
catch (MalformedMimeTypeException e) {
throw new RuntimeException("fail", e);
}
intentFiltersArray = new IntentFilter[] {ndef, };
techListsArray = new String[][] { new String[] { android.nfc.tech.MifareClassic.class.getName() } };
}
@Override
protected void onResume() {
super.onResume();
adaptadorNFC = NfcAdapter.getDefaultAdapter(this);
System.out.println("Se setearan parametros");
final Intent intent = new Intent(this.getApplicationContext(), this.getClass());
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
adaptadorNFC.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, techListsArray);
leerTarjeta(this.getIntent());
}
@Override
protected void onPause() {
System.out.println("Se dessetearan parametros");
adaptadorNFC.disableForegroundDispatch(this);
super.onPause();
}
希望这能帮助其他人,因为这个问题一年前就被问到了:不,你不能。您正试图覆盖系统安全性,因为您运行的是沙盒,所以无法控制此行为。好的,但不知何故,我安装的某个应用程序具有所需的行为。在应用程序关闭标记的某些地方,它什么也不做,在另一些地方,它执行一个操作(并不总是相同的)。在使用自己的应用程序时,从未要求我选择像现在这样的活动。这正是我需要的行为。也许有什么办法我可以用?我不知道是否有可能获取和反编译从谷歌市场安装的应用程序的源代码-如果是这样,如果我在这里没有得到答案,我会这样做。这并不能真正回答问题。如果您有不同的问题,可以单击以提问。一旦你有足够的时间,你也可以吸引更多的注意力,这是真的。也许不完全如此,但我认为@mitrue应该是决定这一点的人。
private IntentFilter[] intentFiltersArray;
private String[][] techListsArray;
private PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
try {
ndef.addDataType("text/plain");
}
catch (MalformedMimeTypeException e) {
throw new RuntimeException("fail", e);
}
intentFiltersArray = new IntentFilter[] {ndef, };
techListsArray = new String[][] { new String[] { android.nfc.tech.MifareClassic.class.getName() } };
}
@Override
protected void onResume() {
super.onResume();
adaptadorNFC = NfcAdapter.getDefaultAdapter(this);
System.out.println("Se setearan parametros");
final Intent intent = new Intent(this.getApplicationContext(), this.getClass());
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
adaptadorNFC.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, techListsArray);
leerTarjeta(this.getIntent());
}
@Override
protected void onPause() {
System.out.println("Se dessetearan parametros");
adaptadorNFC.disableForegroundDispatch(this);
super.onPause();
}