有谁知道第一次通过 Android 手机或平板电脑上的 USB(或 BLE)连接设备时是否可以自动打开 Play 商店?
目的是确保用户在第一次连接新设备(例如 MIDI 键盘或其他)时安装 bundle 的应用程序。它显然必须是 Android 操作系统的一部分(哪个版本?)
谢谢
最佳答案
首先从下面复制 bradcastrecieverclass
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..");
}
}
现在将其复制并粘贴到您的 list 文件中
<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>
并将这些权限添加到 list 文件
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
关于android - 连接 USB(或 BLE)设备时启动 Play Store,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25620753/