2014-06-19 154 views
0

如何将我的应用程序设置为默认值。像我已经使一个包含QR码扫描器功能的应用程序一样,我已经使用了QR码扫描器的ZXing库项目。 这是工作文件,但是当我运行项目,我从“使用”选项完成操作。当我点击我的应用程序扫描仪按钮时,它会打开设备相机,但在此之前它会询问选项。我希望我的应用程序是QR扫描仪的默认设置。意味着它不会出现使用选项的完整操作。将应用程序设置为默认设置android

那么我该如何做到这一点?在清单

+0

您只须打开斑马线的应用程序,而不是让应用程序打开它,如果你点击你的应用程序的扫描仪按钮的用户,请我理解正确吗? – tknell

+0

@tknell - 你说得对。但ZXing是我的图书馆项目,它不是我的原始应用程序,我的原始应用程序是'ScanQR',我想打开'ScanQR'应用程序,不要询问用户打开哪个应用程序 – PTech

+0

好,在您的ScanQR应用程序中,您有一个扫描按钮,这应该打开一个扫描活动,这也是在ScanQR应用程序?或者你是否想从另一个同样来自你的活动中打开ScanQR应用程序? – tknell

回答

0

使用意图过滤来指定动作在活动处理象下面这样:

<activity class=".NoteEditor" android:label="@string/title_note"> 

     <intent-filter android:label="@string/resolve_edit"> 
      <action android:name="android.intent.action.VIEW" /> 
      <action android:name="android.intent.action.EDIT" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="vnd.android.cursor.item/vnd.google.note" /> 
     </intent-filter> 

     <intent-filter> 
      <action android:name="android.intent.action.INSERT" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" /> 
     </intent-filter> 

    </activity> 

例如动作名称读取QR码也许android.intent.readQR您指定意图过滤器这个动作,告诉机器人,你的应用程序处理此行动。当你做得对,你的应用程序应该出现在该列表中。

看看这个链接:

http://developer.android.com/reference/android/content/Intent.html

编辑:检查此链接用于设置应用程序为默认:

http://droidyue.com/blog/2014/01/12/set-the-preferred-application-in-android/

+0

我不希望我的应用程序在列表中,我希望我的应用程序将默认的一个。意味着它被设置为默认值,所以没有列表可以打开应用程序。 – PTech

0

如果您已包括斑马线应用项目( https://github.com/zxing/zxing/tree/master/android),而不仅仅是核心,您可以直接打开负责扫描的活动,如下所示:

Intent intent = new Intent(this,CaptureActivity.class); 
intent.setAction(Intents.Scan.ACTION); 
//or intent.setAction("com.google.zxing.client.android.SCAN"); 
intent.putExtra("SCAN_MODE","QR_CODE_MODE"): // for only scanning qr codes 
startActivityForResult(intent, 9000); // replace 9000 with some request code you defined 

并得到结果在你的活动onActivityResult

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    if (resultCode == RESULT_OK) { 
     if(resultCode=9000){ // again, replace 
      String result = data.getStringExtra("SCAN_RESULT"); 
      ... 
     } 
    } 
相关问题