16

次の方法でアプリを起動できます。

  1. ランチャーでアイコンをタップする
  2. 「表示されている」インテントフィルターを登録します(つまり、ユーザーが「送信」をクリックしてからアプリを選択します)
  3. ダイヤラに数字コードを入力して「電話」-「見えない」インテント、ユーザーはアプリを選択できず、コードを入力するだけです

アプリを起動する他の方法はありますか?(私は主に、段落3の「見えない」意図のようなものに興味があります)。

  • デフォルトのシステムアプリ(最も人気のあるGoogleアプリもデフォルトとしてカウントされます)と私のアプリのみを備えたクリーンなデバイスがあると仮定します
  • 通常のユーザー向けの方法が推奨されますが、より難しいアプローチも役立ちます
  • 1つのデバイスで使用できるバリアント(アプローチするために他のデバイスは必要ありません)が推奨されますが、「複数のデバイスのバリアント」も役立ちます。
4

2 に答える 2

14

Web ブラウザーからアプリを実行することもできます。

<intent-filter>
<data android:scheme="my.special.scheme" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>

NFC トランザクションでアプリを起動できます。

メインフェストに<uses-feature android:name="android.hardware.nfc" />

詳細については、こちらをご覧ください: LINK


また、受信者を登録して、シークレット コードが含まれる SMS を受信したときにアプリを起動することもできます。

  public void onReceive(Context context, Intent intent) {
            Bundle bundle = intent.getExtras();

            Object messages[] = (Object[]) bundle.get("pdus");
            SmsMessage smsMessage[] = new SmsMessage[messages.length];
            for (int n = 0; n &lt; messages.length; n++) {
            smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
            }

            String text = smsMessage[0].getMessageBody();

if(text = "yoursecretcode") {
//launch the app 
abortBroadcast(); //if you want to hide this messeage
 } 
            }

必要な許可:<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>


選択した電話番号から電話がかかってきたときに、受信者を登録してアプリを起動することもできます。

public class ServiceReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
    MyPhoneStateListener phoneListener=new MyPhoneStateListener();
    TelephonyManager telephony = (TelephonyManager) 
    context.getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
  }
}

public class MyPhoneStateListener extends PhoneStateListener {
  public void onCallStateChanged(int state,String incomingNumber){
  switch(state){

    case TelephonyManager.CALL_STATE_RINGING:
      String numer = TelephonyManager.EXTRA_INCOMING_NUMBER;
   // launch your app if 'numer' is ...

 break;
        }
      } 
    }

このREAD_PHONE_STATE許可が必要です


シェルを使用してこれを行うこともできます (電話はルート化されている必要があります)。

例えば ​​:

Runtime.getRuntime().exec("su");

Runtime.getRuntime ().exec ("am start -n com.android.calculator2/.Calculator");

同僚"Arpan"が書いた:

電話を傾けて手を振る (基本的には近接センサーを使用してアプリのインテントを起動します)

コードサンプルを提供します:

public class SensorActivity extends Service implements SensorEventListener {
  private SensorManager mSensorManager;
  private Sensor mProximity;

  @Override
  public final void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
  }

  @Override
  public final void onAccuracyChanged(Sensor sensor, int accuracy) {
    // Do something here if sensor accuracy changes.
  }

  @Override
  public final void onSensorChanged(SensorEvent event) {
    float distance = event.values[0];
  if(!ss()) // LAUNCH YOUR APP IF ISN't RUNNNING
  }

  @Override
  protected void onResume() {
    // Register a listener for the sensor.
    super.onResume();
    mSensorManager.registerListener(this, mProximity, SensorManager.SENSOR_DELAY_NORMAL);
  }

  @Override
  protected void onPause() {
    // Be sure to unregister the sensor when the activity pauses.
    super.onPause();
    mSensorManager.unregisterListener(this);
  }
}

private boolean ss() {
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("com.packagename.something.ActivityName".equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

"Arpan"また書いた:

USB デバイスを接続し、マニフェストにインテント フィルターを配置します (USB ホスト モードが利用可能な場合)。

public static boolean isConnected(Context context) {
        Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
        int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB;
    }

これを貼り付けることができますTimer


Arpan の投稿を編集し、Android® のジェスチャー検索に関するリンクを追加しました。


ウィジェットを使用してアプリケーションを起動できます (ユーザーがこれをクリックすると、アプリが起動します)。ウィジェット クラスのコード スニペットを提供します。詳細については、こちらを参照してください。

package com.helloandroid.countdownexample;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;



public class CountdownWidget extends AppWidgetProvider {


    @Override
    public void onDeleted(Context context, int[] appWidgetIds) {
            //called when widgets are deleted
            //see that you get an array of widgetIds which are deleted
            //so handle the delete of multiple widgets in an iteration
            super.onDeleted(context, appWidgetIds);
    }

    @Override
    public void onDisabled(Context context) {
            super.onDisabled(context);
            //runs when all of the instances of the widget are deleted from
            //the home screen
            //here you can do some setup
    }

    @Override
    public void onEnabled(Context context) {
            super.onEnabled(context);
            //runs when all of the first instance of the widget are placed
            //on the home screen
    }



@Override
        public void onClick() {
         //your code to launch application...       
        }

    @Override
    public void onReceive(Context context, Intent intent) {
            //all the intents get handled by this method
            //mainly used to handle self created intents, which are not
            //handled by any other method


            //the super call delegates the action to the other methods

            //for example the APPWIDGET_UPDATE intent arrives here first
            //and the super call executes the onUpdate in this case
            //so it is even possible to handle the functionality of the
            //other methods here
            //or if you don't call super you can overwrite the standard
            //flow of intent handling
            super.onReceive(context, intent);
    }

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                    int[] appWidgetIds) {
            //runs on APPWIDGET_UPDATE
            //here is the widget content set, and updated
            //it is called once when the widget created
            //and periodically as set in the metadata xml

            //the layout modifications can be done using the AppWidgetManager
            //passed in the parameter, we will discuss it later

            //the appWidgetIds contains the Ids of all the widget instances
            //so here you want likely update all of them in an iteration

            //we will use only the first creation run
            super.onUpdate(context, appWidgetManager, appWidgetIds);
    }


}

ヘッドフォンが接続されているかどうかを確認します

ヘッドフォンがインテント ( ACTION_HEADSET_PLUG) に接続されるたびに起動されます。これを確認してBroadcastReceiverアクティビティを開始します

IntentFilter f = new IntentFilter();
f.addAction(Intent.ACTION_HEADSET_PLUG);
registerReceiver(headsetPlugReceiver, f);

public BroadcastReceiver headsetPlugReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        // start new Activity or do something else
    }
};

そしてマニフェストで:

<receiver android:name="activity.to.receive.headplug.event">    
  <intent-filter>
    <action android:name="android.intent.action.HEADSET_PLUG" />
  </intent-filter>
</receiver>

于 2013-02-02T16:19:42.837 に答える
3
  1. スマートフォンを傾けて手を振る(基本的に近接センサーを使用してアプリのインテントを起動します)
  2. 画面をタップおよび/またはジェスチャしてインテントを起動します(これについてはここで読むことができます)
  3. USBデバイスを接続し、マニフェストにインテントフィルターを配置します(USBホストモードが利用可能な場合)
于 2013-02-06T12:23:23.717 に答える