2016-07-19 48 views
0

我已經爲生產檢查的目的編寫了一個大型商店的Android應用程序。我有幾個安卓平板電腦,每個安裝平臺都會提供給商店。Android平板電腦 - 修改操作系統,使應用程序在啓動時啓動

由於此平板電腦的唯一目的是運行單個應用程序,是否有強制此應用程序在開啓平板電腦時加載並僅允許使用此應用程序的方法?該應用程序確實需要一個活動的4G連接,因此它仍然需要使用Android的一些核心功能以及實際運行該應用程序。

我對此事不太瞭解,所以提前對此表示歉意,但是有人可以爲我澄清一些情況嗎?

回答

0

首先,你需要的許可,您的AndroidManifest.xml:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

此外,在yourAndroidManifest.xml,定義服務,並聽取了BOOT_COMPLETED行動:

<service android:name=".MyService" android:label="My Service"> 
<intent-filter> 
    <action android:name="com.myapp.MyService" /> 
</intent-filter> 
</service> 

<receiver 
android:name=".receiver.StartMyServiceAtBootReceiver" 
android:label="StartMyServiceAtBootReceiver"> 
<intent-filter> 
    <action android:name="android.intent.action.BOOT_COMPLETED" /> 
</intent-filter> 
</receiver> 

然後,你需要定義將獲得BOOT_COMPLETED操作並啓動您的服務的接收器。

public class StartMyActivityeAtBootReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 
    if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { 
     Intent serviceIntent = new Intent(context, MyActivity.class); 
     context.startService(serviceIntent); 
    } 
} 
} 
+0

這會實際加載應用程序還是它只是在後臺運行? – user3605739

+0

它會啓動活動'Intent serviceIntent = new Intent(context,MyActivity.class);'您提供的任何活動都會嘗試並讓我知道如果不工作 – SaravInfern

相關問題