android - 连接 USB(或 BLE)设备时启动 Play Store

标签 android usb bluetooth-lowenergy google-play

有谁知道第一次通过 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/

相关文章:

android - 在 Android 应用程序中重新启动后尝试打开文件夹时出现权限错误

objective-c - CFSetGetCount 崩溃(EXC_BAD_ACCESS)

linux - Bluez 自动重新连接设备

ios - 首次设置 BLE 外设名称的方式和时间

javascript - 混合移动应用程序

android - 不能将 DrawerLayout 放在 StatusBar 下

java - 如何在使用 postDelayed() 循环的 Android 中停止 Runnable?

java - 如何在 ubuntu 中以 super 用户身份运行 eclipse

python - 尝试使用 pyusb 从 USB 设备读取数据时,我不断收到 "usb.core.USBError: [Errno 16] Resource busy"

python-3.x - 通过 BLE 从 PolarH10 获取数据