2014-09-02 71 views
1

是否有人知道在首次通過Android手機或平板電腦通過USB(或BLE)連接設備時是否可以自動打開Play商店? 其目的是確保用戶在首次連接新設備(例如MIDI鍵盤或其他設備)時安裝捆綁應用程序。這顯然必須是Android操作系統的一部分(哪個版本?)連接USB(或BLE)設備時啓動Play商店

感謝

從下面

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.hardware.usb.UsbManager; 

public class Usbinserted extends BroadcastReceiver { 

@Override 
public void onReceive(Context ctx, Intent intent) { 
    // TODO Auto-generated method stub 


      Intent i = new Intent(Intent.ACTION_MAIN, null); 

      i.addCategory(Intent.CATEGORY_LAUNCHER); 

      ComponentName cn = new ComponentName(
       "com.google.android.finsky.FinskyApp", 
       "com.google.android.finsky.FinskyApp.AssetBrowserActivity"); 

      i.setComponent(cn); 

      i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

      ctx.startActivity(i); 

// Log.d(TAG,"USB connected.."); 


} 

} 

現在複製並粘貼到您的清單文件

+0

是可能的 – raj 2014-09-02 10:10:15

+0

@raj證明它(你的回答沒有解決我的問題)。 – DrMad 2014-09-02 13:14:04

回答

0

第一個副本bradcastrecieverclass

<receiver android:name=".Usbinserted" > 
     <intent-filter> 
      <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /> 
      <action android:name="android.intent.action.MEDIA_MOUNTED" /> 
      <action android:name="android.intent.action.UMS_CONNECTED" /> 
      <action android:name="android.intent.action.USB_ACCESSORY_ATTACHED" /> <data android:scheme="file"/> 
     </intent-filter> 
    </receiver> 

並將這些權限添加到清單文件

<uses-feature android:name="android.hardware.usb.host" /> 
<uses-permission android:name="android.permission.USB_PERMISSION" /> 
+0

你沒有回答我的問題。最初安裝的應用程序沒有。問題是自動觸發到Play商店的連接以下載我的應用程序。 – DrMad 2014-09-02 12:27:01

+0

因爲你需要安裝一個應用程序包含廣播接收器 – raj 2014-09-02 12:36:50