-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from aaWen2859/master
增加OpenBrowser浏览器启动步骤
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/src/androidTest/java/com/smart/farmer/step/OpenBrowser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.smart.farmer.step; | ||
|
||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.content.pm.ResolveInfo; | ||
import android.net.Uri; | ||
import android.support.test.InstrumentationRegistry; | ||
|
||
import com.smart.farmer.step.log.LogUtils; | ||
|
||
import java.io.IOException; | ||
|
||
public class OpenBrowser extends BaseStep { | ||
|
||
protected String url = "about:blank";//启动的浏览器地址 | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public void setUrl(String url) { | ||
this.url = url; | ||
} | ||
|
||
@Override | ||
protected void runSelf() throws Exception { | ||
|
||
//启动移动端HTML5浏览器 | ||
Context mContext = InstrumentationRegistry.getInstrumentation().getContext(); | ||
//筛选条件 | ||
|
||
//默认浏览器,BROWSABLE 种类 | ||
String default_browser = "android.intent.category.DEFAULT"; | ||
String browsable = "android.intent.category.BROWSABLE"; | ||
String view = "android.intent.action.VIEW"; | ||
Intent intent = new Intent(view); | ||
|
||
//添加类别 | ||
intent.addCategory(default_browser); | ||
intent.addCategory(browsable); | ||
|
||
//添加Data及Type | ||
Uri uri = Uri.parse("http://"); | ||
intent.setDataAndType(uri, null); | ||
ResolveInfo info = mContext.getPackageManager().resolveActivity(intent, PackageManager.GET_INTENT_FILTERS); | ||
String infoPackage = info.activityInfo.packageName; | ||
String infoactivityName = info.activityInfo.name; | ||
|
||
//命令行启动 | ||
try { | ||
String test= getUiDevice().executeShellCommand("am start -a android.intent.action.VIEW -d " + getUrl() + " -n " + infoPackage + "/" + infoactivityName); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} | ||
|