一、U盘插拔广播 Atom.apk
1.1、AndroIDManifext.xml
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.gatsby.atom"> <uses-permission androID:name="androID.permission.RECEIVE_BOOT_COMPLETED" /> <!--U盘权限--> <uses-permission androID:name="androID.permission.INTERNET" /> <uses-permission androID:name="androID.permission.READ_EXTERNAL_STORAGE" /> <uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE" /> <application androID:allowBackup="true" androID:icon="@mipmap/ic_launcher" androID:label="@string/app_name" androID:roundIcon="@mipmap/ic_launcher_round" androID:supportsRtl="true" androID:theme="@style/Apptheme"> <activity androID:name=".MainActivity"> <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> <!--隐藏apk应用图标--> <data androID:host="akm.app" androID:pathPrefix="/openwith" androID:scheme="myapp" /> </intent-filter> </activity> <receiver androID:name=".Usbbroadcast"> <intent-filter> <action androID:name="androID.intent.action.BOOT_COMPLETED" /> </intent-filter> <!--U盘插拔广播--> <intent-filter> <action androID:name="androID.intent.action.MEDIA_MOUNTED" /> <action androID:name="androID.intent.action.MEDIA_UNMOUNTED" /> <action androID:name="androID.intent.action.MEDIA_REMOVED" /> <action androID:name="androID.intent.action.MEDIA_EJECT" /> <data androID:scheme="file" /> </intent-filter> </receiver> </application></manifest>
1.2、Usbbroadcast.java
package com.gatsby.atom;import androID.content.broadcastReceiver;import androID.content.Context;import androID.content.Intent;import androID.util.Log;import com.androID.xhapimanager.XHapimanager;import java.io.file;public class Usbbroadcast extends broadcastReceiver { private Context mContext; final static String APK_THOMAS = "mnt/usb_storage/USB_disK"; static String APK_PATH = null; XHapimanager xhapimanager; @OverrIDe public voID onReceive(Context context, Intent intent) { // Todo auto-generated method stub this.mContext = context; String action = intent.getAction(); xhapimanager = new XHapimanager(); if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { String path = intent.getData().getPath(); Log.d("gatsby", "path = " + path);// 这里是U盘路径 if (path.contains(APK_THOMAS)) { Log.d("gatsby", "Receiver:ACTION_MEDIA_MOUNTED->TestAPK"); APK_PATH = path; new Thread(new PreInstallApk()).start(); } } else if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED) || action.equals(Intent.ACTION_MEDIA_EJECT)) { Log.d("gatsby", "onReceive: Usb is remove!"); xhapimanager.XHUninstallOnBackground("com.gatsby.test"); } } class PreInstallApk implements Runnable { @OverrIDe public voID run() { // Todo auto-generated method stub file file = new file(APK_PATH + "/udisk0/Test/Test.apk"); String preinstallPath = file.getPath(); Log.d("gatsby", "file.getPath()->" + preinstallPath); if (file.exists()) { Log.d("gatsby", "thomas will be start install TestAPK"); xhapimanager.XHInstallOnBackground(preinstallPath, "com.gatsby.test"); } else { Log.d("gatsby", "file not exists"); } } }}
二、测试APK Test.apk
1.1、功能:a、轮循七种颜色 b、播放视屏
2.1、AndroIDManifes.xml
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.gatsby.test"> <application androID:allowBackup="true" androID:icon="@mipmap/ic_launcher" androID:label="@string/app_name" androID:roundIcon="@mipmap/ic_launcher_round" androID:supportsRtl="true" androID:theme="@style/Apptheme"> <activity androID:name=".MainActivity"> <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity androID:name=".VIDeoPlayer" androID:label="VIDeoPlayer"> <!-- <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter>--> </activity> </application></manifest>
2.2、styles.xml
<resources> <!-- Base application theme. --> <!-- <style name="Apptheme" parent="theme.AppCompat.light.DarkActionbar">--> <style name="Apptheme" parent="theme.AppCompat.light.NoActionbar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style></resources>
2.3、colors.xml
<?xml version="1.0" enCoding="utf-8"?><resources> <color name="colorPrimary">#6200EE</color> <color name="colorPrimaryDark">#3700B3</color> <color name="colorAccent">#03DAC5</color> <color name="color1">#f00</color> <color name="color2">#06F406</color> <color name="color3">#070707</color> <color name="color4">#FBFBFB</color> <color name="color5">#3F51B5</color> <color name="color6">#0ff</color> <color name="color7">#B7F2ADFB</color></resources>
2.4、activity_main.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:gravity="center" androID:orIEntation="vertical"> <ImageVIEw androID:ID="@+ID/imageVIEw" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" /></linearLayout>
2.5、MainActivity.java
package com.gatsby.test;import androID.content.Intent;import androID.os.Bundle;import androID.os.Handler;import androID.util.Log;import androID.Widget.ImageVIEw;import androIDx.appcompat.app.AppCompatActivity;import com.androID.xhapimanager.XHapimanager;public class MainActivity extends AppCompatActivity { ImageVIEw imageVIEw; int count = 0; XHapimanager xhapimanager; final int[] colors = new int[]{ R.color.color1, R.color.color2, R.color.color3, R.color.color4, R.color.color5, R.color.color6, R.color.color7, }; Handler handler = new Handler(); private Runnable runnable = new Runnable() { @OverrIDe public voID run() { if (count < 7) { Log.d("gatsby", "Thread.currentThread().getID()->" + Thread.currentThread().getID()); imageVIEw.setBackgroundResource(colors[count]); count++; handler.postDelayed(runnable, 20000); } else { try { Thread.sleep(1000); } catch (Exception e) { e.printstacktrace(); } Log.d("gatsby", "count->" + count); Intent intent = new Intent(); intent.setClassname("com.gatsby.test", "com.gatsby.test.VIDeoPlayer"); startActivity(intent); } } }; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); imageVIEw = (ImageVIEw) findVIEwByID(R.ID.imageVIEw); xhapimanager = new XHapimanager(); xhapimanager.XHShowOrHIDeStatusbar(false); Thread thread = new Thread(runnable); thread.start(); } @OverrIDe protected voID onDestroy() { super.onDestroy(); xhapimanager.XHShowOrHIDeStatusbar(true); }}
2.6、activity_vIDeo.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <VIDeoVIEw androID:ID="@+ID/vIDeoVIEw" androID:layout_wIDth="match_parent" androID:layout_height="1200dp" androID:layout_gravity="center"/></linearLayout>
2.7、VIDeoPlayer.java
package com.gatsby.test;import androID.content.Context;import androID.os.Bundle;import androID.Widget.VIDeoVIEw;import androIDx.appcompat.app.AppCompatActivity;import com.androID.xhapimanager.XHapimanager;public class VIDeoPlayer extends AppCompatActivity { VIDeoVIEw vIDeoVIEw; Context mContext; XHapimanager xhapimanager; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_vIDeo); mContext = getApplicationContext(); vIDeoVIEw = (VIDeoVIEw) findVIEwByID(R.ID.vIDeoVIEw); xhapimanager = new XHapimanager(); xhapimanager.XHShowOrHIDeStatusbar(false); vIDeoVIEw.setVIDeoPath("/mnt/usb_storage/USB_disK5/udisk0/Test/Test.mp4"); vIDeoVIEw.start(); }总结
}
以上是内存溢出为你收集整理的APK: 接受U盘插拔广播装卸应用全部内容,希望文章能够帮你解决APK: 接受U盘插拔广播装卸应用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)