我的应用适用于Android 5.1.1。
在4.4.2中它在发射时崩溃。
这是MainActivity.java
package com.medialablk.onlineshoppin;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private List < Sites > sitesList = new ArrayList < > ();
private RecyclerView recyclerView;
private SitesAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mAdapter = new SitesAdapter(sitesList);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(
getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.addItemDecoration(new DividerItemDecoration(this,
LinearLayoutManager.VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
prepareSitesData();
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string
.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(new NavigationView
.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.nav_preferences) {
// Handle the preference action
} else if (id == R.id.nav_about) {
// Handle the About action
}
DrawerLayout drawer = (DrawerLayout) findViewById(
R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
});
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(
getApplicationContext(), recyclerView, new RecyclerTouchListener
.ClickListener() {
@Override
public void onClick(View view, int position) {
if (checkNet()) {
Sites sites = sitesList.get(position);
Intent intent = new Intent(
getApplicationContext(),
BrowserActivity.class);
intent.putExtra("url", sites.getUrl());
startActivity(intent);
} else {
Intent intent = new Intent(
getApplicationContext(),
BrowserActivity.class);
intent.putExtra("url",
"file:///android_asset/index.html"
);
startActivity(intent);
}
}
@Override
public void onLongClick(View view, int position) {
}
}));
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void prepareSitesData() {
Sites sites = new Sites(0, "Takas.lk", "www.takas.lk",
"http://takas.lk/", R.drawable.me);
sitesList.add(sites);
sites = new Sites(1, "Wow.lk", "www.wow.lk", "http://wow.lk/", R.drawable
.me);
sitesList.add(sites);
sites = new Sites(2, "OnlineShopping.lk",
"Online Shopping Sri Lanka Online Shopping Sri Lanka", "#",
R.drawable.me);
sitesList.add(sites);
sites = new Sites(3, "OnlineShopping.lk",
"Online Shopping Sri Lanka Online Shopping Sri Lanka", "#",
R.drawable.me);
sitesList.add(sites);
sites = new Sites(4, "OnlineShopping.lk",
"Online Shopping Sri Lanka Online Shopping Sri Lanka", "1",
R.drawable.me);
sitesList.add(sites);
sites = new Sites(5, "OnlineShopping.lk",
"Online Shopping Sri Lanka Online Shopping Sri Lanka", "1",
R.drawable.me);
sitesList.add(sites);
sites = new Sites(6, "OnlineShopping.lk",
"Online Shopping Sri Lanka Online Shopping Sri Lanka", "1",
R.drawable.me);
sitesList.add(sites);
sites = new Sites(7, "OnlineShopping.lk",
"Online Shopping Sri Lanka Online Shopping Sri Lanka", "1",
R.drawable.me);
sitesList.add(sites);
sites = new Sites(8, "OnlineShopping.lk",
"Online Shopping Sri Lanka Online Shopping Sri Lanka", "1",
R.drawable.me);
sitesList.add(sites);
mAdapter.notifyDataSetChanged();
}
public boolean checkNet() {
boolean mobileNwInfo;
ConnectivityManager conxMgr = (ConnectivityManager) getSystemService(
CONNECTIVITY_SERVICE);
try {
mobileNwInfo = conxMgr.getActiveNetworkInfo().isConnected();
} catch (NullPointerException e) {
mobileNwInfo = false;
}
return mobileNwInfo;
}
}
App Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.medialablk.onlineshopping"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
}
答案 0 :(得分:1)
试试这个,确保所有库版本在gradle依赖项中必须相同
const {clipboard} = require('electron')