1

次のコードを使用して、アプリを既定のプログラムとして設定します。キーを押しhomeてアプリに移動します...

<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />

またDISABLE_KEYGUARD、電話のロックを解除する必要なく、アプリで直接起動します。

プログラムでデフォルトのランチャーに戻すにはどうすればよいですか? つまり、どうすればAndroidのホーム画面に戻ることができますか?

使用してみSystem.exit(0)ましたが、機能しません。Android のホーム画面ではなく、アプリに戻るだけです。


以下は私のコードです。自動的にアプリに戻ります。コードの問題を教えてください。

TesthomeActivity.java

public class TesthomeActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button btn = (Button)findViewById(R.id.button1);
    btn.setOnTouchListener(exitappTouchListener);
}
OnTouchListener exitappTouchListener= new OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent arg1) {
        // TODO Auto-generated method stub
        if(arg1.getAction() == MotionEvent.ACTION_DOWN){

        }
        if(arg1.getAction() == MotionEvent.ACTION_UP ){
            Intent i = new Intent();
              i.setAction(Intent.ACTION_MAIN);
              i.addCategory(Intent.CATEGORY_HOME);
              TesthomeActivity.this.startActivity(i); 
              finish(); 
            System.exit(0);
        }
        return false;
    }
};
}

StartupReceiver.java

public class StartupReceiver extends BroadcastReceiver{

public void onReceive(Context context, Intent intent)
{

    Intent activityIntent = new Intent(context, TesthomeActivity.class);
    activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(activityIntent);
}

}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.inno.testhome"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
    <activity android:name=".TesthomeActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.HOME" />
        </intent-filter>
    </activity>
    <receiver android:name="StartupReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
</application>
</manifest>
4

3 に答える 3

2

これを読む

またはこれを使用します

Intent i = new Intent();
  i.setAction(Intent.ACTION_MAIN);
  i.addCategory(Intent.CATEGORY_HOME);
  yourActivity.this.startActivity(i); 
  finish(); 

私はこれがあなたを助けると思います

于 2012-06-18T03:59:46.163 に答える
0

アプリがデフォルトのランチャーとして設定されている場合、Android システムはアプリが終了するたびに自動的に再起動します。元のホーム画面の概念はなくなりました。オペレーティング システムに関する限り、アプリ現在ホーム画面です。

これが、アプリを終了してもデフォルトのランチャーに戻れない理由です。必要な結果を得る唯一の方法は、デフォルトのランチャーを変更することです

于 2012-09-06T10:32:22.683 に答える
0

PackageManagerHome インテントに応答するアプリを照会する必要があります。

その後、他のアクティビティを開始するのと同じように、正しいものを起動できます。処理する前に、必ずリストからアプリを削除してください...

これに関する有用な情報については、@Commonsware の Launchalot サンプル アプリをお勧めします。これは、特定のインテントに応答するアプリのリストを列挙する方法を示しています。

ここで github で彼のコードを確認してください。

于 2013-09-04T11:06:58.127 に答える