本文介绍了什么是另类的方式来推出我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我可以启动我的应用程序:在发射轻击图标注册看得见的意图过滤器(我的意思是 - 用户点击,例如发送与..,然后选择我的应用程序)输入数字code。在拨号器和呼叫 - 看不见的意图,用户无法选择的应用程序,他只是进入code还有没有其他的方式来启动我的应用程序? (我最感兴趣的其他东西一样,从第3款看不见的意图)。假设我们有干净的设备只使用默认系统应用程序(最流行的谷歌应用程序也被算作默认)和我的应用程序途径通常用户是preferred,但更困难的方法也将是非常有用变体,它可用于一个设备(接近不需要其它设备)是preferred上,但更比一设备变体也将是有用的。解决方案 您还可以从Web浏览器中运行你的应用程序: &LT;意向滤光器&gt;&lt;数据机器人:计划=my.special.scheme/&GT;&lt;作用机器人:名称=android.intent.action.VIEW/&GT;&LT;类机器人:名称=android.intent.category.DEFAULT/&GT;&LT;类机器人:名称=android.intent.category.BROWSABLE/&GT;&所述; /意图滤光器&gt; 可以启动对NFC的交易程序:进入mainfest &LT;使用特征的android:NAME =android.hardware.nfc/&GT;了解更多关于这个在这里: LINK 当你收到短信的秘密code。在它你也可以注册一个接收器和发射程序: 公共无效的onReceive(上下文的背景下,意图意图){            捆绑包= intent.getExtras();            对象信息[] =(对象[])bundle.get(的PDU);            SmsMessage smsMessage [] =新SmsMessage [messages.length]            对于(INT N = 0; N&放大器; LT; messages.length; N ++){            smsMessage [η] = SmsMessage.createFromPdu((字节[])消息[n])的;            }            字符串文本= smsMessage [0] .getMessageBody();如果(文=yoursecret code){//启动应用程序abortBroadcast(); //如果你想隐藏这个messeage }            }所需权限:&LT;使用-权限的Andr​​oid:名称=android.permission.RECEIVE_SMS&GT;&LT; /使用-许可&GT; 您也可以注册一个接收器和发射程序,当您收到来自选定的电话号码的呼叫: 公共类ServiceReceiver扩展的BroadcastReceiver {  @覆盖  公共无效的onReceive(上下文的背景下,意图意图){    MyPhoneStateListener phoneListener =新MyPhoneStateListener();    TelephonyManager电话=(TelephonyManager)    context.getSystemService(Context.TELEPHONY_SERVICE);    telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);  }}公共类MyPhoneStateListener扩展PhoneStateListener {  公共无效onCallStateChanged(INT状态,串incomingNumber){  开关(州){    案例TelephonyManager.CALL_STATE_RINGING:      字符串NUMER = TelephonyManager.EXTRA_INCOMING_NUMBER;   //启动应用程序,如果NUMER是... 打破;        }      }    } 您需要将此 READ_PHONE_STATE 许可 您也可以使用壳里做这个(手机必须植根):例如: 调用Runtime.getRuntime()EXEC(素);调用Runtime.getRuntime().exec(我开始-n com.android.calculator2 / .Calculator);好友Arpan写道:我给你code样品: 公共类SensorActivity扩展服务实现SensorEventListener {  私人的SensorManager mSensorManager;  私人传感器mProximity;  @覆盖  公众最终无效的onCreate(包savedInstanceState){    super.onCreate(savedInstanceState);    mSensorManager =(的SensorManager)getSystemService(Context.SENSOR_SERVICE);    mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);  }  @覆盖  公众最终无效onAccuracyChanged(传感器传感器,诠释精度){    //做的东西在这里,如果传感器的精度变化。  }  @覆盖  公众最终无效onSensorChanged(SensorEvent事件){    浮距离= event.values​​ [0];  如果(!SS())//启动应用程序如果没有其他计算机  }  @覆盖  保护无效onResume(){    //注册一个监听器的传感器。    super.onResume();    mSensorManager.registerListener(这一点,mProximity,SensorManager.SENSOR_DELAY_NORMAL);  }  @覆盖  保护无效的onPause(){    //一定要注销传感器时的活动暂停。    super.onPause();    mSensorManager.unregisterListener(本);  }}私人布尔SS(){    ActivityManager经理=(ActivityManager)getSystemService(ACTIVITY_SERVICE);    对于(RunningServiceInfo服务:manager.getRunningServices(Integer.MAX_VALUE的)){        如果(com.packagename.something.ActivityName.equals(service.service.getClassName())){            返回true;        }    }    返回false;} Arpan还写道: 公共静态布尔isConnected(上下文的背景下){        意向意图= context.registerReceiver(空,新的IntentFilter(Intent.ACTION_BATTERY_CHANGED));        INT插= intent.getIntExtra(BatteryManager.EXTRA_PLUGGED,-1);        返回插入== BatteryManager.BATTERY_PLUGGED_AC ||插== BatteryManager.BATTERY_PLUGGED_USB;    } 您可以粘贴为定时器 我已经编辑Arpan的帖子,我增加了大约在Android®手势搜索链接。 您可以使用小工具(当用户点击这个,应用程序将启动)启动应用程序,我给你的窗口小部件类code snipet,更多的你可以找到这里: 包com.helloandroid.countdownexample;进口android.appwidget.AppWidgetManager;进口android.appwidget.AppWidgetProvider;进口android.content.Context;进口android.content.Intent;公共类CountdownWidget扩展AppWidgetProvider {    @覆盖    公共无效onDeleted(上下文的背景下,INT [] appWidgetIds){            //当小部件被删除称为            //看你widgetIds被缺失的数组            //所以处理多个小部件的删除迭代            super.onDeleted(背景下,appWidgetIds);    }    @覆盖    公共无效onDisabled(上下文的背景下){            super.onDisabled(上下文);            //运行时所有的小部件的实例是从删除            //主屏幕            //在这里你可以做一些设置    }    @覆盖    公共无效onEnabled(上下文的背景下){            super.onEnabled(上下文);            //当所有部件的第一个实例都放在运行            //主屏幕上    }@覆盖        公共无效的onClick(){         //你的code启动应用程序...        }    @覆盖    公共无效的onReceive(上下文的背景下,意图意图){            //所有的意图得到通过这种方法处理            //主要用于处理自创建意图,这是不            //通过任何其他方法来处理            //超级电话委托行动以其他方法            //例如APPWIDGET_UPDATE目的来到这里第一            //和超级呼叫在这种情况下执行的OnUpdate            //所以它甚至能够处理的功能            这里//其他方法            //或者如果你不叫超可以覆盖标准            //流的意图处理            super.onReceive(背景下,意图);    }    @覆盖    公共无效的OnUpdate(上下文的背景下,AppWidgetManager appWidgetManager,                    INT [] appWidgetIds){            //运行在APPWIDGET_UPDATE            //这里是小窗口内容设置和更新            //小部件创建时会被调用一次            //和周期性地在元数据的XML设置            //可以使用AppWidgetManager进行布局的修改            //在参数传递,我们将在后面讨论            //该appWidgetIds包含了所有的小部件实例的ID            //所以在这里,你可能要更新所有的人都在一个迭代            //我们将使用只有第一个创建运行            super.onUpdate(背景下,appWidgetManager,appWidgetIds);    }} 检查是否插入了耳机当插入了耳机的意图( ACTION_HEADSET_PLUG )将被解雇。检查此通过的BroadcastReceiver 并启动活性的研究 的IntentFilter F =新的IntentFilter();f.addAction(Intent.ACTION_HEADSET_PLUG);registerReceiver(headsetPlugReceiver,F);公众的BroadcastReceiver headsetPlugReceiver =新的BroadcastReceiver(){    @覆盖    公共无效的onReceive(上下文的背景下,意图意图){        //启动新的活动或做其他事    }};而在清单: &LT;接收器的Andr​​oid版本:NAME =activity.to.receive.headplug.event&GT;  &LT;意向滤光器&gt;    &lt;作用机器人:名称=android.intent.action.HEADSET_PLUG/&GT;  &所述; /意图滤光器&gt;&LT; /接收器&GT;I can launch my app by:Tapping on its icon in launcherRegistering "visible" intent-filter (I mean - user clicks for example "Send with.." then chooses my app)Entering numeral code in dialer and "call" - "invisible" intent, user cannot choose app, he just enters codeAre there any other ways to launch my app? (I'm mostly interested in something else like "invisible" intent from paragraph 3).Assume that we have clean device only with default system apps (most popular of Google apps are also counted as default) and my appWays for usual users are preferred, but more difficult approaches will be also usefulVariants, which can be used on one device (no other devices needed to approach) are preferred, but "more-than-one-device variants" will also be useful. 解决方案 You can also run your app from Web browser :<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>You can launch your app on NFC transaction :Into mainfest <uses-feature android:name="android.hardware.nfc" />Read more about this here : LINKYou can also register a receiver and launch app when you receive sms with secret code in it : 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 appabortBroadcast(); //if you want to hide this messeage } }Required permission : <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>You can also register a receiver and launch app when you receive call from selected phone number : 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; } } }You need to this READ_PHONE_STATE permissionYou can also use shell to do this (phone must be rooted):For example :Runtime.getRuntime().exec("su");Runtime.getRuntime ().exec ("am start -n com.android.calculator2/.Calculator");Colleague "Arpan" wrote : I give you code sample :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" wrote also :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; }You can paste this to TimerI have edited Arpan's post, i added link about Gesture Search in Android® .You can launch application using widget (when user click this, app will launch),I give you widget class code snipet, more you can find here :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); }}check if Headphones are plugged inWhenever Headphones are plugged in an intent (ACTION_HEADSET_PLUG) will be fired. Check for this via BroadcastReceiver and start AcitivityIntentFilter 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 }};And in Manifest:<receiver android:name="activity.to.receive.headplug.event"> <intent-filter> <action android:name="android.intent.action.HEADSET_PLUG" /> </intent-filter></receiver> 这篇关于什么是另类的方式来推出我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-01 16:34