我的情况很奇怪.
有一个应用程序,我决定从第一个应用程序的代码创建另一个.
我复制了.xml文件,复制了.java文件以便一切正常.
但是有一个巨大的问题:我的onNewIntent(Intent intent)
方法是在第一个项目中调用的,但它没有在第二个项目中调用(代码是相同的!)
方法,可以触发,但现在无法触发
public void onClick(View arg0) {
Intent browserInt = new Intent (Intent.ACTION_VIEW,
Uri.parse("https://oauth.yandex.ru/authorize?response_type=token&client_id=zzzzz"));
browserInt.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(browserInt);
}
Run Code Online (Sandbox Code Playgroud)
这是onNewIntent()方法:
@Override
protected void onNewIntent(Intent intent){
System.out.println(" I WORKED!");
Uri uri = intent.getData();
if (uri!=null) {
String m = uri.toString().split("#")[1];
String[] args = m.split("&");
String arg = args[0];
String token = arg.split("=")[1];
System.out.println(token);
}
}
Run Code Online (Sandbox Code Playgroud)
遗憾的是,我在日志中看不到"我工作".
我在SO和Internet上都阅读了很多类似的问题,尝试设置Intent标志SINGLE_TOP,SINGLE_TASK等等.
这是Android Manifest的WORKING项目:
<application
android:name="yyy"
android:icon="@drawable/yaru_icon"
android:allowBackup="false"
android:label="xxx"
android:theme="@style/LightTheme">
<activity
android:name=".Main"
android:label="xxx"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application> …
Run Code Online (Sandbox Code Playgroud) 我在RecyclerView中有一个简单项目列表.使用ItemTouchHelper实现"轻扫到删除"行为非常容易.
public class TripsAdapter extends RecyclerView.Adapter<TripsAdapter.VerticalItemHolder> {
private List<Trip> mTrips;
private Context mContext;
private RecyclerView mRecyclerView;
[...]
//Let adapter know his RecyclerView. Attaching ItemTouchHelper
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new TripItemTouchHelperCallback());
itemTouchHelper.attachToRecyclerView(recyclerView);
mRecyclerView = recyclerView;
}
[...]
public class TripItemTouchHelperCallback extends ItemTouchHelper.SimpleCallback {
public TripItemTouchHelperCallback (){
super(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.RIGHT);
}
@Override
public boolean onMove(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
//some "move" implementation
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
//AND WHAT …
Run Code Online (Sandbox Code Playgroud) 我在Android开发控制台中收到以下崩溃报告.我的应用程序在我尝试使用该应用程序的模拟器或设备上正常运行,但出于某种原因,在Galaxy Nexus(Maguro)上它无法运行.我也没有得到任何编译错误.
java.lang.NoClassDefFoundError: java.util.Objects
at com.nivelsonic.nivelsonic.MyTankActivity$5.onResponse(MyTankActivity.java:199)
at com.nivelsonic.nivelsonic.MyTankActivity$5.onResponse(MyTankActivity.java:160)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
MyTankActivity.java
public void drawTankStatus() {
tankView = (TankView) this.findViewById(R.id.vMyTank);
tvLocation = (TextView) this.findViewById(R.id.tvLocation);
tvLevel = (TextView) this.findViewById(R.id.tvLevel);
ivRssi = (ImageView) this.findViewById(R.id.ivRssi);
ivSettings = (ImageView) this.findViewById(R.id.ivSettings);
ivAlert = (ImageView) this.findViewById(R.id.ivAlert);
final Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse …
Run Code Online (Sandbox Code Playgroud) 我创建了一个管理 XMPP 连接的服务。我的应用程序需要定期接收 XMPP 消息。一切似乎都按预期工作,但只有当手机插入 Android Studio 并且我在调试模式下运行应用程序时。当我拔掉电话,或者即使它已插入但我从电话而不是从 AS 启动应用程序,该服务似乎没有启动...
我确保在清单中正确声明了我的服务:
<service
android:name=".xmpp.MyService"
android:enabled="true" />
Run Code Online (Sandbox Code Playgroud)
其中 .xmpp 是我的主包中的一个子包。
这是我的服务
public class MyService extends Service {
public static ConnectivityManager cm;
public static MyXMPP xmpp;
private static String LOG_TAG = "MyService";
@Override
public IBinder onBind(final Intent intent) {
Log.v(LOG_TAG, "in onBind");
return null;
}
@Override
public void onCreate() {
super.onCreate();
cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (CurrentInfo.getUser() != null) {
xmpp = MyXMPP.getInstance(MyService.this, getResources().getString(R.string.xmpp_url), CurrentInfo.getUser().getJabberId(), getString(R.string.xmpp_password));
xmpp.connect("onCreate");
}
}
@Override
public int onStartCommand(final …
Run Code Online (Sandbox Code Playgroud) service android android-service android-studio android-service-binding
我按照 mikep 发布的以下参考来处理超过 23 个具有高级许可证的航点,它确实处理了超过 23 个航点,但是它没有考虑具有 28 个航点的最佳路线。请在下面找到代码片段。如果我错过了什么,请告诉我。
参考:Google Directions API 的每个请求限制超过 23 个航点(商务/工作级别)
<!DOCTYPE html>
<html>
<head>
<title>Distance Matrix service</title>
<style>
#right-panel {
font-family: 'Roboto','sans-serif';
line-height: 30px;
padding-left: 10px;
}
#right-panel select, #right-panel input {
font-size: 15px;
}
#right-panel select {
width: 100%;
}
#right-panel i {
font-size: 12px;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
width: 50%;
}
#right-panel {
float: right;
width: 48%;
padding-left: 2%;
}
#output …
Run Code Online (Sandbox Code Playgroud)我希望有人能帮助我解决我的问题。我有一个有 3 个选项卡的 Android 应用程序,我使用片段,第一个选项卡是 recyclerView 列表,第二个选项卡是地图。问题出在选项卡 1 中,我需要通过齐射获取数据到选项卡 1 上的 recyclerView,如果运行正常,但我在第一个应用程序启动时看不到数据,但是当我再次更改选项卡并返回选项卡 1 时,它将刷新数据并在recyclerView上显示数据。
适配器.java
public class CustomListAdapterWarkop extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context;
private List<Warkop> mWarkop;
private LayoutInflater inflater;
public CustomListAdapterWarkop(Context context, List<Warkop> mWarkop) {
this.context=context;
inflater= LayoutInflater.from(context);
this.mWarkop = mWarkop;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.list_warkop_row, parent, false);
ItemViewHolder holder = new ItemViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
ItemViewHolder viewHolder = (ItemViewHolder) holder;
Warkop current …
Run Code Online (Sandbox Code Playgroud) 我在Kotlin 中创建了一个具有多种视图类型的 RecyclerView(技术动态方法调度或运行时多态性。),现在我有ViewHolder如下图所示
abstract class BaseViewHolder<T> internal constructor(itemView: View) : RecyclerView.ViewHolder(itemView){
abstract fun bind(_object:T)
}
Run Code Online (Sandbox Code Playgroud)
我有如下图所示的适配器
class activation_items_main_activity (list: List<out BaseModel>,context: Context):RecyclerView.Adapter<BaseViewHolder<*>>() {
private var mList: List<out BaseModel>? = null
private var mInflator:LayoutInflater ? = null
init {
this.mList = list
this.mInflator = LayoutInflater.from(context)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<*> {
when (viewType)
{
Constant_ViewType_RecyclerView.ViewType.ListOfActivation_Type1 -> return ListOfActivation_MainActivity_Holder(mInflator!!.inflate(R.layout.activities_layout_item,parent,false))
Constant_ViewType_RecyclerView.ViewType.ListOfActivation_Type2 -> return ListOfActivation_MainActivity2_Holder(mInflator!!.inflate(R.layout.activities_layout_items_type2,parent,false))
}
return null // -----> **problem return null**
}
override fun getItemCount(): …
Run Code Online (Sandbox Code Playgroud) Android P引入了变化Biometrics API
.
现在我们应该使用BiometricPrompt
class在我们的应用程序中集成生物识别身份验证(FingerprintManager
不推荐使用).
问题是此类仅适用于API 28.
生物识别技术文档说:
还为运行Android O及更早版本的设备提供了支持库,允许应用程序在更多设备上利用此API的优势.
但我找不到那个支持库.
它存在吗?或者将在未来的实施中添加?
每当我尝试设置 LinearLayout 的高度时,我总是会遇到以下异常:
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
LinearLayout.LayoutParams hide = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
LinearLayout.LayoutParams show = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100);
driverMainOptions.setLayoutParams(hide);
mapDirections.setLayoutParams(show);
Run Code Online (Sandbox Code Playgroud)
是否需要特定的导入语句才能正确执行?
我如何在片段类中使用getSystemService,如下面的代码
final EditText input = new EditText(getContext());
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_TEXT);
//Show Automatic KeyBoard
input.postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager keyboard = (InputMethodManager) getBaseContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.showSoftInput(input, 0);
}
}, 50);
builder.setView(input);
Run Code Online (Sandbox Code Playgroud) android ×9
java ×2
biometrics ×1
fragment ×1
google-maps ×1
java.lang ×1
javascript ×1
kotlin ×1
service ×1