2016-07-05 24 views
0

をAPKランチャータブレット上のアプリが、通常のアプリを作るマニフェストはどのように1つのAPKがタブレット上ランチャーアプリが、携帯電話でちょうど通常アプリもするのですか?このためにマニフェストファイルをどのように設定しますか?私はAPKがタブレット上で実行されたとき、それは選択肢の一つとして表示されます意味ランチャーアプリによってAndroidは携帯電話上

:同じAPKは、携帯電話上で実行されている場合は Select home picker

、それは「ホームを選択表示されませんアプリ "ピッカー。簡単に言えば

が、これはAPKを持っている必要があります動作です:

目標:私は電話にホームをクリックすると

  • 、私はとしてアプリが表示されませんランチャーの選択肢の1つ。私はタブレットにホームをクリックすると
  • その後、私はの選択肢の一つとして アプリが表示されるはずです。

私のアプローチは、どのような種類のデバイスが実行されているかを決定するChooserActivity.javaがあります。タブレットの場合はTabletMainActivity.javaを起動し、Phoneの場合はPhoneMainActivity.javaを開始します。 (それは錠剤であるか、電話が正常であるかどうかを見つけるためのコード。)

ChooserActivity.java

public class ChooserActivity extends AppCompatActivity { 

    ImageView tabIndicator; 
    private static final String TAG = "Chooser"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_chooser); 
     Log.d(TAG, "onCreate2() Chooser"); 
     finish(); 

     if (findViewById(R.id.tabIndicator)==null){ 
      //PHONE 
      startActivity(new Intent(this, PhoneMainActivity.class)); 

     }else{ 
      //TABLET 
      startActivity(new Intent(this, TabletMainActivity.class)); 
     } 
    } 

} 

RES /レイアウト/ activity_chooser.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.sample.tabletchecker.Chooser"> 
<TextView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:text="PHONE" 
    /> 

</RelativeLayout> 

RES /レイアウト - sw600dp/activity_chooser.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.sample.tabletchecker.Chooser"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="TABLET" 
     /> 
    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:id="@+id/tabIndicator" 
     /> 
</RelativeLayout> 

TabletMainActivity.javaあり、次のランチャーのマニフェストの設定:

<activity android:name=".TabletMainActivity" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <!-- launcher setting --> 
      <category android:name="android.intent.category.HOME" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 

PhoneMainActivity.javaは、単に通常の活動であるマニフェストには何もありません。これは、このアクティビティを電話機の通常のアクティビティにしたいからです。

<activity android:name=".PhoneActivity"> 

    </activity> 

マイChooserActivity.javaアプリが開か/クリックがあったとき開始される最初のアクティビティである、それは、私がのためにさまざまなバリエーションを試してみました。2. ChooserActivityマニフェストエントリの間

<activity android:name=".ChooserActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
</activity> 

を選択しますTabletMainActivity.javaのintent-filterは正しい動作を得ることができませんでした。私はいつもランチャーピッカーが表示されているのを見る。

+0

「ChooserActivity」を起動した後、あなたは 'TabletMainActivity'または' MobileMainActivity'を呼び出しますか? –

+0

はい、** ChooserActivtity.java **は、開始するアクティビティが終了した後に終了します。それがタブレットデバイスの場合、電話機が起動すると、セレクタアクティブがTabletMainActivityを開きます。** PhoneMainActivity **。 – Hilfritz

答えて

0

あなたが全体のトピックを読めば、彼らはRES /値 - として、(特定の値ファイルにブール値を設定する方法について説明し

Determine if the device is a smartphone or tablet?

http://developer.android.com/training/multiscreen/screensizes.html#TaskUseSWQuali

ここでは、この回答を参照してください。 sw600dp /):

<resources> 
    <bool name="isTablet">true</bool> 
</resources> 

sw600dp修飾子は有効であるためAndroid 3.2以上のプラットフォーム用RES /値として(「標準」値ファイルに、次に

<resources> 
    <bool name="isTablet">true</bool> 
</resources> 

:あなたは、この技術は(3.2以前)全てのプラットフォーム上で動作を確認するには、RES /値-XLARGEフォルダに同じファイルを作成します/)、あなたはfalseにブール値を設定します。

<resources> 
    <bool name="isTablet">false</bool> 
</resources> 

その後の活動で、この値を取得し、あなたがタブレットサイズのデバイスで実行されているかどうかを確認することができます

チェックあなたにするときのアクティビティを選択インテント

私はまた、あなたのために他の方法を入れています

アッパー方法が私のために適切に動作している

boolean tabletSize = getResources().getBoolean(R.bool.isTablet); 
if (tabletSize) { 


Intent intent = new Intent(ChooserActivity.this, TabletMainActivity.class); 


    startActivity(intent); 

} else { 
     Intent intent = new Intent(ChooserActivity.this, PhoneMainActivity.class); 


    startActivity(intent); 


} 

...

インポート

 import android.content.Context; 
    import android.content.res.Configuration; 
    import android.util.DisplayMetrics; 

機能

public static int FunctionCall(Context context) { 

    if ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) { 

      Intent intent=new Intent(this,PhoneMainActivity.class); 

      startActivity(intent); 
    } 

    else if ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) { 
     Intent intent=new Intent(this,PhoneMainActivity.class); 

       startActivity(intent); 

    } 
    else if ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) { 

     Intent intent=new Intent(this,TabletMainActivity.class); 

       startActivity(intent); 


    } else if ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) { 
     Intent intent=new Intent(this,TabletMainActivity.class); 

       startActivity(intent); 

    } 


    return value; 
    } 

+0

タブレットか電話かどうかのデバイスのチェックは大丈夫です。問題は、ランチャー用の 'TabletMainActivity.java'と' PhoneMainActivity.java'のマニフェスト設定です。 – Hilfritz

+0

ありがとうございますが、それは質問/問題の答えではありません。 – Hilfritz

+0

私はエルと思います。 Arjunは正解ですが、別のアクティビティが必要であることを指定するのを忘れていました。例えば、StartActivity ... コードに入れてSmartphoneActivityまたはTabletActivityを起動してください –