开机自启动和由一个APK启动另一个APK核心代码
生活随笔
收集整理的這篇文章主要介紹了
开机自启动和由一个APK启动另一个APK核心代码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、開機自啟動
public class BootReceiver extends BroadcastReceiver {private static final String ACTION = "android.intent.action.BOOT_COMPLETED";private static final String TAG = "ZED_Led_Receiver";private static final String FileName = "/sys/class/zed/led1";private static final String action_boot="android.intent.action.BOOT_COMPLETED"; //啟動APK@Overridepublic void onReceive(Context context, Intent intent) {//Log.e(TAG,"LedReceiver.");if (intent.getAction().equals(ACTION)){{ //啟動APKIntent ootStartIntent=new Intent(context,BootActivity.class); //這一句的BootActivity是要啟動的activityootStartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(ootStartIntent); }if(android.os.SystemProperties.get("persist.sys.skled").equals("1")){ledSet(1);}else{ledSet(0);} } }<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.pstreets.demo"android:versionCode="1"android:versionName="1.0" ><uses-sdk android:minSdkVersion="10" /><uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /><uses-permission android:name="android.permission.DISABLE_KEYGUARD" /><applicationandroid:icon="@drawable/ic_launcher"android:label="@string/app_name" ><activityandroid:name=".BootupDemoActivity"android:label="@string/app_name" ><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><receiver android:name=".BootupReceiver" android:enabled="true"android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"></action> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver></application></manifest>
2、一個APK啟動另一個APK代碼 package com.motic.uitest;import android.app.Activity; import android.content.ComponentName; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;public class UITestActivity extends Activity {/** Called when the activity is first created. */Button m_btn;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);m_btn = (Button)findViewById(R.id.but);m_btn.setOnClickListener(new BtnLister()); }public class BtnLister implements OnClickListener{public void onClick(View v) {Intent mIntent = new Intent( ); ComponentName comp = new ComponentName("com.example", "com.example.UITutorial_V2Activity"); // ComponentName comp = new ComponentName("com.example.layout", // "com.example.layout.SmsActivity");mIntent.setComponent(comp); mIntent.setAction("android.intent.action.VIEW"); startActivity(mIntent);finish();} }}
總結
以上是生活随笔為你收集整理的开机自启动和由一个APK启动另一个APK核心代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Delphi 鼠标移动
- 下一篇: 计算机资产管理,▪ 资产管理